2.4 KiB
2.4 KiB
OpenWebUI Backend Service
This is a backend service for OpenWebUI that provides OpenWebUI-compatible API endpoints for chat functionality and model switching.
Features
- OpenWebUI-compatible API endpoints
- Ollama API proxy
- Chat functionality with model switching
- Support for multiple LLM models (gemma3, llama3.3, llama3.1, mistral, deepseek)
Project Structure
ai_service/
├── models/ # Model and chat services
│ ├── model_service.py
│ ├── chat_service.py
│ └── model_parameters.py
├── embeddings/ # Document processing for RAG
│ └── document_service.py
├── openwebui_api.py # OpenWebUI-compatible API endpoints
├── config.py # Configuration settings
├── api.py # FastAPI application
└── deploy.sh # Deployment script
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_ai_service.py
API Documentation
Once the service is running, you can access the API documentation at:
- Swagger UI: http://localhost:5252/docs
- ReDoc: http://localhost:5252/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 5252 using uvicorn with nohup.
API Endpoints
Health Check
GET /health- Check if the service is running
OpenWebUI-Compatible Endpoints
GET /api/models- Get available models in OpenWebUI formatPOST /api/chat/completions- OpenAI-compatible chat completions endpoint
Ollama API Proxy
POST /ollama/api/generate- Proxy to Ollama's generate endpoint
Original API 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