I am using model 4o and the web search tool in open ai api to fetch the price of a product from a website. It seems to work well for some but not for others.
Even though it gives the correct url for the product , it just gives the wrong price both when using api and playground.
Below is my code:
class ProductEvent(BaseModel):
Product_url: str
Brand: Optional[str] = None
SKU_name: str
Product_description: Optional[List[str]] = None
Regular_price: Optional[str] = None
Promo_price: Optional[str] = None
Confidence: Optional[str] = None
client = OpenAI(api_key=openai_key)
instructions = “”" You are a specialist in sourcing pricing data from retailers.
Task:
Locate the product corresponding to the provided SKU only on the website provided.
Once identified, extract and return the result as a valid JSON containing following fields:
{
"product URL": "the product URL from the search result"
" brand": "the brand as found on the website"
"SKU name": "the SKU name as found on the website"
"product description": "product description as found on the website"
"regular price": "regular price as found on the website without the currency symbol, provide only the number, make sure the price is correct"
"promo price": "promo price as found on the website (if applicable, NA otherwise)"
"confidence": "level of confidence that the search result reflects the same product as the one provided"
}
Output Requirements:
1.Ensure the JSON is valid and complete (i.e., properly closed braces/brackets, no trailing commas).
2.if the domain does not contain any SKU that resembles the product, please return "No result" """
tools=[
{
“type”: “web_search_preview”,
“user_location”: {
“type”: “approximate”,
“country”: “GB”,
“city”: “London”,
“region”: “London”,
}
}
]
def process_row(row):
website = “ttps://www.argos.co.uk/”
item = row[“Item”]
subcategory = row[“Subcategory”]
category = row[“Category”]
response = client.responses.parse(
model=“gpt-4o”,
temperature=0,
tools=tools,
tool_choice=“required”,
instructions=instructions,
input = f""“On the domain {website} find the SKU that best matches new {item} {subcategory}, {category} “””,
text_format=ProductEvent,
)
event = json.loads(response.output_text)
return event
Apply the function to each row and store the results in a new DataFrame
results = df_input.apply(process_row, axis=1)
results_df = pd.DataFrame(results.tolist())
This is my input
Electronics,Mobile phones & tablets,Apple iPad (2021) 64GB Wi-fi 10.2-In
my output
ttps://www.argos.co.uk/product/9506172,Apple,Apple iPad 2021 10.2 Inch Wi-Fi 64GB - Silver,[Delightfully capable. Surprisingly affordable…,289.00,None,High
But if we click on the link it provides it shows 269 not 289