Skip to content

This project is a terminal-based AI chatbot built with LangChain, LangGraph, and OpenAI. It uses the modern ReAct agent architecture and supports streaming responses directly to the terminal for a smooth and interactive experience.

Notifications You must be signed in to change notification settings

codebyimran-projects/ai-chatbot-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

AI Chatbot using LangChain, LangGraph, and OpenAI

This project is a terminal-based AI chatbot built with LangChain, LangGraph, and OpenAI. It uses the modern ReAct agent architecture and supports streaming responses directly to the terminal for a smooth and interactive experience.

Features

  • Uses LangGraph's latest create_react_agent
  • Supports real-time streaming responses
  • Simple and clean terminal interface
  • Easily expandable to include tools, memory, or additional models
  • Uses the latest OpenAI gpt-4o-mini model
  • Environment variables loaded using python-dotenv

Requirements

Install the required libraries:

pip install langchain langgraph langchain-openai python-dotenv

How to Use

  1. Create an .env file in the project directory.
  2. Add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
  1. Run the script:
python main.py
  1. Type messages in the terminal and the chatbot will respond.
  2. Type exit or quit to close the program.

Project Structure

/project-folder
    main.py
    README.md
    .env

Code Explanation

  • ChatOpenAI loads the OpenAI model for the chatbot.
  • create_react_agent creates a modern ReAct agent using LangGraph.
  • The agent streams output using agent.stream.
  • HumanMessage is used for sending user input to the model.

Example Prompt Flow

You: Hello
Bot: Hi, how can I assist you?

Future Improvements

  • Add memory support
  • Add custom tools (search, calculator, file operations)
  • Add voice input and text-to-speech output
  • Create a full GUI or web interface

About

This project is a terminal-based AI chatbot built with LangChain, LangGraph, and OpenAI. It uses the modern ReAct agent architecture and supports streaming responses directly to the terminal for a smooth and interactive experience.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages