E-Commerce Whatsapp Bot
One popular use case for LLMs and RAG in B2B is a retrieval-based chatbot for e-commerce that helps customers find related products in a shop and answer their questions about the products.
HyperChat™ can ingest structured databases that define such shop catalogs, run retrieval based on customer queries, and respond with the database element representing that product (e.g, JSON) to enable integrations with platforms like Whatsapp and Slack.
An example collection is provided here so that you can experience chatting with the bot to search the catalog get information about the products.
Example
Consider the following 5 JSON files that describe products in the catalog of a hypothetical shop that sells skincare products:
- RadianceBoost Skin Serum 30 mL.json (opens in a new tab)
- PureBalance Hydrating Gel 50 mL.json (opens in a new tab)
- GlowMax Moisturizing Cream 50 mL.json (opens in a new tab)
- DermaCare Soothing Cream 30 mL.json (opens in a new tab)
- BalanceHydra Moisture Cream 50 mL.json (opens in a new tab)
The following is an example script for chatting with this Collection using our REST APIs over Python. The script appends the referred retrieved products to the message as "Sources" and writes the JSON files for the products to local files, simulating a scenario in which a platform integration might take place (i.e., the platform integration component can read the JSON and transform it for the platform as needed to display the data).
import time, os, requests, json
namespace_id = "81870dba-88c8-4d6f-95ad-3001a53d6211"
questions = [
"I have very dry skin, especially in the winter. Can you recommend a moisturizer that will give me long-lasting hydration?",
"I struggle with oily skin and frequent breakouts. Do you have a product that can help control oil without clogging my pores?",
"I have combination skin, and I need a face cream that won't be too heavy but still provides enough hydration. What do you recommend?"
]
for q in questions:
print("="*20)
print("Question: ", q, "\n")
headers = {"Content-Type": "application/json",
"Authorization": "Bearer "+os.environ["HYPERBEE_API_KEY"]}
json_data = {"namespace": namespace_id,
"model": "hyperchat",
"optimization": "premium",
"thread_message": q,
"stream": False,
"max_num_results": 2 # arbitrary choice
}
response = requests.post("https://api-rag.hyperbee.ai/v1/chat/completions", headers=headers, json=json_data)
response_json = response.json()
thread_id = response_json.get("thread_id", None)
answer = response_json["choices"][0]["message"]["content"]
print("Thread ID:", thread_id,"\n")
print("Answer: ", answer,"\n")
files = response_json.get("files", [])
refstr = ""
if len(files) > 0:
refstr += "Sources:\n"
for i, file in enumerate(files):
refstr += f"{i + 1}) {file.split(', url:')[0]}\n"
print(refstr)
if "additional_outputs" in response_json and response_json["additional_outputs"]:
additional_output = response_json["additional_outputs"].get("contents", "No additional outputs")
matched_products = []
for f in files:
for ao in additional_output:
if(f.split(', url:')[0] == json.loads(ao)["item_link"]):
json_filename = json.loads(ao)["details"]["product_name"]
with open(json_filename + ".json", "w") as ff:
print(ao, file=ff)
Hint: the namespace used in this example is public, you can use the Collection ID as is in your examples
The output is given in the following, where the script also saves the database JSON files of the referenced products from the catalog to local files for the answer of each question:
====================
Question: I have very dry skin, especially in the winter. Can you recommend a moisturizer that will give me long-lasting hydration?
Thread ID: 6716143b982213326e5ca3a9
Answer: For very dry skin, especially in the winter, I recommend the **GlowMax Moisturizing Cream 50 mL**. This rich moisturizer is designed specifically for dry skin and deeply hydrates while restoring the skin’s barrier with shea butter and hyaluronic acid. It provides long-lasting hydration and leaves the skin feeling soft and smooth.
You can find more details and purchase it here.
Sources:
1) https://example.com/product-hydration-cream
====================
Question: I struggle with oily skin and frequent breakouts. Do you have a product that can help control oil without clogging my pores?
Thread ID: 67161460f5acc90d1dd710b3
Answer: For controlling oil and preventing breakouts without clogging your pores, I recommend the "PureBalance Hydrating Gel 50 mL." This lightweight gel helps control shine and reduce sebum levels with ingredients like tea tree oil and salicylic acid, which are known for their effectiveness in preventing breakouts and keeping the skin clear. You can find more details here.
Sources:
1) https://example.com/product-skin-balancing-gel
====================
Question: I have combination skin, and I need a face cream that won't be too heavy but still provides enough hydration. What do you recommend?
Thread ID: 67161464982213326e5ca3ac
Answer: I recommend the **BalanceHydra Moisture Cream 50 mL**. This moisturizing cream is ideal for normal to combination skin, balancing hydration levels with aloe vera and jojoba oil. It provides moisture to dry areas while keeping oily regions under control, leaving the skin fresh and non-greasy.
You can find more details here.
Sources:
1) https://example.com/product-skin-hydration-cream