Shopping groceries
This tutorial explains how to implement the grocery shopping routine, which adds a given set of products to the cart in the online grocery store.
Algorithm
- For each product from the list:
- Open the page with a search for it in the online grocery store
- Extract the list of the matched products from this page
- Choose a suitable product from the list of found products
- Add this product to the cart
Let’s split the routine into three tasks, the first one contains a list of products that should be added to carts, the second one describes how to find a product and add it to cart, and the third one explains how to extract a products list from the given tab in a structured format.
To make it even more fun, let’s interact with the Polish store https://zakupy.auchan.pl (but the true reason, of course, is that the author of this guide lives in Poland and uses this store to shop for groceries).
In our tests, OpenAI coped with the task pretty well, but sometimes it added something unexpected to the cart, like dried plums instead of normal plums.
Shopping list
Save the following prompt as task “Auchan: Shop”:
You are the assistant who helps me to shop for groceries in the Polish onlinestore "Auchan". Use the tool "add_auchan_product_to_cart" to add the productsfrom the list below to the cart.
# General guidelines
- The product name is given in the format "English name / Polish name", with the optional guidelines at the next line.- Use only the Polish version of the product's name as an argument for the tool.- Use the product name as a search query exactly as specified after the slash, do not modify it.- Use the optional guidelines that can be specified after the name of each product.- Make sure to add all products to the cart from the list below.- Do not retry adding a product to the cart on error.- If error happens stop immediately- After adding all products to cart, create a report that contains all processed products grouped by category as provided below.- Each entry should include: the name of the product from the list below, the name of the product added to the cart, the price for this item (not for kg!), the weight or another measurement unit, and the link to the search results- Each report entry format: "Product: [product](link), price, weight" (e.g., "[Ogórek](http://zakupy.auchan.pl/somelink), 2,99 zł, 500g")- Example of the report entry format: "Milk: (Mleko UHT 3.8% Łaciate 1 l)[http://zakupy.auchan.pl/somelink], 5,28 zł, 1l- If an error happen adding this product to cart, include the entry as: "Product: Error", e.g.: "Milk: Tool call error `Milk wasn't found`"- Include the error text from tool call to report- Include the products that were not added to the cart for any reason to the end of the report.
# Products
## Vegetables
- Tomatoes / Pomidor- Cucumbers / Ogurek - Prefer Ogórek krótki Pewni Dobrego- Red Peppers / Papryka czerwona- Yellow Peppers / Papryka zółta- Potatoes / Ziemniaki - Prefer: Ziemniaki kulinarne Warzywa Auchan 2 kg- Dill / Koperek - Prefer fresh ("świeży") that often referred as "bunch" ("pęczek") - Avoid dried ("suszony")
## Fruits
- Bananas / Banany- Apples / Jabłki- Pears / Gruszki- Watermelon / Karpuz
[... add your products here ...]Because your order will probably be different each time, let the query be modified before executing by checking the checkbox “Edit before call” in “Options” tab. This will give you a chance to adjust the product list according to the products in stock before ordering everything.
Adding a product to the cart
Create the task with:
- Main
- Name: “Auchan: Add product to cart”
- Options Tool name: add_auchan_product_to_cart
- Arguments
- Query as shown below
- Allowed tools:
get_auchan_products
- Parameters
- product (description: “The name of the product that should be added to cart”)
- guidelines (description: “The guidelines that should be followed to add the product to cart”)
The task prompt is:
You are the assistant that helps me to buy groceries in the polish onlinestore "zakupy.auchan.pl".
# Goal
Follow the steps below to add the product to cart according to providedguidelines.
Product: $harmony.args.product
Guidelines:
$harmony.args.guidelines- Prefer products with the lowest price per kg.- Prefer weighed products ("na wage").- Prefer products from the brand "Auchan".- Add only a single product for each search.- Don't add processed food (dried, canned, juiced and so on) unless the product name or guidelines specifies that the processed product is needed
# Step 1: Open the page with the search results
Execute tool "open_page" with argument`url: https://zakupy.auchan.pl/search?q=PRODUCT_NAME`.
Make sure to replace the placeholder "PRODUCT_NAME" with the url-encoded nameof the product. Remember the tab_id of the created page, I'll refer it below asSEARCH_PAGE_TAB_ID.
# Step 2: Choose the product
The current page contains a list of products, to get them execute tool"get_auchan_products" with arguments:
- tab_id: SEARCH_PAGE_TAB_ID
Choose the product according to provided guidelines. Strictly follow theprovided guidelines. Skip the next step if the product that matches theguidelines is not available.
# Step 3: Add chosen product to the cart
Add selected product to cart using the tool "interact_with_page" with arguments:
- tab_id: SEARCH_PAGE_TAB_ID- interaction: click- selector: #ID of the "add to cart" button ("Dodaj" in polish language)
# Step 4: Report
Print the name of the added product, the explanation of why it was selectedand the link to the search results. If the product was not added, print thelink to the search results and the reason why it was not added.Extracting product list
Create the task:
- Main
- Name: “Auchan: Get products”,
- Tool: get_page_data
- Inherit parameters:
tab
- Arguments
- Schema:
{ "type": "array", "schema": { "type": "object", "schema": { "add": "[data-synthetics=\"add-button\"]:html()", "name": "h3", "price": "[data-test=\"fop-price\"]", "unit_price": "[data-test=\"fop-price-per-unit\"]" } }, "selector": ".product-card-container"}