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
|
|
|
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
|
|
|
|
|
- Chat functionality with model switching
|
|
|
|
|
- Support for multiple LLM models (gemma3, llama3.3, llama3.1, mistral, deepseek)
|
2025-05-09 15:41:16 +01:00
|
|
|
|
|
|
|
|
## Technology Stack
|
|
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
- **Backend**: FastAPI
|
|
|
|
|
- **Chat Models**: Ollama models via OpenWebUI
|
2025-05-09 15:41:16 +01:00
|
|
|
|
|
|
|
|
## Project Structure
|
|
|
|
|
|
|
|
|
|
```
|
2025-05-09 17:38:58 +01:00
|
|
|
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
|
|
|
|
|
run_ai_service.py # Script to run the service
|
|
|
|
|
deploy_ai_service.sh # Local deployment script
|
|
|
|
|
remote_deploy.sh # Remote deployment script
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Setup Instructions
|
|
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
1. Create a virtual environment:
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
|
|
|
|
python -m venv venv
|
|
|
|
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
|
|
|
```
|
2025-05-09 17:38:58 +01:00
|
|
|
|
|
|
|
|
2. Install dependencies:
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
|
|
|
|
pip install -r requirements.txt
|
|
|
|
|
```
|
2025-05-09 17:38:58 +01:00
|
|
|
|
|
|
|
|
3. Copy `.env.example` to `.env` and update the values:
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
2025-05-09 17:38:58 +01:00
|
|
|
cp ai_service/.env.example ai_service/.env
|
|
|
|
|
# Edit the .env file with appropriate values
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
2025-05-09 17:38:58 +01:00
|
|
|
|
|
|
|
|
4. Run the service:
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
2025-05-09 17:38:58 +01:00
|
|
|
python run_ai_service.py
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Deployment
|
|
|
|
|
|
|
|
|
|
To deploy the service:
|
|
|
|
|
|
|
|
|
|
1. Local deployment:
|
|
|
|
|
```
|
|
|
|
|
./deploy_ai_service.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. Remote deployment:
|
|
|
|
|
```
|
|
|
|
|
./remote_deploy.sh [server_ip] [user] [port] [remote_dir]
|
2025-05-09 15:41:16 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## API Documentation
|
|
|
|
|
|
2025-05-09 17:38:58 +01:00
|
|
|
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 17:38:58 +01:00
|
|
|
|
|
|
|
|
## OpenWebUI Configuration
|
|
|
|
|
|
|
|
|
|
To configure OpenWebUI to use this service as its backend:
|
|
|
|
|
|
|
|
|
|
1. Set the following environment variables in OpenWebUI:
|
|
|
|
|
```
|
2025-05-09 20:00:26 +01:00
|
|
|
OLLAMA_API_BASE_URL=http://your-server-ip:5252/ollama
|
|
|
|
|
OPENAI_API_BASE_URL=http://your-server-ip:5252/api
|
2025-05-09 17:38:58 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. Restart OpenWebUI to apply the changes.
|