Using the ai_service as backend for openwebui
This commit is contained in:
@@ -1,61 +1,90 @@
|
||||
# Chatbot Application
|
||||
# OpenWebUI Backend Service
|
||||
|
||||
A chatbot application with document training, private/team chat options, and model switching capability.
|
||||
A backend service for OpenWebUI that provides OpenWebUI-compatible API endpoints for chat functionality and model switching.
|
||||
|
||||
## Features
|
||||
|
||||
- Document training through library page
|
||||
- Private chat functionality
|
||||
- Team chat functionality (multiple users can see each other's interactions)
|
||||
- Model switching capability
|
||||
- OpenWebUI-compatible API endpoints
|
||||
- Ollama API proxy
|
||||
- Chat functionality with model switching
|
||||
- Support for multiple LLM models (gemma3, llama3.3, llama3.1, mistral, deepseek)
|
||||
|
||||
## Technology Stack
|
||||
|
||||
- **Backend**: Flask with FastAPI
|
||||
- **Database**: MySQL
|
||||
- **Vector Database**: Pinecone
|
||||
- **Embeddings**: Sentence Transformers / OpenAI Embeddings
|
||||
- **Chat Models**: Various LLMs (configurable)
|
||||
- **Backend**: FastAPI
|
||||
- **Chat Models**: Ollama models via OpenWebUI
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
app/
|
||||
├── api/ # API endpoints (Flask and FastAPI)
|
||||
├── config/ # Configuration settings
|
||||
├── database/ # Database connection and utilities
|
||||
├── models/ # Database models
|
||||
├── services/ # Business logic services
|
||||
└── utils/ # Utility functions
|
||||
tests/ # Test cases
|
||||
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
|
||||
```
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
1. Clone the repository
|
||||
2. Create a virtual environment:
|
||||
1. Create a virtual environment:
|
||||
```
|
||||
python -m venv venv
|
||||
source venv/bin/activate # On Windows: venv\Scripts\activate
|
||||
```
|
||||
3. Install dependencies:
|
||||
|
||||
2. Install dependencies:
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
4. Copy `.env.example` to `.env` and update the values
|
||||
5. Initialize the database:
|
||||
|
||||
3. Copy `.env.example` to `.env` and update the values:
|
||||
```
|
||||
flask db init
|
||||
flask db migrate
|
||||
flask db upgrade
|
||||
cp ai_service/.env.example ai_service/.env
|
||||
# Edit the .env file with appropriate values
|
||||
```
|
||||
6. Run the application:
|
||||
|
||||
4. Run the service:
|
||||
```
|
||||
python run.py
|
||||
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]
|
||||
```
|
||||
|
||||
## API Documentation
|
||||
|
||||
Once the application is running, you can access the API documentation at:
|
||||
- FastAPI Swagger UI: http://localhost:5000/docs
|
||||
- FastAPI ReDoc: http://localhost:5000/redoc
|
||||
Once the service is running, you can access the API documentation at:
|
||||
- Swagger UI: http://localhost:5251/docs
|
||||
- ReDoc: http://localhost:5251/redoc
|
||||
|
||||
## OpenWebUI Configuration
|
||||
|
||||
To configure OpenWebUI to use this service as its backend:
|
||||
|
||||
1. Set the following environment variables in OpenWebUI:
|
||||
```
|
||||
OLLAMA_API_BASE_URL=http://your-server-ip:5251/ollama
|
||||
OPENAI_API_BASE_URL=http://your-server-ip:5251/api
|
||||
```
|
||||
|
||||
2. Restart OpenWebUI to apply the changes.
|
||||
|
||||
Reference in New Issue
Block a user