Skip to content

praneeg488-ctrl/cc

Repository files navigation

🏦 Finance AI Buddy

An AI-powered financial analysis assistant with document intelligence, RAG queries, agentic workflows, and data visualization.

Next.js FastAPI Python TypeScript


✨ Features

  • πŸ’¬ Chat Interface β€” ChatGPT-like UI with streaming responses, markdown rendering, and code highlighting
  • πŸ“‚ Document Upload β€” Upload PDFs, CSVs, Excel, and PowerPoint files for AI analysis
  • πŸ” RAG Queries β€” Ask questions over uploaded documents with retrieval-augmented generation
  • πŸ€– Multi-Agent Workflows β€” AutoGen-style agents for financial analysis, document parsing, and visualization
  • πŸ“Š Chart Generation β€” AI-generated matplotlib charts returned as interactive images
  • πŸͺž Document Mirror β€” Reconstruct and transform document structures (slides, tables, summaries)
  • πŸŒ™ Dark & Light Themes β€” Glassmorphism UI with smooth transitions
  • πŸ’Ύ Chat History β€” Persistent conversations with rename/delete support
  • βš™οΈ Flexible LLM Backend β€” Works with OpenAI, vLLM, or any OpenAI-compatible API

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Next.js Frontend (:3000)          β”‚
β”‚  app/page.tsx β”‚ app/layout.tsx β”‚ globals.cssβ”‚
β”‚  TailwindCSS + Framer Motion + React Markdownβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚ HTTP / SSE
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           FastAPI Backend (:8000)            β”‚
β”‚                 api.py                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚ /chat   β†’ Streaming LLM responses   β”‚    β”‚
β”‚  β”‚ /upload β†’ File ingestion + embed    β”‚    β”‚
β”‚  β”‚ /query  β†’ RAG-based Q&A             β”‚    β”‚
β”‚  β”‚ /agent  β†’ Multi-agent workflows     β”‚    β”‚
β”‚  β”‚ /plot   β†’ Chart generation          β”‚    β”‚
β”‚  β”‚ /docs   β†’ Document management       β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚  FAISS Vector DB β”‚ File Storage              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
          OpenAI-compatible API
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚              β”‚              β”‚
 OpenAI API    vLLM Local    Custom API

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Python 3.10+
  • An OpenAI API key OR a running vLLM server

1. Clone & Install

# Clone the repository
cd Finance-ai

# Install frontend dependencies
npm install

# Install backend dependencies
pip install -r requirements.txt

2. Start the Backend

# Start FastAPI server
uvicorn api:app --host 0.0.0.0 --port 8000 --reload

The API will be available at http://localhost:8000.
API docs: http://localhost:8000/docs

3. Start the Frontend

# In a new terminal
npm run dev

Open http://localhost:3000 in your browser.

4. Configure

Open the Settings panel (βš™οΈ icon) in the app and enter:

Setting OpenAI vLLM Local
API Key sk-... any-string (ignored)
API URL https://api.openai.com/v1 http://localhost:8001/v1
Model gpt-4 Your model name (e.g. meta-llama/Meta-Llama-3-8B)

βš™οΈ Configuration Examples

OpenAI (Default)

{
  "api_key": "sk-proj-...",
  "api_url": "https://api.openai.com/v1",
  "model": "gpt-4"
}

vLLM Local Server

First, start vLLM:

python -m vllm.entrypoints.openai.api_server \
  --model meta-llama/Meta-Llama-3-8B-Instruct \
  --host 0.0.0.0 \
  --port 8001

Then configure the app:

{
  "api_key": "not-needed",
  "api_url": "http://localhost:8001/v1",
  "model": "meta-llama/Meta-Llama-3-8B-Instruct"
}

Any OpenAI-Compatible API (e.g., Ollama, Together, etc.)

{
  "api_key": "your-api-key",
  "api_url": "https://api.together.xyz/v1",
  "model": "mistralai/Mixtral-8x7B-Instruct-v0.1"
}

πŸ“ Project Structure

Finance-ai/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ page.tsx          # Complete frontend (single file)
β”‚   β”œβ”€β”€ layout.tsx        # Root layout
β”‚   └── globals.css       # Global styles + animations
β”œβ”€β”€ api.py                # Complete backend (single file)
β”œβ”€β”€ package.json          # Frontend dependencies
β”œβ”€β”€ requirements.txt      # Python dependencies
β”œβ”€β”€ next.config.js        # Next.js config with API proxy
β”œβ”€β”€ tailwind.config.ts    # TailwindCSS config
β”œβ”€β”€ postcss.config.js     # PostCSS config
β”œβ”€β”€ tsconfig.json         # TypeScript config
└── README.md             # This file

Runtime directories (auto-created):

Finance-ai/
β”œβ”€β”€ uploads/              # Uploaded documents
β”œβ”€β”€ vector_db/            # FAISS indexes
└── metadata.json         # Document metadata

πŸ”Œ API Endpoints

Method Endpoint Description
POST /chat Streaming LLM chat (SSE)
POST /upload Upload & ingest documents
POST /query RAG-based Q&A over documents
POST /agent Multi-agent workflow execution
POST /plot Generate charts from data
GET /documents List all uploaded documents
DELETE /documents/{id} Delete a document

Example: Chat Request

curl -X POST http://localhost:8000/chat \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Explain EBITDA"}],
    "api_key": "sk-...",
    "api_url": "https://api.openai.com/v1",
    "model": "gpt-4"
  }'

Example: Upload Document

curl -X POST http://localhost:8000/upload \
  -F "file=@financial_report.pdf"

Example: RAG Query

curl -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What were the Q3 revenue figures?",
    "document_id": "abc-123",
    "api_key": "sk-...",
    "api_url": "https://api.openai.com/v1",
    "model": "gpt-4"
  }'

πŸ€– Multi-Agent System

The /agent endpoint runs an AutoGen-style pipeline:

User Query
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Document Parser   β”‚  Extracts and structures document content
β”‚ Agent             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Data Analyst     β”‚  Analyzes financial data, generates insights
β”‚ Agent             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Visualization    β”‚  Creates charts and visual representations
β”‚ Agent             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
    Final Output (streamed via SSE)

Each agent step is streamed as an SSE event so the frontend can display progress in real-time.


πŸ› οΈ Tech Stack

Frontend

  • Next.js 14 β€” React framework (App Router)
  • TailwindCSS β€” Utility-first styling
  • Framer Motion β€” Animations
  • React Markdown β€” Markdown rendering
  • Lucide React β€” Icons

Backend

  • FastAPI β€” Async Python web framework
  • FAISS β€” Vector similarity search
  • LangChain β€” LLM orchestration
  • Matplotlib β€” Chart generation
  • OpenAI Python SDK β€” LLM integration

Supported LLM Providers

  • OpenAI (GPT-4, GPT-3.5)
  • vLLM (any HuggingFace model)
  • Any OpenAI-compatible API

πŸ“„ License

MIT License β€” feel free to use and modify.

About

123 chat

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors