A hands-on repository documenting my journey learning LangChain — from basic LLM integrations to building a functional terminal chatbot.
Langchain/
├── Google-GenAI/ # LangChain with Google Gemini
├── Mistral-AI/ # LangChain with Mistral AI
└── lc-chatbot/ # Terminal chatbot project
Exploring LangChain with Google's Gemini model.
Model used: gemini-2.5-flash
from langchain_google_genai import ChatGoogleGenerativeAI
model = ChatGoogleGenerativeAI(model="gemini-2.5-flash")
response = model.invoke("Hello gemini")
print(response.text)Setup:
pip install langchain-google-genai python-dotenvAdd your API key to .env:
GOOGLE_API_KEY=your_key_here
Exploring LangChain with Mistral AI's chat model.
Model used: mistral-small-latest
from langchain_mistralai.chat_models import ChatMistralAI
model = ChatMistralAI(model="mistral-small-latest")
response = model.invoke("Hello Mistral")
print(response.text)Setup:
pip install langchain-mistralai python-dotenvAdd your API key to .env:
MISTRAL_API_KEY=your_key_here
A terminal-based conversational chatbot built with LangChain and Google Gemini. Maintains full chat history across the session so the model remembers previous messages.
Model used: gemini-2.5-flash
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.messages import HumanMessage, AIMessage
model = ChatGoogleGenerativeAI(model="gemini-2.5-flash")
messages = []
while True:
userInput = input("Enter Prompt ......")
messages.append(HumanMessage(userInput))
response = model.invoke(messages)
messages.append(AIMessage(response.content))
print(response.text)Run it:
cd lc-chatbot
pip install -r requirements.txt
python main.pyExploring LangChain Tools, LLM hallucinations, and tool calling workflows using Mistral.
This module demonstrates how to overcome one of the biggest limitations of LLMs — lack of real-time awareness — by integrating external tools.
LLMs like Mistral:
- Do not know real-time data
- Can generate incorrect or guessed answers
Example:
model.invoke("What is today's date?")➡️ May return a wrong date
We define a tool to fetch real-time data:
from langchain.tools import tool
from datetime import date
@tool
def getCurrentDate():
"""Returns current date"""
return str(date.today())Bind tool to model:
model = ChatMistralAI(model="mistral-small").bind_tools([getCurrentDate])response = model.invoke("today's date ?")
tool_result = getCurrentDate.invoke(response.tool_calls[0]["args"])
final_response = model.invoke(
["Human:- Today's Date", "Tool result := " + tool_result]
)
print(final_response.text)- User asks a question
- LLM decides to call a tool
- Tool executes (
getCurrentDate) - Result is passed back to LLM
- LLM generates accurate final answer
- Tools solve hallucination for dynamic data
- LLM + Tools = more reliable systems
- This is the foundation of AI agents
- Automate tool execution loop
- Add multiple tools
- Build full agent using
AgentExecutor
- Clone the repo:
git clone https://github.com/amitava-code/Langchain.git
cd Langchain- Create and activate a virtual environment:
python -m venv venv
source venv/Scripts/activate # Git Bash on Windows- Install dependencies and add your API keys to a
.envfile in the relevant folder.
- LangChain
- Google Gemini
- Mistral AI
- Python 3.11+