Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -10,23 +10,97 @@ app_port: 7860
|
|
| 10 |
|
| 11 |
# ChatKit Python Backend
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
- **Fact recording tool** that renders a confirmation widget with _Save_ and _Discard_ actions.
|
| 21 |
-
- **Guardrail-ready system prompt** extracted into `app/constants.py` so it is easy to modify.
|
| 22 |
-
- **Simple fact store** backed by in-memory storage in `app/facts.py`.
|
| 23 |
-
- **REST helpers**
|
| 24 |
-
- `GET /facts` β list saved facts (used by the frontend list view)
|
| 25 |
-
- `POST /facts/{fact_id}/save` β mark a fact as saved
|
| 26 |
-
- `POST /facts/{fact_id}/discard` β discard a pending fact
|
| 27 |
-
- `GET /health` β surface a basic health indicator
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
To enable the realtime assistant you need to install both the ChatKit Python package and the OpenAI SDK, then provide an `OPENAI_API_KEY` environment variable.
|
| 32 |
|
|
|
|
| 10 |
|
| 11 |
# ChatKit Python Backend
|
| 12 |
|
| 13 |
+
This FastAPI service implements an advanced multi-agent support system using the **OpenAI Agents SDK** and **OpenAI ChatKit**. It provides specialized support agents for different platforms (Kimi, DeepSeek, Google) with integrated RAG and persistent memory.
|
| 14 |
|
| 15 |
+
## ποΈ Architecture Overview
|
| 16 |
|
| 17 |
+
The system is built on a modular, agentic architecture designed for high-performance customer support.
|
| 18 |
|
| 19 |
+
### Component Diagram
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
```mermaid
|
| 22 |
+
graph TD
|
| 23 |
+
Client[ChatKit Frontend] <--> API[FastAPI Orchestrator]
|
| 24 |
+
|
| 25 |
+
subgraph "Agent Layer"
|
| 26 |
+
API <--> KimiAgent[Kimi Agent]
|
| 27 |
+
API <--> DeepSeekAgent[DeepSeek Agent]
|
| 28 |
+
API <--> GoogleAgent[Google Agent]
|
| 29 |
+
API <--> Summ[Summarizer Agent]
|
| 30 |
+
end
|
| 31 |
+
|
| 32 |
+
subgraph "Tools & Intelligence"
|
| 33 |
+
KimiAgent & DeepSeekAgent & GoogleAgent --> RAG[LlamaIndex RAG Tool]
|
| 34 |
+
KimiAgent & DeepSeekAgent & GoogleAgent --> Facts[Fact Recording Tool]
|
| 35 |
+
RAG --> Chroma[ChromaDB Vector Store]
|
| 36 |
+
RAG --> WebsiteData[Website Knowledge Base]
|
| 37 |
+
end
|
| 38 |
+
|
| 39 |
+
subgraph "Persistence"
|
| 40 |
+
API --> SQLiteThreads[SQLite: Chat Threads]
|
| 41 |
+
API --> SQLiteState[SQLite: User State]
|
| 42 |
+
end
|
| 43 |
+
|
| 44 |
+
subgraph "External Providers"
|
| 45 |
+
KimiAgent --> Groq[Groq API]
|
| 46 |
+
DeepSeekAgent --> OpenRouter[OpenRouter API]
|
| 47 |
+
GoogleAgent --> OR_Gemini[OpenRouter/Gemini]
|
| 48 |
+
end
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### Key Components
|
| 52 |
+
|
| 53 |
+
1. **FastAPI Orchestrator**: Handles request routing, SSE streaming, and handoffs between Agents and ChatKit.
|
| 54 |
+
2. **OpenAI Agents SDK**: Provides the logic for agent loops, tool calling, and handoffs.
|
| 55 |
+
3. **ChatKit Server**: Manages the ChatKit protocol, ensuring real-time UI updates (widgets, thoughts, tool results).
|
| 56 |
+
4. **Vector RAG Engine**: Uses LlamaIndex and ChromaDB to query school-specific services from scraped website data.
|
| 57 |
+
5. **Multi-Modal**: Integrated Groq Whisper for audio transcriptions.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## π€ Model Configuration
|
| 62 |
+
|
| 63 |
+
The system utilizes a specialized mix of state-of-the-art models to balance performance, cost, and reasoning capabilities.
|
| 64 |
+
|
| 65 |
+
| Agent / Service | Model Name | Primary Provider | API Class |
|
| 66 |
+
| :--- | :--- | :--- | :--- |
|
| 67 |
+
| **Kimi Agent** | `moonshotai/kimi-k2-instruct-0905` | **Groq** | `OpenAIResponsesModel` |
|
| 68 |
+
| **DeepSeek Agent** | `deepseek/deepseek-chat` | **OpenRouter** | `OpenAIChatCompletionsModel` |
|
| 69 |
+
| **Google Agent** | `google/gemini-2.5-flash` | **OpenRouter** | `OpenAIChatCompletionsModel` |
|
| 70 |
+
| **Summarizer Agent** | `meta-llama/llama-4-scout-17b-16e-instruct` | **Groq** | `OpenAIResponsesModel` |
|
| 71 |
+
| **Audio Transcription** | `whisper-large-v3-turbo` | **Groq** | Native Deepgram/Whisper |
|
| 72 |
+
|
| 73 |
+
---
|
| 74 |
+
|
| 75 |
+
## π Assumptions & Limitations
|
| 76 |
+
|
| 77 |
+
### Assumptions
|
| 78 |
+
- **API Availability**: The system assumes stable connections to Groq and OpenRouter.
|
| 79 |
+
- **Static Knowledge**: The RAG system assumes the vector database is pre-built from the school's website data (accessible in the `website/` folder).
|
| 80 |
+
- **Single Instance**: Currently architected for single-instance deployment (SQLite persistence).
|
| 81 |
+
|
| 82 |
+
### Limitations
|
| 83 |
+
- **Responses API Compatibility**: Only Groq natively supports the full `OpenAIResponsesModel` required for advanced thread state. OpenRouter models use `OpenAIChatCompletionsModel` with a custom persistence bridge.
|
| 84 |
+
- **Concurrency**: SQLite is configured in WAL mode, but extremely high concurrent traffic would require a transition to PostgreSQL.
|
| 85 |
+
- **Context Limits**: While the Summarizer Agent mitigates context bloat, extremely complex multi-turn sessions still rely on the provider's context window (e.g., 128k for DeepSeek/Gemini).
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## π° Cost Estimation (Rough Calculation)
|
| 90 |
+
|
| 91 |
+
*Calculations based on 1,000 user queries with an average of 2,000 tokens per turn (1,500 input / 500 output).*
|
| 92 |
+
|
| 93 |
+
| Model (Provider) | Input Cost (per 1k) | Output Cost (per 1k) | **Estimated Total / 1,000 Queries** |
|
| 94 |
+
| :--- | :--- | :--- | :--- |
|
| 95 |
+
| **DeepSeek V3** (OpenRouter) | $0.21 | $0.14 | **$0.35** |
|
| 96 |
+
| **Gemini 1.5 Flash** (OpenRouter) | $0.11 | $0.15 | **$0.26** |
|
| 97 |
+
| **Llama 3.3 70B** (Groq) | Free Tier / $0 | Free Tier / $0 | **$0.00** |
|
| 98 |
+
|
| 99 |
+
*Note: Costs are based on current OpenRouter pricing (Jan 2025) and Groq's current free-tier offering. Prices may fluctuate based on provider updates.*
|
| 100 |
+
|
| 101 |
+
---
|
| 102 |
+
|
| 103 |
+
## π Getting Started
|
| 104 |
|
| 105 |
To enable the realtime assistant you need to install both the ChatKit Python package and the OpenAI SDK, then provide an `OPENAI_API_KEY` environment variable.
|
| 106 |
|