Skip to content

Commit

Permalink
product catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
chemik-bit committed Jul 8, 2024
1 parent 0d1eae0 commit e86ae86
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ venv/
ENV/
env.bak/
venv.bak/
website/docs/.env

# Spyder project settings
.spyderproject
Expand Down
20 changes: 20 additions & 0 deletions examples/sample_product_catalog_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Product 1: Himmel Soft Memory Foam Mattress
Dive into the luxury of the Himmel Soft Memory Foam Mattress, a masterpiece of comfort and design. This mattress features a temperature-sensitive memory foam that contours to your body, providing customized support and exceptional comfort. It is built on a durable high-density foam base that retains its shape and firmness over time. Enhanced with cooling gel particles, it helps maintain an optimal sleeping temperature all night. The soft, hypoallergenic cover, beautifully stitched with elegant patterns, not only decorates your space but also protects against allergens. Choose the Himmel Soft Memory Foam Mattress for a rejuvenating sleep experience.
Price: $950
Sizes available for this product: Twin, Queen, King

Product 2: Tradfri Pocket Spring Mattress
Experience the perfect combination of tradition and modernity with our Tradfri Pocket Spring Mattress. It boasts a sturdy pocket spring core surrounded by luxurious padding layers that provide a balanced support and plush comfort. The top layer is quilted and soft, enhancing the comfort with a touch of luxury. The reinforced edges offer increased durability and a uniform sleep surface. Its natural cotton cover efficiently absorbs moisture, ensuring a dry and pleasant sleep environment. The Tradfri Pocket Spring Mattress is ideal for those who value a harmonious blend of support and softness.
Price: $1,250
Sizes available for this product: Queen, King

Product 3: Grönblad Natural Latex Mattress
The Grönblad Natural Latex Mattress is our commitment to sustainable comfort. Crafted from 100% natural latex sourced from environmentally responsible plantations, this mattress delivers a dynamic, supportive sleep while offering excellent pressure relief. It features a base of individually encased coils that reduce motion transfer, making it ideal for couples. Covered in certified organic cotton, it provides a soft, breathable sleeping surface. With its natural antimicrobial and hypoallergenic qualities, the Grönblad is an excellent choice for those with allergies, combining eco-friendliness with luxurious comfort.
Price: $1,550
Sizes available for this product: Twin, Full

Product 4: Skogsliden Bamboo Mattress
Elevate your sleep with the Skogsliden Bamboo Mattress, where comfort meets sustainability. This mattress includes a layer of adaptive foam that conforms to your body, supported by a durable base foam that prevents sagging. The highlight is its bamboo-infused top layer, offering a soft, cool touch and excellent moisture management, thanks to bamboo's natural properties. The removable bamboo cover is silky and easy to care for, ensuring a clean and refreshing sleep environment. The Skogsliden Bamboo Mattress is a luxurious choice for those seeking eco-friendly sleep solutions.
Price: $2,500
Sizes available for this product: King
2 changes: 1 addition & 1 deletion salesgpt/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setup_knowledge_base(
with open(product_catalog, "r") as f:
product_catalog = f.read()

text_splitter = CharacterTextSplitter(chunk_size=10, chunk_overlap=0)
text_splitter = CharacterTextSplitter(chunk_size=5000, chunk_overlap=200)
texts = text_splitter.split_text(product_catalog)

llm = ChatOpenAI(model_name="gpt-4-0125-preview", temperature=0)
Expand Down
72 changes: 72 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import pytest
from unittest.mock import patch, MagicMock
from salesgpt.tools import generate_stripe_payment_link, send_email_tool, generate_calendly_invitation_link
import os
import json

@pytest.fixture
def mock_requests_post():
with patch("salesgpt.tools.requests.request") as mock_post:
yield mock_post

@pytest.fixture
def mock_smtplib():
with patch("salesgpt.tools.smtplib.SMTP_SSL") as mock_smtp:
yield mock_smtp

@pytest.fixture
def mock_requests():
with patch("salesgpt.tools.requests.post") as mock_post:
yield mock_post

def test_generate_stripe_payment_link(mock_requests_post):
# Mock the response of the requests.post call within your tool function
mock_response = MagicMock()
mock_response.text = "https://mocked_payment_link.com"
mock_response.status_code = 200
mock_requests_post.return_value = mock_response

# Mock the get_product_id_from_query function to return a valid JSON string
with patch("salesgpt.tools.get_product_id_from_query", return_value=json.dumps({"price_id": "price_123"})):
# Call the function you're testing
result = generate_stripe_payment_link("query about a product")

# Assert that the result is as expected
assert result == "https://mocked_payment_link.com", "The function should return the URL from the mocked response."

# Additionally, you can assert that the requests.post was called with the correct arguments
mock_requests_post.assert_called_once()

def test_send_email_tool(mock_smtplib):
# Mock the SMTP server object and its methods
mock_server = MagicMock()
mock_smtplib.return_value = mock_server

# Mock the email details extraction
email_details = {
"recipient": "[email protected]",
"subject": "Test Subject",
"body": "Test Body"
}
with patch("salesgpt.tools.get_mail_body_subject_from_query", return_value=json.dumps(email_details)):
result = send_email_tool("query about sending an email")
assert result == "Email sent successfully.", "The function should return a success message."

mock_smtplib.assert_called_once_with('smtp.gmail.com', 465)
mock_server.login.assert_called_once_with(os.getenv("GMAIL_MAIL"), os.getenv("GMAIL_APP_PASSWORD"))
mock_server.sendmail.assert_called_once()
mock_server.quit.assert_called_once()

def test_generate_calendly_invitation_link(mock_requests):
mock_response = MagicMock()
mock_response.status_code = 201
mock_response.json.return_value = {
"resource": {
"booking_url": "https://mocked_calendly_link.com"
}
}
mock_requests.return_value = mock_response
result = generate_calendly_invitation_link("query about a meeting")

assert result == "url: https://mocked_calendly_link.com", "The function should return the URL from the mocked response."
mock_requests.assert_called_once()
21 changes: 20 additions & 1 deletion website/docs/Tools/Product_catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@ sidebar_position: 2

---

# Product search catalog
# Product catalog
To ensure that SalesGPT can effectively understand and utilize your product catalog, it is important to set up the correct chunk size in the text splitter within the `tools.py` file. Proper chunking helps in maintaining the context and coherence of the product information.

Here are two examples of incorrect setups and one example of a correct setup:

### Incorrect Setup 1
![Incorrect Setup 1](/img/bad_1.png)

### Incorrect Setup 2
![Incorrect Setup 2](/img/bad_2.png)

### Correct Setup
![Correct Setup](/img/correct.png)

You can implement your product catalog into SalesGPT by loading it.
To add a different product catalog, such as the `sample_product_catalog_2.txt` file, follow these steps:

1. **Update the product catalog file**: Replace the existing product catalog file with your new product catalog file. For example, you can use the `sample_product_catalog_2.txt` file.

2. **Update the `run_api` file**: Make sure to update the `product_catalog` variable in the `run_api` file to point to the new product catalog file. Alternatively, if you have set up the `PRODUCT_CATALOG` environment variable, update it to the path of your new product catalog file.

Here is an example of how to update the `setup_knowledge_base` function (product catalog function) in the `tools.py` file:
![Correct Product Catalog](/img/new_products.png)
Loading

0 comments on commit e86ae86

Please sign in to comment.