How anandhakumar123456/genai works
Purpose and entry points
TradeTalks AI is a single-user, conversational financial-education assistant. It provides beginner-oriented investing and trading explanations while avoiding personalized buy/sell advice.
• Backend ASGI entry point: main.py (uvicorn main:app --reload)
• Browser client: index.html
• Conversational/LLM orchestration: agent.py
FastAPI chat boundary
main.py owns the HTTP application and exposes POST /chat, accepting a user_question query parameter. The endpoint streams plain-text model output back to the caller rather than waiting for a complete response.
This is the primary frontend/backend boundary: index.html submits questions to the FastAPI service and consumes the response incrementally.
Paths: main.py, index.html
Agent orchestration and conversation state
agent.py implements the chat agent layer between the API and Groq-hosted LLM. It is responsible for maintaining in-memory conversation history so later turns can be interpreted in the context of the active discussion.
Because history is memory-resident, conversations are process-local and are not durable across server restarts or naturally shared across multiple backend instances.
Paths: agent.py, main.py
Prompt and safety policy layer
prompts.py centralizes instructions supplied to the model. This layer defines the assistant’s educational tone, expected explanatory structure, and financial-safety constraints, including avoiding direct trading recommendations.
Prompting is the key behavioral boundary: application code delegates domain framing and response policy to model instructions rather than implementing financial analysis logic locally.
Paths: prompts.py, agent.py
Structured interaction schemas
schemas.py contains Pydantic models used to represent structured application/LLM interaction data, including cases where the assistant needs to present topic choices or clarification-oriented responses.
These schemas form the contract between orchestration logic and structured response handling, while the public /chat API remains a streamed text interface.
Paths: schemas.py, agent.py, main.py
Model and external-service integration
The runtime uses LangChain and LangChain-Groq to invoke a Groq-hosted language model. Authentication is supplied through the GROQ_API_KEY environment variable, expected in a local .env file.
The model provider is an external dependency and the source of generated educational content; no market-data service, database, or persistent message store is represented in the repository.
Paths: agent.py, pyproject.toml, uv.lock
Runtime and deployment shape
The application is a lightweight Python 3.13+ service using FastAPI and Uvicorn, paired with a standalone static HTML/CSS/JavaScript client. The frontend is opened directly in a browser rather than being represented as a separately built or served web application.
Paths: pyproject.toml, main.py, index.html
Main entry points: agent.py Chat agent · pyproject.toml Python runtime dependencies · main.py POST /chat · index.html Static chat client
Components 12
Browser Client
- Static chat client · Opened directly in the browser.
index.html
Python Service
- POST /chat · Accepts user_question and streams plain text.
main.py - Response streaming
main.py - Structured interactions · Models topic-choice and clarification responses.
schemas.py - Python runtime dependencies · Defines FastAPI, Uvicorn, LangChain, and LangChain-Groq dependencies.
pyproject.toml - Locked dependencies
uv.lock
AI Integration
- Chat agent · Coordinates conversation and model calls.
agent.py - Conversation history · Process-local and lost on restart.
agent.py - Educational safety policy · Defines explanatory tone and avoids direct trading recommendations.
prompts.py - LangChain integration
agent.py - GROQ_API_KEY
Other components
- Groq-hosted LLM · Generates educational responses.
Connections 13
- Static chat client → POST /chat: submits question
- POST /chat → Chat agent: invokes
- Chat agent → Conversation history: reads and updates
- Chat agent → Educational safety policy: applies policy
- Chat agent → Structured interactions: uses structured contracts
- Chat agent → LangChain integration: calls through
- LangChain integration → Groq-hosted LLM: model request
- GROQ_API_KEY → LangChain integration: authenticates
- Chat agent → Response streaming: generated text
- Response streaming → Static chat client: incremental plain text
- Python runtime dependencies → POST /chat: runs with FastAPI/Uvicorn
- Python runtime dependencies → LangChain integration: provides dependencies
- Locked dependencies → Python runtime dependencies: pins versions