Files
2025-05-09 20:00:26 +01:00

98 lines
2.4 KiB
Markdown

# 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
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:
```
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:
1. Make the deployment script executable:
```
chmod +x deploy.sh
```
2. 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 format
- `POST /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 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