Character AI — a thoughtfully built LLM-powered conversational application for intelligent, context-aware dialogue.
Topics: character-modeling · conversational-ai · deep-learning · generative-ai · interactive-fiction · large-language-models · llm · nlp · persona-based-chatbot · role-playing-dialogue
Character AI is an LLM-powered application that provides a clean, functional interface for interacting with frontier language models. It goes beyond a simple prompt-response wrapper: it maintains conversation memory, supports configurable system prompts for persona and task specialisation, and provides streaming output for a responsive chat experience.
The application supports multiple LLM backends — OpenAI GPT-4o, Google Gemini, Anthropic Claude, and locally-running Ollama models — configurable via environment variables without code changes. This makes it a flexible foundation for a wide range of conversational AI use cases: customer support bots, coding assistants, educational tutors, and domain-specific advisors.
The conversation history is managed with configurable memory: either a simple sliding window buffer (last N messages) or a vector-store-backed semantic memory that retrieves relevant earlier context based on the current query. Both modes are implemented and selectable via the sidebar.
Building a production-ready LLM chat application requires more than an API call. Memory, streaming, error handling, rate limit management, and a clean UI each add meaningful complexity. This project implements all of these correctly so that it can serve as a solid, reusable foundation for any conversational AI product built on top of it.
User message → Streamlit chat UI
│
Memory retrieval (buffer or vector)
│
LLM API call (streamed)
│
Response rendering + history update
Conversation history maintained across turns — either as a sliding window buffer or semantic vector retrieval for long-context conversations.
LLM responses are streamed character by character to the UI, providing low-latency perceived response time.
Sidebar text area for runtime system prompt editing — change the AI's persona, task focus, or response format without restarting the app.
Switch between OpenAI, Gemini, Claude, and Ollama backends via environment variable or sidebar selector.
Download full conversation history as Markdown or JSON.
Real-time per-message and session-total token counters in the sidebar.
Graceful handling of API rate limits, timeouts, and model errors with automatic retry and user notification.
Create, name, switch between, and delete conversation sessions without page reload.
| Library / Tool | Role | Why This Choice |
|---|---|---|
| Streamlit | Chat UI | st.chat_message, st.chat_input, sidebar |
| OpenAI SDK | Primary LLM backend | GPT-4o function calling and streaming |
| google-generativeai | Gemini backend | Gemini Pro/Flash streaming API |
| python-dotenv | Config | Environment variable management |
| FAISS (optional) | Vector memory | Semantic conversation history retrieval |
| LangChain (optional) | Memory abstraction | ConversationBufferMemory wrappers |
Key packages detected in this repo:
streamlit·google-generativeai
- Python 3.9+ (or Node.js 18+ for TypeScript/JS projects)
pipornpmpackage manager- Relevant API keys (see Configuration section)
git clone https://github.com/Devanik21/Character-AI.git
cd Character-AI
python -m venv venv && source venv/bin/activate
pip install streamlit openai google-generativeai python-dotenv
echo 'OPENAI_API_KEY=sk-...' > .env
streamlit run app.pystreamlit run app.py
# Use Gemini backend
BACKEND=gemini streamlit run app.py
# Use local Ollama
BACKEND=ollama MODEL=llama3 streamlit run app.py| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY |
(required for OpenAI) |
OpenAI API key |
GOOGLE_API_KEY |
(required for Gemini) |
Google API key |
BACKEND |
openai |
LLM backend: openai, gemini, ollama |
MEMORY_WINDOW |
10 |
Number of messages in sliding window memory |
Copy
.env.exampleto.envand populate all required values before running.
Character-AI/
├── README.md
├── requirements.txt
├── app.py
└── ...
- RAG mode: chat over uploaded documents with citation
- Voice I/O with Whisper and TTS
- Multi-agent mode with specialist sub-agents
- Docker deployment with Traefik reverse proxy
- Persistent storage with SQLite conversation database
Contributions, issues, and feature requests are welcome. Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'feat: add your feature') - Push to your branch (
git push origin feature/your-feature) - Open a Pull Request
Please follow conventional commit messages and ensure any new code is documented.
API keys for the configured LLM backend are required. Streaming availability depends on the model and backend. Ollama must be running locally for the Ollama backend to work.
Devanik Debnath
B.Tech, Electronics & Communication Engineering
National Institute of Technology Agartala
This project is open source and available under the MIT License.
Crafted with curiosity, precision, and a belief that good software is worth building well.