2.4 KiB
2.4 KiB
AI Service for Chatbot Application
This is the AI service component for the chatbot application. It provides APIs for document processing, embeddings, and chat functionality.
Features
- Document processing and embedding
- Retrieval-augmented generation (RAG)
- Chat functionality with model switching
- Team chat support
Project Structure
ai_service/
├── embeddings/ # Embedding and document processing services
├── models/ # Model and chat services
├── utils/ # Utility functions
├── data/ # Data storage
├── config.py # Configuration settings
├── api.py # FastAPI application
└── run.py # Script to run the service
Setup Instructions
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt -
Copy
.env.exampleto.envand update the values:cp .env.example .env # Edit the .env file with appropriate values -
Run the service:
python run.py
API Documentation
Once the service is running, you can access the API documentation at:
- Swagger UI: http://localhost:5251/docs
- ReDoc: http://localhost:5251/redoc
Deployment
To deploy the service:
-
Make the deployment script executable:
chmod +x deploy.sh -
Run the deployment script:
./deploy.sh
This will start the service on port 5251 using uvicorn with nohup.
API Endpoints
Document Endpoints
POST /documents- Process a document for embeddingGET /documents- Get all documentsGET /documents/{doc_id}- Get a document by IDDELETE /documents/{doc_id}- Delete a documentPOST /documents/search- Search for documents
Model Endpoints
GET /models- Get available modelsGET /models/{model_id}- Get information about a model
Chat Endpoints
POST /chats- Create a new chatGET /chats/user/{user_id}- Get all chats for a userGET /chats/{chat_id}- Get a chat by IDPOST /chats/{chat_id}/messages- Send a message to a chatPOST /chats/{chat_id}/members/{user_id}- Add a user to a team chatDELETE /chats/{chat_id}/members/{user_id}- Remove a user from a team chatDELETE /chats/{chat_id}- Delete a chat