A lightweight conversational agent powered by LangChain, Ollama, and FastAPI. This project provides an interactive chat API using Llama3 as the language model.
- 🔥 Conversational AI: Uses
Llama3for text-based interactions. - 🛠 LangChain Agent: Implements a LangChain-powered conversational agent.
- ⚡ FastAPI Backend: Provides an efficient REST API for chat queries.
- 🛠 Extensible Tooling: Includes an example
echo_toolthat can be expanded. - 🖥 Docker-Ready: Easily containerized for deployment.
git clone https://github.com/TamerOnLine/tameronline-ollamachatagent.git
cd tameronline-ollamachatagentEnsure you have Python 3.9+ installed, then run:
pip install -r requirements.txtuvicorn main:app --host 0.0.0.0 --port 8000 --reloadUse cURL or Postman to send a chat request:
curl -X POST "http://127.0.0.1:8000/chat/" -H "Content-Type: application/json" -d '{"query": "Hello, how are you?"}'Expected JSON response:
{
"response": "Hello! How can I assist you today?"
}tameronline-ollamachatagent/
│── agent.py # Defines the LangChain Agent with Llama3
│── main.py # FastAPI server handling chat requests
│── requirements.txt # Dependencies list
│── LICENSE # MIT License
│── README.md # Project Documentation
└── img/ # Images or assets (if any)
By default, the model used is Llama3. If you want to switch to another Ollama model (e.g., mistral), modify agent.py:
llm = ChatOllama(model="mistral", temperature=0)You can extend the agent by defining new tools. Example:
def reverse_tool(text: str):
return text[::-1] # Reverses the input text
tools.append(Tool(name="reverse_tool", func=reverse_tool, description="Reverses the input text."))To run this project in a container:
docker build -t ollama-chat-agent .
docker run -p 8000:8000 ollama-chat-agentThis project is licensed under the MIT License. See LICENSE for details.
- Author: Tamer Hamad Faour
- GitHub: TamerOnLine
- Website: mystrotamer.com
🌟 Enjoy building with Ollama & LangChain! 🚀
