A Streamlit UI for LLM chat applications with persistence and chat history
Project description
UI4AI
A simple, lightweight, and plug-and-play Streamlit-based UI for LLM chatbot applications.
🚀 Features
- Plug in your own
generate_responsefunction - Built-in sidebar history and session management
- Optional extras:
- Title generation
- Token counting
- Max history control
- Customizable and editable conversation history titles
- Persistent session state: continue your chat even after restarting the app
📦 Installation
pip install UI4AI
🧠 Basic Usage
from UI4AI import run_chat
import openai
openai.api_key = "<YOUR_API_KEY>"
def generate_response(messages) -> str:
try:
response = openai.ChatCompletion.create(
model="gpt-4",
messages=messages,
temperature=0.7
)
return response.choices[0].message.content
except Exception as e:
raise RuntimeError(f"Response generation failed: {str(e)}")
run_chat(
generate_response=generate_response,
title="My Chatbot",
sidebar=True,
session_state=True,
token_counting=True
)
▶️ Running the App
streamlit run app.py # Or replace with your own script name
🎨 Customization Options
You can customize the UI with these optional parameters:
run_chat(
generate_response: Callable[[List[Dict]], str],
page_title: str = "AI Chat",
title: str = "Conversational Bot",
layout: str = "wide",
new_conversation: str = "➕ New Chat",
chat_placeholder: str = "Ask me anything...",
sidebar_instructions: str = "Conversation History",
spinner_text: str = "Thinking...",
)
🔧 Additional Features
🧠 Title Generation
Automatically generates a conversation title.
🔢 Token Counting
Displays the total token count used in the conversation.
🕒 Customizable Max History
Control how many messages are remembered in the chat history.
For example, if you first ask “Who is Spider-Man?” When you later ask “Name all his movies?”, it assumes “his” means Spider-Man this is because of history.
📝 Customizable Conversation Titles
You can edit or customize the title of any conversation in the history sidebar for better organization.
💾 Persistent Sessions
Session state is stored automatically, so your chat history and context are preserved. You can continue your conversation even if you restart or refresh the app!
📚 Sidebar History
View and click through previous conversation threads in the sidebar.
💾 Persistent Sessions
Your chat history persists even after refreshing the page or even restarting app. You can return and continue where you left off!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ui4ai-0.1.2.tar.gz.
File metadata
- Download URL: ui4ai-0.1.2.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05a5ad97e1e3852aad3fb96a5bce2a3f526dd74f62c92822993a7f399862d842
|
|
| MD5 |
0e3d0b11c008dbd3ceb76e0fda021546
|
|
| BLAKE2b-256 |
b56c236a65d487e142c5c4183352ff2ad44d3a52bc7f9c5480810fca67928e36
|
File details
Details for the file UI4AI-0.1.2-py3-none-any.whl.
File metadata
- Download URL: UI4AI-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
101ec34fbfb911d5de61a94a3e91742e1e65c4ad7e643a4c0203e2b929bf0d17
|
|
| MD5 |
5adc7fbee925eb22d64489a0962f4c45
|
|
| BLAKE2b-256 |
9bd220c8e7e794255e983322d566342b4d25418f63fc5e69a7f401bf47aaa336
|