Agent that answers questions using OpenAI and a local knowledge base.
The project is organized into three main components:
frontend/- Streamlit web UIbackend/- FastAPI REST APIai/- AI components (agents, tools, vector store)src/- Shared utilities (database, configuration)
Q&A agent using:
- LangChain +
langchain-openai - OpenAI GPT-4.1 (or compatible model via API key)
- Optional local knowledge in the
knowledgedirectory
- Python: 3.11+
- Poetry installed
- Install deps:
poetry install
- Set
OPENAI_API_KEY(via.envor environment variable)
Start the API server:
poetry run uvicorn backend.app:app --reload --host 0.0.0.0 --port 8000Then open the interactive Swagger UI:
- API docs:
http://localhost:8000/docs
From there you can:
-
List messages for a chat:
- Endpoint:
POST /chat/get_messages - Example body:
{ "chat_id": 1 }
- Endpoint:
-
Ask a question in a chat (with history + routing + KB):
- Endpoint:
POST /chat/answer - Example body:
{ "chat_id": 1, "question": "What do koalas eat?" }
- Endpoint:
-
Delete a chat:
- Endpoint:
DELETE /chat/delete?chat_id=1(e.g.DELETE /chat/delete?chat_id=1)
- Endpoint:
Start the Streamlit web interface:
poetry run streamlit run frontend/app.pyThe UI will open automatically in your browser at http://localhost:8501.
Features:
- 💬 Chat Interface: Ask questions and get answers from the agent
- 📚 Knowledge Base Management: Upload
.txtfiles to the knowledge base - 📝 Chat History: View and manage multiple chat sessions
- 🔍 Smart Search: The agent automatically searches the knowledge base when needed