FastAPIChat is a powerful application for testing and evaluating large language model based chatbots.
- FastAPIChat powers LLM Arena, serving over 10+ LLMs, for diverse and dynamic chatbot interactions
- FastAPIChat enables seamlessly rate LLM generated responses, ensuring continuous improvement based on user feedback.
- [2024/06] π₯ We released FastAPIChat v1.0.0
More
- [2024/06] We released FastAPIChat v1.0.0 with ChatBot and ChatBot Arena
Key features:
- π¬ LLM Chats(10+ LLMs)
- βοΈ LLM Arena
- π³οΈ Chat Feedback collection
- β‘ FastAPI API Documentation and Authentication
FastAPIChat integrates seamlessly with Python programs and libraries and includes out-of-the-box integrations for:
Note: To begin, you'll need an API key from OpenRouter.
- Note: In Dev mode, the default config with backend is SQLite.
- Clone Repo:
git clone https://github.com/yuting1214/FastAPIChat.git
- Configure Virtual Environment (Recommended):
-
Create Virtual Environment
# macOS/Linux # You may need to run `sudo apt-get install python3-venv` first on Debian-based OSs python3 -m venv .venv # Windows # You can also use `py -3 -m venv .venv` python -m venv .venv
-
Activate the virtual environment:
# macOS/Linux source .venv/bin/activate # Windows .venv\Scripts\activate
- Install Dependencies:
pip install -r requirements.txt
- Update the .env file with
USER_NAME=<API_Doc_Username>
PASSWORD=min=<API_Doc_PASSWORD>
OPENROUTER_API_KEY=<Your_API_KEY>
- Run the application:
python -m backend.app.main --mode dev
- Add extra envs in with your environment configurations:
DB_ENGINE=<Your_DB_config>
DB_USERNAME=<Your_DB_config>
DB_PASS=<Your_DB_config>
DB_HOST=<Your_DB_config>
DB_PORT=<Your_DB_config>
DB_NAME=<Your_DB_config>
API_BASE_URL=<Your_Host_URL>
- Run the application:
python -m backend.app.main --mode prod
- Alternatively, use Dockerfile for deployment.
- Control quotas by adjusting limits in
backend/app/core/constants.py
:
TEXT_API_QUOTA_LIMIT = <int>
- To add a new LLM model, specify its details in backend/data/llm_models:
{
'llm_model_name': 'Mixtral 8x22B',
'llm_vendor': 'Mistral AI',
'llm_type': 'text',
'api_provider': 'OpenRouter',
'api_endpoint': 'mistralai/mixtral-8x22b-instruct',
}
-
Utilize Gradio and FastAPI Integration: Seamlessly combine Gradio for the frontend display and FastAPI for robust backend functionality, offering a smooth user experience.
-
Well-Crafted API Management: Our meticulously designed API ensures efficient data transportation and effective management of API quota usage, providing users with a reliable and hassle-free experience.
-
Integration of Leading Language Models: Integrate more than 10+ popular language models from various vendors, including OpenAI, Mistral, Meta and Anthropic, enabling users to leverage cutting-edge AI capabilities for text generation.
-
Comprehensive Testing and Documentation: Benefit from comprehensive testing suites and detailed documentation, empowering developers to understand and contribute to the project with ease, ensuring robustness and maintainability. Third-Party Services: Integrate with third-party APIs for enhanced functionality.
-
Third-Party Services Integration: Seamlessly integrates with third-party APIs for enhanced functionality.
- Project Details: Heptabase
More Project Details
FastAPIChat/
βββ backend/ # Backend directory for the FastAPI application
β βββ app/ # Main application directory
β β βββ __init__.py # Initialization file for the app package
β β βββ api/ # Directory for API related code
β β β βββ __init__.py # Initialization file for the API package
β β β βββ v1/ # Version 1 of the API
β β β β βββ __init__.py # Initialization file for the v1 API package
β β β β βββ endpoints/ # Directory for API endpoint definitions
β β β β β βββ __init__.py # Initialization file for endpoints package
β β β β β βββ text_generation.py # Endpoints for text generation
β β β β β βββ llm_management.py # Endpoints for LLM model management
β β β β β βββ api_usage.py # Endpoints for API usage management
β β β β β βββ api_calldetail.py # Endpoints for API Detail management
β β β β β βββ message.py # Endpoints for messasge management
β β β β β βββ chat.py # Endpoints for chat management
β β β β β βββ rating.py # Endpoints for rating management
β β β β β βββ user.py # Endpoints for user management
β β β β β βββ quota.py # Endpoints for quota management
β β β β β βββ doc.py # Endpoints for OpenAPI doc management
β β βββ dependencies/ # Directory for dependency management
β β β βββ __init__.py # Initialization file for dependencies package
β β β βββ database.py # Database connection and session management
β β β βββ rate_limiter.py # Rate limiting logic
β β βββ core/ # Core application logic
β β β βββ __init__.py # Initialization file for core package
β β β βββ constant.py # Constant settings
β β β βββ config.py # Configuration settings
β β β βββ init_setting.py # Init settings with user's input
β β βββ models/ # Directory for SQLAlchemy models
β β β βββ __init__.py # Initialization file for models package
β β β βββ user.py # User model
β β β βββ quota.py # Quota model
β β β βββ message.py # Message model
β β β βββ api_usage.py # API usage model
β β β βββ llm.py # LLM model
β β β βββ chat.py # Chat model
β β β βββ rating.py # rating model
β β βββ schemas/ # Directory for Pydantic schemas
β β β βββ __init__.py # Initialization file for schemas package
β β β βββ user.py # Schemas for user data
β β β βββ quota.py # Schemas for quota data
β β β βββ message.py # Schemas for message data
β β β βββ api_usage.py # Schemas for API usage data
β β β βββ llm.py # Schemas for LLM model data
β β β βββ llm_message.py # Schemas for LLM generated output data
β β β βββ chat.py # Schemas for chat data
β β β βββ rating.py # Schemas for rating data
β β βββ crud/ # Directory for CRUD operations
β β β βββ __init__.py # Initialization file for crud package
β β β βββ user.py # CRUD for user management
β β β βββ quota.py # CRUD for quota management
β β β βββ message.py # CRUD for message management
β β β βββ api_usage.py # CRUD for API usage management
β β β βββ llm.py # CRUD for LLM model management
β β β βββ llm_message.py # CRUD for LLM generated output management
β β β βββ chat.py # CRUD for chat management
β β β βββ rating.py # CRUD for rating management
β β βββ main.py # Main FastAPI application file
β βββ data/ # Directory for data when initiating db
β β βββ __init__.py # Initialization file for data package
β β βββ llm_models.py # LLM models infomation
β βββ security/ # New directory for authentication and authorization
β β βββ __init__.py # Initialization file for security package
β β βββ authentication.py # Authentication logic
β β βββ authorization.py # Authorization logic
β βββ tests/ # Directory for test files
β β βββ __init__.py # Initialization file for tests package
β β βββ test_text_generation.py # Tests for text generation endpoints
βββ frontend/ # Frontend directory for the Gradio app
β βββ __init__.py # Initialization file for frontend package
β βββ gradio/ # Main gradio UI directory
β β βββ __init__.py # Initialization file for the gradio package
β β βββ text/ # Directory for ChatBot UI related code
β β β βββ __init__.py # Initialization file for the text package
β β β βββ event_listeners.py #
β β β βββ text_generation.py #
β β β βββ text_generation_arena.py
β βββ login/ # Main login UI directory
β β βββ __init__.py # Initialization file for the gradio package
β β βββ static/ # Directory for static files
β β β βββ style.css # CSS for login UI
β β βββ templates/ # Directory for HTML templates
β β β βββ base.html # HTML base template
β β β βββ login.html # HTML login template
βββ llm/
β βββ __init__.py # Makes llm a Python package
β βββ llm_text_chain.py # Module for LLM text generation integration
β βββ prompt/ # Folder for prompt handling
β βββ __init__.py # Initializes the prompt package
β βββ base_text_templates.py# Stores base prompt templates for text generation
β βββ examples/ # Directory for few-shot examples used by the chain
β βββ deprecated/ # Directory for deprecated prompts
β βββ vendors/ # Directory for vendor-specific LLM configurations
β βββ __init__.py # Makes vendors a Python package
β βββ openrouter.py # Configurations and usage for OpenRouter as LLM provider
βββ .env # Environment variables file
βββ .gitignore # Git ignore file
βββ requirements.txt # Python dependencies file
βββ Dockerfile # Docker configuration
βββ README.md # Project README file
-
Integraion of local LLM: Integrate with Ollama to enable users to run LLMs locally and battle with LLMs from API.
-
Integraion of RAG LLM: Enable users to compare different configuration of RAG LLM in LLM Arena.
-
Integration of Redis or other NoSQL Databases: Incorporate Redis or other NoSQL databases to efficiently track and store user history data, enabling personalized experiences and insights for users.
-
History Message Management: Allow user to fetch back the previous messages from database and continue the chat.
-
Rate Limiter: Integrate rate limiter for API protection.
We welcome contributions from the community! Whether it's bug fixes, feature enhancements, or documentation improvements, feel free to open a pull request.
Designed with β€οΈ by Mark Chen