Add store-server.gbai: barcode scan, image search, NCM, shipping, auto-register

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-01-14 11:43:46 -03:00
parent c11160d37d
commit d6b9016564
12 changed files with 179 additions and 20 deletions

View file

@ -0,0 +1,12 @@
PARAM query AS STRING
existing = SEARCH PRODUCTS query, 1
IF LEN(existing) > 0 THEN
RETURN existing[0]
END IF
info = LLM "Extract product info: " + query + ". Return JSON {name, category, brand, description}"
info.is_active = true
SAVE "products", info
RETURN info

View file

@ -0,0 +1,41 @@
PARAM product_id AS STRING
PARAM quantity AS INTEGER
product = PRODUCT product_id
IF NOT product THEN
RETURN {error: "Product not found"}
END IF
IF NOT quantity THEN
quantity = 1
END IF
dimensions = {
length: product.length,
width: product.width,
height: product.height,
weight: product.gross_weight
}
IF NOT dimensions.weight THEN
dimensions = LLM "Estimate shipping dimensions for: " + product.name + ". Return JSON {length_cm, width_cm, height_cm, weight_kg}"
END IF
volume = dimensions.length * dimensions.width * dimensions.height * quantity
volumetric_weight = volume / 5000
billable = MAX(dimensions.weight * quantity, volumetric_weight)
shipping = {
product_id: product_id,
quantity: quantity,
dimensions: dimensions,
volume_cm3: volume,
billable_weight_kg: billable,
options: [
{carrier: "Ground", days: "5-7", cost: 5.99 + billable * 1.5},
{carrier: "Express", days: "2-3", cost: 12.99 + billable * 2.5},
{carrier: "Overnight", days: "1", cost: 24.99 + billable * 4.0}
]
}
RETURN shipping

View file

@ -0,0 +1,13 @@
PARAM query AS STRING
categories = FIND "categories"
similar = SEARCH PRODUCTS query, 5
result = LLM "Classify '" + query + "' into: " + categories + ". Similar: " + similar + ". Return JSON {category_id, name, confidence, brand, type}"
cached = FIND "product_cache", "query=" + query
IF cached THEN
RETURN cached.result
END IF
SAVE "product_cache", {query: query, result: result}
RETURN result

View file

@ -0,0 +1,35 @@
PARAM product_id AS STRING
product = PRODUCT product_id
IF NOT product THEN
RETURN {error: "Product not found"}
END IF
IF product.description AND product.brand THEN
RETURN product
END IF
query = product.name + " " + product.category
links = SCRAPE_ALL "https://www.google.com/search?q=" + query, "a"
links = FIRST links, 10
enriched = []
FOR i = 0 TO 2
IF links[i] THEN
content = SCRAPE links[i], "body"
PUSH enriched, content
END IF
NEXT
result = LLM "Analyze these product descriptions: " + enriched + ". Create best description for: " + product.name + ". Return JSON {description, brand, material, features}"
UPDATE "products", product_id, {
description: result.description,
brand: result.brand,
material: result.material,
external_metadata: result
}
product.description = result.description
product.brand = result.brand
RETURN product

View file

@ -0,0 +1,14 @@
PARAM product_id AS STRING
product = PRODUCT product_id
IF NOT product THEN
RETURN {error: "Product not found"}
END IF
IF product.tax_code THEN
RETURN {tax_code: product.tax_code, tax_class: product.tax_class}
END IF
info = LLM "Get NCM/tax classification for: " + product.name + " " + product.category + ". Return JSON {tax_code, tax_class, description}"
UPDATE "products", product_id, {tax_code: info.tax_code, tax_class: info.tax_class}
RETURN info

View file

@ -0,0 +1,30 @@
PARAM image AS STRING
barcode = SCAN BARCODE image
IF NOT barcode THEN
RETURN {error: "No barcode found"}
END IF
ean = barcode.data
cached = FIND "products", "global_trade_number=" + ean
IF cached THEN
RETURN cached
END IF
data = GET "https://world.openfoodfacts.org/api/v0/product/" + ean + ".json"
IF data.product THEN
product = {
name: data.product.product_name,
brand: data.product.brands,
global_trade_number: ean,
description: data.product.generic_name,
category: data.product.categories,
net_weight: data.product.quantity
}
ELSE
product = LLM "Search product info for EAN: " + ean + ". Return JSON {name, brand, description, category}"
product.global_trade_number = ean
END IF
SAVE "products", product
RETURN product

View file

@ -0,0 +1,12 @@
PARAM image AS STRING
description = SEE image
similar = SEARCH PRODUCTS description, 5
IF LEN(similar) > 0 THEN
RETURN similar[0]
END IF
product = LLM "Extract product info from: " + description + ". Return JSON {name, brand, category, color, material}"
SAVE "products", product
RETURN product

View file

@ -0,0 +1,16 @@
PARAM query AS STRING
cached = FIND "search_cache", "query=" + query
IF cached THEN
RETURN cached.result
END IF
result = SEARCH PRODUCTS query, 10
IF LEN(result) = 0 THEN
web = SCRAPE_ALL "https://www.google.com/search?q=" + query + "+product", ".g"
result = LLM "Extract products from: " + web + ". Return JSON [{name, price, description}]"
END IF
enhanced = LLM "Add descriptions: " + result + ". Return JSON [{id, name, price, description, stock}]"
SAVE "search_cache", {query: query, result: enhanced}
RETURN enhanced

View file

@ -0,0 +1,6 @@
name,value
bot-name,store-server
bot-description,Store Server API - Product search, classification, barcode scanning and enrichment
botmodels-enabled,true
llm-provider,openai
llm-model,gpt-4o
1 name,value
2 bot-name,store-server
3 bot-description,Store Server API - Product search, classification, barcode scanning and enrichment
4 botmodels-enabled,true
5 llm-provider,openai
6 llm-model,gpt-4o

View file

@ -1,7 +0,0 @@
PARAM product_id AS INTEGER
PARAM quantity AS INTEGER OPTIONAL
product = PRODUCT product_id
shipping = LLM "Calculate shipping for: " + product + ", qty: " + quantity + ". Return JSON {dimensions: {length_cm, width_cm, height_cm}, weight_kg, volume_cm3, shipping_options: [{carrier, cost, days}]}"
RETURN shipping

View file

@ -1,7 +0,0 @@
PARAM query AS STRING
categories = FIND "Categories.csv"
result = SEARCH PRODUCTS query, 5
enhanced = LLM "Classify '" + query + "' into categories: " + categories + ". Similar products: " + result + ". Return JSON {category_id, category_name, confidence, attributes: {brand, type}}"
RETURN enhanced

View file

@ -1,6 +0,0 @@
PARAM query AS STRING
result = SEARCH PRODUCTS query, 10
enhanced = LLM "Enhance these product results with descriptions: " + result + ". Return JSON array with id, name, price, description"
RETURN enhanced