Skip to content

Group-16-COSC-310/grocery-chat-bot

Repository files navigation

grocery-chat-bot

An assistant chatbot for a grocery store that helps answer customer queries.

The chatbot will greet the user, then answer their question about store/product information or other, more complex concerns.

The chatbot will do so by doing a basic check of the user input, and redirecting the query to the appropriate mini-bot, where a more in-depth response will be handled. If the bot cannot decipher the user's message, they will be provided with the store's email, phone number, and hours to talk to a real employee.

Table of contents

Setup

The Google cloud key needs to be obtained by contacting [email protected] to run the full bot.

Windows (PowerShell)

Creating virtual environment and install dependencies to run the bot:

python3 -m venv venv
venv\Scripts\activate
pip install -r requirements.txt

Setting up the environment variables for the bot (Google cloud key) in PowerShell:

$env:GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

Setting up the environment variables for the bot (Google cloud key) in cmd:

set GOOGLE_APPLICATION_CREDENTIALS=KEY_PATH

Unix (Bash)

Creating virtual environment and install dependencies to run the bot:

./install.sh

Setting up the environment variables for the bot (Google cloud key).

export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

Run

python3 main.py

Main Bot

The main bot will handle all inputs and ouputs from the user.

See in-depth documentation here.

Product & Store Mini-bots

This mini-bot will handle any question related to product price, stock, nutrition, and store information. The bot first determines what topic is of interest (product or store information) and breaks the user's message down into keywords. The bot then compares these words and checks them in order to create the most appropriate response, and returns the response to the main bot.

See in-depth documentation here.

Tests

We are using pytest for all of our tests. Our test cases can be found in the test folder.

Test all cases:

python -m pytest

Test selected cases:

  • database
  • store_info
  • prod_info
  • intent_detection
python -m pytest -v -m <selected case>

API

You can call the API from any other Python script to check store's information or products information. This does not require the bot to be running or a diagflow key.

Make sure to import the API correctly, as the API is not imported by default, and is dependent on your project's file hierarchy.

Store Info API

From this bot you can query the store's information.

Example import for product info bot:

from app.products.store_info import StoreInfoHandler

handle(string) -> string

StoreHandler = StoreInfoHandler()
message = "Where is the store?"
output = StoreHandler.handle(message)
# returns string: "It is 123 Main St"

parse(string) -> object

StoreHandler = StoreInfoHandler()
message = "Where is the store?"
print(StoreHandler.parse(message))
# returns object: {'request': 'address'}

Product Info API

From this bot you can query the store's products information.

Example import for product info bot:

from app.products.product_info import ProductInfoHandler

handle(string) -> string

StoreHandler = ProductInfoHandler()
message = "How much does a banana cost?"
output = StoreHandler.handle(message)
# returns string: "Bananas cost $0.67 per kg."

parse(string) -> object

StoreHandler = ProductInfoHandler()
message = "How much does a banana cost?"
output = StoreHandler.parse(message)
# returns object: {'request': 'price', 'id': '4011'}

Database API

The database API also allows queries straight from the database.

Example import for database:

from app.database import Database

Database lifecycle:

db = Database.instance()
db.connect()
db.init_database()
# queries or methods
db.close()

get_product("id", str) -> List

output = db.get_product("id", "4011")
# returns list: [OrderedDict([('id', '4011'), ('name', 'banana'), ('names', 'bananas'), ('price', 0.67), ('price_scale', 'per kg'), ('in_stock', True), ('calories', 89), ('protein', '1.1 g'), ('carbs', '22.8 g'), ('sugar', '12.2 g'), ('fat', '0.3 g')])]

New Features

Nutrition Sub-Topic

With nutrition sub-topic, the bot will also provide nutrition information for the product, which will help user decide whether to buy the product or not.

nutrition-snippet

5 Reasonable responses outside of the topic

With 5 reasonable responses outside of the topic, the bot will provide a more fluent response to the user. This will prompt the user to rephrase their question if the bot does not understand the question. The bot also provides responses for refunds or exchanges for the product, which allows for more smooth and realistic conversation.

response-snippet

Spelling Mistakes

With spelling mistakes handled by Google's Diagflow API, the bot will provide a more accurate response to the user.

correcttion-snippet

Synonym Recognition

With synonym recognition handled by Google's Diagflow API, the bot will provide a more accurate response to the user.

correcttion-snippet

Named Entity Recognition

With Named Entity Recognition handled by Google's Diagflow API, the bot will provide a more accurate response to the user.

correcttion-snippet

Sentiment Analysis

With Sentiment Analysis handled by Google's Diagflow API, the bot will provide a more accurate response to the user.

correcttion-snippet

About

An assistant chatbot that answers customer queries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published