Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Agent-Chat-Bot (LangChain + Google Gemini Chatbot)

This project demonstrates how to build a simple chatbot using LangChain with Google Gemini models.
It takes user input from the terminal, sends it to the Gemini API, and prints the AI’s response.


📦 Requirements


⚙️ Installation

Clone the repository and install dependencies:

git clone https://github.com/your-username/your-repo.git
cd your-repo
pip install -r requirements.txt

Add the following to your requirements.txt:

langchain
python-dotenv

🔑 Setup Environment Variables

Create a .env file in the project root and add your Gemini API key:

GEMINI_API_KEY=your_api_key_here

📝 Code Example

from langchain.chat_models import init_chat_model
from dotenv import load_dotenv
import os

# Load environment variables
load_dotenv()
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")

# Initialize Gemini model
module = init_chat_model(
    model="gemini-3-flash-preview",
    model_provider="google-genai",
    api_key=GEMINI_API_KEY
)

# Chat loop
userinput = input("User: ")
response = module.invoke(userinput)
print(f"Agent: {response.content[0]['text']}")

▶️ Usage

Run the script:

python main.py

Example interaction:

User: Hello, how are you?
Agent: I'm doing great! How can I help you today?

🔄 Flowchart

flowchart TD
    A[👤 User Input] --> B[LangChain init_chat_model]
    B --> C[Google Gemini API]
    C --> D[AI Response]
    D --> E[💻 Printed to Console]
Loading

⏱️ Sequence Diagram

sequenceDiagram
    participant U as 👤 User
    participant L as LangChain (init_chat_model)
    participant G as Google Gemini API
    participant C as 💻 Console

    U->>L: Enter message (input)
    L->>G: Send request with API key
    G-->>L: Return AI response
    L->>C: Print response
    C-->>U: Display "Agent: ..."
Loading

📚 Notes

  • Make sure your API key is valid and has access to Gemini models.
  • You can extend this script into a full chatbot with conversation history, streaming responses, or integration into web/mobile apps.

🤝 Contributing

Feel free to fork this repo, open issues, or submit pull requests to improve the project.


About

A lightweight Python chatbot powered by **LangChain** and **Google Gemini**. It reads user input from the console, sends it to the Gemini API, and prints the AI’s response back in real time. Simple setup with `.env` for API key management, making it easy to extend into larger applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages