AI Chatbot UI for aisuite
A Flask interface for chatting with multiple AI models in one place: saved histories, cost estimates and more. Built for the SAÜ AI Society chatbot workshop.
cat README.md
AI Chatbot UI for AI Suite Library
This project is created as part of a workshop titled "Chatbot Workshop: Design Your Own AI Assistant" conducted by the Sakarya University AI Society.
What is this Project?
This project enables users to easily interact with multiple AI models through a single interface. Equipped with advanced features, it offers capabilities like saving chat histories, estimating costs, and processing PDF files. It also supports both local and API-based models, providing exceptional flexibility.
Türkçe README için, buraya tıklayın
Key Features
-
Model Flexibility:
- Switch between different AI models within the same chat session, enabling diverse conversational experiences and comparisons.
-
Chat History Management:
- Save and revisit previous chats, allowing users to continue past conversations seamlessly.
-
Markdown Support:
- Display responses with Markdown formatting for enhanced readability, including features like links, code snippets, and lists.
-
Cost Estimation:
- Calculate the estimated cost of a conversation based on the pricing models of various AI APIs, helping users manage and predict expenses effectively.
-
Integration with Ollama:
- Utilize both local models and API-based models within the same chat session, offering flexibility in performance, privacy, and cost.
-
Crop Conversation for Infinite Chat:
- Automatically crops old conversations to ensure the context length remains within model limits, allowing for continuous, uninterrupted chatting.
-
PDF Upload Support (Text Only):
- Upload text-based PDF files to interact with their content directly in the chat interface. Ideal for extracting insights, summarizing, or asking questions about the document.
Setup Instructions (Windows)
Step 1: Install Required Libraries
-
Clone the repository:
git clone <repository-url> cd <repository-folder> -
Install the required Python libraries:
pip install -r requirements.txt
Step 2: Configure the Models
-
Navigate to the
model_config.jsonfile in the project directory. -
Update the model configuration with your API keys and model details. Below is an example structure:
{ "models": [ { "name": "OpenAI GPT-4o", "api_key": "Your API Key Here", "id": "openai:gpt-4o", "local": false }, { "name": "Ollama Llama3.2 3B", "api_key": "None", "id": "ollama:llama3.2:3b", "local": true } ] } -
Key points:
- Replace
"Your API Key Here"with the appropriate API keys for each model. - Local models (
"local": true) do not require API keys.
- Replace
Step 3: Configure Pricing (Optional)
-
Open the
pricing_config.jsonfile to update the cost for each model:{ "openai:gpt-4o": { "prompt_tokens": 2.50, "completion_tokens": 10.00 } } -
Notes:
- Pricing is given in USD per 1,000 tokens.
- Local models (
local: true) do not have pricing, as they operate on your hardware without additional costs.
Step 4: Setup for Local Models
-
Download and install Ollama from their official website.
-
After installation, use the following command to download the required local models:
ollama pull <model_id>- Replace
<model_id>with the specific ID of the model you want to use (e.g.,llama3.2:3b).
- Replace
-
Once the model is installed, update the
model_config.jsonwith:- Provider: Use
ollamaas the provider. - Model ID: The ID of the downloaded model.
- Provider: Use
Step 5: Run the Application
-
Start the chatbot UI by running the following command:
python app.py -
Open your browser and go to the URL displayed in the terminal (default:
http://127.0.0.1:5000/) to start using the chatbot.
Step 6: Additional Feature - Uploading PDFs
-
To use the PDF upload feature, ensure the files are:
- Text-based PDFs (scanned or image-based PDFs are not supported).
-
Upload the PDF file through the chatbot UI by clicking the Upload button. Once uploaded, the file's text content will be available for interaction.
Features to Be Added Later
-
Retrieval-Augmented Generation (RAG):
- Integrate retrieval-based techniques to enhance chatbot responses by incorporating relevant data from external sources or uploaded documents.
-
Image Support:
- Enable the chatbot to handle image inputs, such as analyzing, describing, or extracting data from images.
-
Adding Models via Interface:
- Provide an intuitive interface for adding new models directly to the system without needing to modify the configuration file manually.
-
Setting API Prices via Web Scraping:
- Automate the updating of API pricing configurations by scraping pricing information from official provider websites.
-
Setting Conversation Max Token Size via Interface:
- Allow users to configure the maximum token size for conversations directly through the interface, providing better control over context length and performance.