Skip to content

ShopAssist AI is an Agentic RAG chatbot designed to enhance the e-commerce shopping experience by offering personalized product recommendations and cart management.

Notifications You must be signed in to change notification settings

sree-teja/shopAssistAI

Repository files navigation

ShopAssist AI

ShopAssist AI is a Retrieval-Augmented Generation (RAG) chatbot designed to enhance the e-commerce shopping experience by offering personalized product recommendations and cart management. This chatbot acts as a virtual sales assistant, improving user engagement and streamlining retail interactions. While this implementation is configured for a fictional Foo convenience store, it is fully adaptable to other retail environments.

Project Structure

ShopAssist AI consists of four primary components, which can be run independently:

  • Chat Interface: A front-end demo built with Streamlit. This is an optional component, as the chatbot can also be used via the command line.
  • Rasa Chatbot: The core chatbot system, built using Rasa, responsible for processing conversations, identifying intents, and delegating queries to the RAG subsystem.
  • Rasa Actions Server: A custom action server that integrates external services, executes business logic, and powers the RAG-based recommendation system.
  • Redis Database: Used to store chat history and user cart data, ensuring continuity in conversations.

The RAG-based recommendation system is powered by OpenAI’s gpt-4o through the OpenAI API. Function calling is the primary integration method used for tool interactions, though alternative approaches like ReAct prompting could be explored.

Installation and Usage

Chat Interface

To install and launch the chatbot demo interface:

  1. Clone the repository.
  2. Navigate to the interface directory:
    cd chat_interface
  3. Install poetry for dependency management.
  4. Install dependencies:
    poetry install
  5. Move to the application folder:
    cd src
  6. Start the interface:
    streamlit run app.py

The chatbot will be accessible at http://localhost:8501.

Rasa Chatbot

To install and run the chatbot:

  1. Navigate to the chatbot directory:
    cd shopAssistAI/rasa_chatbot
  2. Install dependencies:
    poetry install
  3. Download the language model:
    python -m spacy download en_core_web_lg
  4. Train the chatbot model:
    rasa train
  5. Run the chatbot API:
    rasa run
    Alternatively, run it in terminal mode with:
    rasa shell --debug

Rasa Actions Server

To set up and run the custom actions server:

  1. Navigate to the actions server directory:
    cd shopAssistAI/actions_server
  2. Install dependencies:
    poetry install
  3. Set up your OpenAI API key as an environment variable:
    export OPENAI_API_KEY="your_api_key"
    For Azure-based OpenAI, additional variables are required:
    export AZURE_OPENAI_API_KEY="your_azure_api_key"
    export AZURE_RESOURCE="your_azure_resource"
    export AZURE_API_VERSION="your_api_version"
  4. Start the actions server:
    python -m rasa_sdk --actions actions

Redis Database

To run the Redis database:

  1. Ensure you have Docker installed.
  2. Start the database container:
    docker-compose up database

Redis will be accessible at port 6379.

Running with Docker

You can deploy all components via Docker using the provided docker-compose.yml file. However, certain endpoints must be updated for proper communication between containers:

  • chat_interface/src/chatbot.py: Change localhost to rasa for Rasa chatbot URLs and localhost to database for Redis.
  • shopAssistAI/rasa_chatbot/endpoints.yml: Update localhost to actions.
  • shopAssistAI/actions_server/src/LLMChatbot/services/chatbot.py: Change localhost to database.

Code Structure

Familiarizing yourself with the following key directories will help navigate the project efficiently:

  • chat_interface – Contains the front-end chat application.
  • shopAssistAI – The chatbot's core logic.
    • rasa_chatbot
      • endpoints.yml – Defines API endpoints for the chatbot.
      • domain.yml – Specifies chatbot intents, entities, and responses.
      • config.yml – Defines Rasa’s NLP pipeline.
      • data
        • nlu.yml – Training data for natural language understanding.
        • stories.yml – Chatbot conversation flows.
        • rules.yml – Predefined chatbot rules.
      • models – Trained models for intent recognition and slot extraction.
    • datasets – Sample e-commerce datasets for testing.
    • actions_server
      • src
        • LLMChatbot – RAG-based subsystem handling product recommendations.
          • chatbot.py – Main chatbot logic.
          • prompts.py – Prompt templates for OpenAI calls.
          • services
            • database.py – Database operations.
            • product_handler.py – Product search and recommendation logic.
            • memory_handler.py – User conversation history management.
            • cart_handler.py – Shopping cart operations.
            • llm_handler.py – LLM API interactions.
            • guardrails – Implements security measures and constraints.

About

ShopAssist AI is an Agentic RAG chatbot designed to enhance the e-commerce shopping experience by offering personalized product recommendations and cart management.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published