Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Chat Bot

Demo Links

1). AI Chat Bot

Table of contents

Project Overview

A Gradio chat application that plays the role of an Amazon customer assistant. It wraps a LangChain tool-calling agent, backed by an LLM served through OpenRouter, that answers questions about product price, specs, rating, and stock status, and recommends products from a small built-in catalog.

Goal

  • Primary Objective: given a natural-language question about a product, return an accurate answer grounded in the catalog (via tool calls), not a hallucinated one.
  • Secondary Objective: demonstrate a LangChain create_tool_calling_agent + AgentExecutor wired to a Gradio Blocks chat UI, with two custom tools over a mocked dataset.

Data Structure

DEFAULT_AMAZON_CATALOG — a hardcoded list of 10 product dicts, each with:

  • asin, title, category, price, rating, in_stock, description

If a file named amazon_products.json exists in the working directory (same shape as the list above), load_amazon_data() loads that instead of the default catalog.

Tools

  • Python — application logic
  • Gradio (gr.Blocks, gr.Chatbot) — chat UI
  • LangChain (langchain-openai, langchain-core, langchain-classic) — create_tool_calling_agent + AgentExecutor
  • OpenRouter API — LLM backend (ChatOpenAI pointed at https://openrouter.ai/api/v1), model anthropic/claude-3-haiku
  • python-dotenv — environment variable loading

Two LangChain tools exposed to the agent:

  • search_amazon_product(query) — matches by title, ASIN, category, or description
  • get_recommendations_by_criteria(category, max_price) — filters and sorts by stock + rating

How It Works

agent_with_memory.py → loads catalog, defines the two tools, builds the system prompt and
                        prompt template, exposes AmazonChatSession.chat(user_message)
app.py                → Gradio Blocks UI: textbox + Chatbot + Clear button, calls
                        agent.chat() on submit and appends the exchange to chat_history

Request flow: user types a message → app.py respond()AmazonChatSession.chat()AgentExecutor.invoke() (LLM decides whether to call a tool) → tool result (if any) fed back to the LLM → final answer returned → rendered in the Gradio chat window.

Setup & Usage

There's no requirements.txt in the repo, so install directly from the imports:

pip install gradio python-dotenv langchain-openai langchain-core langchain-classic

Create a .env file with:

OPEN_API_KEY=your_openrouter_api_key

Then run:

python app.py

This launches a local Gradio server (default http://127.0.0.1:7860) and, because share=True is set, also prints a temporary public link.

Limitations

  • No requirements.txt or .env.example checked in — dependencies and the required env var have to be reverse-engineered from the source.
  • The env var is named OPEN_API_KEY, not the conventional OPENAI_API_KEY, and the key it expects is an OpenRouter key, not an OpenAI one — easy to misconfigure.
  • Despite the filename agent_with_memory.py and the class AmazonChatSession, there is no real conversation memory: chat() calls executor.invoke({"input": user_message}) fresh each turn with no prior turns passed in. The Gradio chat_history is display-only; the agent never sees it.
  • share=True is hardcoded, so every run of python app.py generates a public URL — convenient for a demo, not something to leave running.
  • No handling for a missing/invalid API key beyond letting the exception string surface as a chat message.
  • The catalog is a static mock (10 hardcoded products, or an optional local JSON file) — not connected to any real Amazon data or API.

Possible Extensions

  • Add a requirements.txt (or pyproject.toml) and a .env.example.
  • Wire actual conversation memory: pass prior turns into agent_scratchpad or attach a memory/history object so follow-up questions work.
  • Rename OPEN_API_KEY to something unambiguous, or add a comment noting it's an OpenRouter key.
  • Add tests for search_amazon_product and get_recommendations_by_criteria against the catalog.
  • Make share configurable via an env var instead of hardcoded True.

About

Gradio-based Amazon shopping assistant using anthropic/claude-3-haiku model function-calling to query a product catalog

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages