Skip to main content

Streamlit UI for LLM chat apps

Project description

A simple, lightweight, and plug-and-play Streamlit-based UI for LLM chatbot applications.


🚀 Features

  • Plug in your own generate_response function
  • Built-in sidebar history and session management
  • Optional extras:
    • Title generation
    • Token counting
    • Max history control

Chat Example


📦 Installation

  pip install UI4AI

🧠 Basic Usage

from UI4AI import run_chat
import openai

# Set your OpenAI API key
openai.api_key = "<YOUR_API_KEY>"

# Define how the chatbot generates responses
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)}")

# Launch the chat app
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.
Title Generation

🔢 Token Counting

Displays the total token count used in the conversation.
Token Counting

🕒 Customizable Max History

Control how many messages are remembered in the chat history.
Max 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.

📚 Sidebar History

View and click through previous conversation threads in the sidebar.
Session History

💾 Persistent Sessions

Your chat history persists even after refreshing the page. You can return and continue where you left off!
Session Persistence

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ui4ai-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

UI4AI-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file ui4ai-0.1.1.tar.gz.

File metadata

  • Download URL: ui4ai-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ui4ai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b3c11ed0c2d93ee5d51461c7c7020be85d0869126ee8b54b36ac9a00a97bfdff
MD5 d1829533ac1a2c157b1e7cc462d19e65
BLAKE2b-256 f7f44c2c9a33754544f21b7264b43d6ee0ef52091f874425b7737736edba2017

See more details on using hashes here.

File details

Details for the file UI4AI-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: UI4AI-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for UI4AI-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8452529da84d92a9cd3821aa4df095cf855a327ba05933e1a7317010836b2cdc
MD5 11bbb3333ea5cc947f50899b895d3e5e
BLAKE2b-256 aef67e9d9dac255bed0c898d64750ee2e8ccd48829e8220cd4bdf82b31337d3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page