2025-05-09 17:38:58 +01:00
|
|
|
# OpenWebUI Backend Service
|
2025-05-09 15:41:16 +01:00
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
This is a backend service for OpenWebUI that provides OpenWebUI-compatible API endpoints for chat functionality and model switching.
|
2025-05-09 15:41:16 +01:00
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
- OpenWebUI-compatible API endpoints
|
|
|
|
|
- Ollama API proxy
|
2025-05-09 15:41:16 +01:00
|
|
|
- Chat functionality with model switching
|
2025-05-09 17:38:58 +01:00
|
|
|
- Support for multiple LLM models (gemma3, llama3.3, llama3.1, mistral, deepseek)
|
2025-05-09 15:41:16 +01:00
|
|
|
|
|
|
|
|
## Project Structure
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ai_service/
|
|
|
|
|
├── models/ # Model and chat services
|
2025-05-09 17:38:58 +01:00
|
|
|
│ ├── model_service.py
|
|
|
|
|
│ ├── chat_service.py
|
|
|
|
|
│ └── model_parameters.py
|
|
|
|
|
├── embeddings/ # Document processing for RAG
|
|
|
|
|
│ └── document_service.py
|
|
|
|
|
├── openwebui_api.py # OpenWebUI-compatible API endpoints
|
2025-05-09 15:41:16 +01:00
|
|
|
├── config.py # Configuration settings
|
|
|
|
|
├── api.py # FastAPI application
|
2025-05-09 17:38:58 +01:00
|
|
|
└── deploy.sh # Deployment script
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Setup Instructions
|
|
|
|
|
|
|
|
|
|
1. Create a virtual environment:
|
|
|
|
|
```
|
|
|
|
|
python -m venv venv
|
|
|
|
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. Install dependencies:
|
|
|
|
|
```
|
|
|
|
|
pip install -r requirements.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
3. Copy `.env.example` to `.env` and update the values:
|
|
|
|
|
```
|
|
|
|
|
cp .env.example .env
|
|
|
|
|
# Edit the .env file with appropriate values
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
4. Run the service:
|
|
|
|
|
```
|
2025-05-09 17:38:58 +01:00
|
|
|
python ../run_ai_service.py
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## API Documentation
|
|
|
|
|
|
|
|
|
|
Once the service is running, you can access the API documentation at:
|
2025-05-09 20:00:26 +01:00
|
|
|
- Swagger UI: http://localhost:5252/docs
|
|
|
|
|
- ReDoc: http://localhost:5252/redoc
|
2025-05-09 15:41:16 +01:00
|
|
|
|
|
|
|
|
## Deployment
|
|
|
|
|
|
|
|
|
|
To deploy the service:
|
|
|
|
|
|
|
|
|
|
1. Make the deployment script executable:
|
|
|
|
|
```
|
|
|
|
|
chmod +x deploy.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. Run the deployment script:
|
|
|
|
|
```
|
|
|
|
|
./deploy.sh
|
|
|
|
|
```
|
|
|
|
|
|
2025-05-09 20:00:26 +01:00
|
|
|
This will start the service on port 5252 using uvicorn with nohup.
|
2025-05-09 15:41:16 +01:00
|
|
|
|
|
|
|
|
## API Endpoints
|
|
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
### Health Check
|
2025-05-09 15:41:16 +01:00
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
- `GET /health` - Check if the service is running
|
2025-05-09 15:41:16 +01:00
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
### OpenWebUI-Compatible Endpoints
|
2025-05-09 15:41:16 +01:00
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
- `GET /api/models` - Get available models in OpenWebUI format
|
|
|
|
|
- `POST /api/chat/completions` - OpenAI-compatible chat completions endpoint
|
2025-05-09 15:41:16 +01:00
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
### Ollama API Proxy
|
|
|
|
|
|
|
|
|
|
- `POST /ollama/api/generate` - Proxy to Ollama's generate endpoint
|
|
|
|
|
|
|
|
|
|
### Original API Endpoints
|
2025-05-09 15:41:16 +01:00
|
|
|
|
|
|
|
|
- `POST /chats` - Create a new chat
|
|
|
|
|
- `GET /chats/user/{user_id}` - Get all chats for a user
|
|
|
|
|
- `GET /chats/{chat_id}` - Get a chat by ID
|
|
|
|
|
- `POST /chats/{chat_id}/messages` - Send a message to a chat
|
|
|
|
|
- `POST /chats/{chat_id}/members/{user_id}` - Add a user to a team chat
|
|
|
|
|
- `DELETE /chats/{chat_id}/members/{user_id}` - Remove a user from a team chat
|
|
|
|
|
- `DELETE /chats/{chat_id}` - Delete a chat
|