A sophisticated conversational AI system built with Python, FastAPI, and LangChain Core, designed to provide intelligent chatbot capabilities using various language models including Nebius and OpenAI.
- Multi-LLM Support: Integrates with Nebius and OpenAI language models
- Vector Database Integration: Uses ChromaDB for context management and retrieval-augmented generation (RAG)
- Modular Architecture: Agent-based design for easy extension and maintenance
- Async/Await Support: Non-blocking operations for better performance
- FastAPI Backend: High-performance web framework with automatic API documentation
- Conversation Context Management: Persistent conversation handling with context managers
- End-to-End Testing: Comprehensive test suite with unit and integration tests
- Docker Support: Containerized deployment with Docker Compose
.
├── .env.example # Environment variables template
├── .github/ # GitHub workflows
│ ├── workflows/
│ │ ├── pytest.yml # Test workflow
│ │ └── ruff-linter.yml # Linting workflow
├── Dockerfile # Docker configuration
├── README.md # This file
├── commands.py # Utility commands
├── docker-compose.yml # Docker Compose configuration
├── main.py # Entry point for the application
├── pyproject.toml # Dependencies and project configuration
├── scripts/ # Utility scripts
│ └── create_vectordb.py # Database setup script
├── src/
│ ├── __init__.py # Package initialization
│ ├── agents/ # Agent implementations for different LLMs
│ │ ├── __init__.py # Package initialization
│ │ ├── nebius_agent.py # Nebius LLM agent
│ │ ├── openai_agent.py # OpenAI LLM agent
│ │ └── context_managers/ # Context management components
│ │ ├── __init__.py # Package initialization
│ │ ├── chroma_cm.py # ChromaDB-based context manager
│ │ └── prompts.py # Prompt templates
│ ├── api/ # API layer with routes and app setup
│ │ ├── __init__.py # Package initialization
│ │ ├── app.py # FastAPI application factory
│ │ ├── deps.py # Dependency injection
│ │ ├── models.py # Pydantic models for API requests/responses
│ │ └── routes/ # API endpoints
│ │ ├── __init__.py # Package initialization
│ │ └── chatbot.py # Chat endpoint implementation
│ ├── core/ # Core system components
│ │ ├── __init__.py # Package initialization
│ │ ├── agent.py # Base Agent class
│ │ ├── consts.py # Constants
│ │ └── entities/ # Core entity classes
│ │ ├── __init__.py # Package initialization
│ │ ├── context_manager.py # Base context manager interface
│ │ └── vector_store.py # Base vector store interface
│ ├── settings.py # Configuration management
│ ├── tests/ # Test suite
│ │ ├── __init__.py # Package initialization
│ │ ├── test_agent.py # Unit tests for agents
│ │ └── e2e/ # End-to-end tests
│ │ ├── __init__.py # Package initialization
│ │ └── test_chatbot.py # End-to-end chatbot tests
│ └── tools/ # Utility tools
│ ├── __init__.py # Package initialization
└── docs/ # Documentation files
└── terminal_commands.md # Terminal commands documentation- Python 3.12+
- uv package manager
- Docker (optional)
-
Clone the repository:
git clone <repository-url> cd cheki-bot-server
Clones the repository from the provided URL and enters the project directory.
-
Synchronize environment and install dependencies:
uv sync # This creates the virtual environment and installs the project dependencies source venv/bin/activate # On Windows: venv\Scripts\activate
Synchronizes the environment and installs the necessary project dependencies. Note: Ensure
uvis installed and available in your PATH. If not installed yet, install it via: https://github.com/astral-sh/uv -
Set up environment variables:
cp .env.example .env # Edit .env with your actual API keys and configurationsCopies the example environment file and configures the actual API keys and settings.
Create a .env file based on the provided .env.example:
ALLOW_ORIGINS: CORS allowed origins (default: http://localhost:5173)LLM_PROVIDER: Language model provider (default: openai)LLM_MODEL: LLM model to use (default: gpt-3.5-turbo)LLM_EMB_MODEL: LLM embedding model (default: text-embedding-3-small)LLM_API_KEY: Your LLM API key (required)LLM_TEMPERATURE: Sampling temperature for LLM responses (default: 0.7)LLM_MAX_TOKENS: Maximum tokens in LLM responses (default: 1000)LLM_CONTEXT_LENGTH: Maximum context length for LLM (default: 32768)CHROMA_PERSIST_DIRECTORY: ChromaDB persistence directory (default: chroma_db)
python main.pydocker-compose upThe API will be available at http://localhost:8000.
The system includes automatic API documentation:
- OpenAPI specification:
http://localhost:8000/docs - ReDoc interface:
http://localhost:8000/redoc
The chatbot provides two endpoints:
POST /chatbot/telegram_webhook- For handling Telegram webhook updatesGET /chatbot/ws- For real-time WebSocket chat interactions
Send a POST request to handle Telegram webhook updates:
# POST endpoint for chat messages
curl -X POST "http://localhost:8000/api/chatbot/telegram_webhook" \
-H "Content-Type: application/json" \
-d '{"content": "Hello, how are you?", "history": []}'Open a WebSocket connection for real-time chat interactions:
# WebSocket endpoint for real-time chat
curl -X GET "ws://localhost:8000/api/chatbot/ws"curl http://localhost:8000/healthNebiusAgent: Implements Nebius LLM integrationOpenAIAgent: Implements OpenAI GPT model integration
ChromaCM: ChromaDB-based context manager for semantic search- Handles conversation history and retrieval of relevant information
Agent: Base class for all agent implementationsBaseEntity: Base entity for conversation data structures
Run unit tests:
uv run pytest src/tests/test_agent.pyRun end-to-end tests:
uv run pytest src/tests/e2e/Run all tests:
uv run pytest- Follow PEP 8 coding standards
- Use type hints throughout the codebase
- Write comprehensive docstrings
- Add unit tests for new functionality
- Run linters and formatters before committing
- Ensure all tests pass before merging
- Built with FastAPI
- Uses LangChain Core
- Vector storage powered by ChromaDB
For support or questions, please open an issue in the repository.