This project is an AI assistant built using Chainlit and the OpenAI Agent SDK, powered by Google Gemini models. It supports real-time streaming responses (just like ChatGPT) and remembers previous messages(history/memory) to keep the conversation flowing naturally. You can use it to build your own smart and responsive chatbot.
Before running this project, ensure you have the following tools, libraries, and API keys properly configured:
Tool / Library | Description |
---|---|
🐍 Python 3.9+ | Required for running the application and libraries |
🧬 Chainlit | Framework for building conversational UIs with LLMs |
🧠 OpenAI Agent SDK | Enables agent orchestration and streaming capabilities |
🌐 Git | Version control for cloning and managing the project repository |
🔑 Google Gemini API | Get API Key for Gemini models |
🔑 OpenAI API Key | Get API Key for streaming |
📦 dotenv | For managing environment variables securely |
🧪 VS Code | Recommended code editor for development |
- 🔄 Real-time Token Streaming: Experience the fluidity of ChatGPT-like responses.
- 🧠 Persistent Memory: Maintain context across your conversations, ensuring your AI assistant remembers previous interactions.
- 🔗 Chainlit Integration: Leverage Chainlit's ease of use for rapid UI development and deployment.
- 🤖 Gemini Power: Utilize the cutting-edge capabilities of the
gemini-2.0-flash
model. - 🧰 OpenAI Agent SDK Integration: Benefit from the robust features and flexibility of the OpenAI Agent SDK.
- 🔐 Secure API Key Management: Safely manage your API keys using a
.env
file. - 🚀 Developer-Friendly Codebase: A modular and well-structured Python codebase, making it easy to extend and customize.
-
Clone the Repository:
git clone https://github.com/waheed444/chainlit-memory-stream-agent.git cd chainlit-memory-stream-agent
-
Create and Activate a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install openai-agents chainlit
# for UV User's
uv add openai-agents chainlit
- Configure API keys: Create a
.env
file in the root directory and add your API keys:
-
📌 Make sure to store your API keys securely in a
.env
file in the root directory:
GEMINI_API_KEY = paste_your_gemini_api_key_here
# OR
OPENAI_API_KEY = paste_your_openai_api_key_here
-
Run the App:
chainlit run agent.py
(Note: You need to have
chainlit
installed. Install it viapip install chainlit
if not already present.)
Start the Chat UI: Once Chainlit is running, open the local URL provided in your terminal and start chatting with your AI assistant.
Ask questions like:
Who was the founder of Pakistan?
Summarize the history of Python in 3 lines.
What’s the latest in AI this year?
Enjoy token-by-token responses with context-aware answers based on your memory/previous messages.
💡 You can customize the agent's behavior, memory strategy, or switch between Gemini and OpenAI models by modifying the app.py
and stream.py
files.
We welcome contributions to improve this project! Please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Make your changes and ensure they adhere to the project's coding style and best practices.
- Commit your changes:
git commit -m "Add feature"
- Push to the branch:
git push origin feature-name
- Submit a pull request with a clear description of your changes and their benefits. If you find any issues or want to improve this project, feel free to open a GitHub issue or submit a pull request.
This repo is only for learning and exploring new things, feel free to fork it, explore, or give suggestions!
Star ⭐ the repo if it helps you!
This project is licensed under the MIT License - see the LICENSE file for details.