Sunbird VA RAG is a Flask-based chat API that utilizes LLMs for generating responses and using Vector Search for document retrieval. The application also integrates with Redis for message history caching and supports dynamic message formatting.
- Flask-based REST API server.
- OpenAI integration for chat completions.
- Redis integration for storing and retrieving session-based message histories.
- Token counting for managing API requests.
- Custom message formatting to control user and assistant interactions.
- Python 3.x
- Flask
- openai
- tiktoken
- redis
- flask_cors
- zlib
- pickle
- Set up a virtual environment and install dependencies.
- Configure the following environment variables:
REDIS_HOST
: Host for your Redis instance. Default islocalhost
.REDIS_PORT
: Port for your Redis instance. Default is6379
.REDIS_DB
: Database index for your Redis instance. Default is0
.OPENAI_API_KEY
: Your OpenAI API key.
To enable search capabilities, implement the vector search function in the search_documents
function placeholder. You may use any vector search library of your choice.
To run the server:
python api.py
Then, you can access the chat API endpoint at:
GET /sunbird-assistant/answer?q=[YOUR_QUESTION]&session_id=[OPTIONAL_SESSION_ID]
/sunbird-assistant/answer
(GET)- Params:
q
: The question you want to ask the Sunbird Assistant.session_id
: (Optional) Session ID for maintaining chat history. Default is "default".
- Returns: Assistant's answer as plain text.
- Params: