in backend-apis/app/routers/p1_customer.py [0:0]
def compare_products(data: CompareProductsRequest) -> HTMLResponse:
"""
# Compare Products
## Request body [CompareProductsRequest]
**products**: *list[string]*
- List of products ids
## Returns:
**HTMLResponse**
- A HTML comparison table
## Raises:
**HTTPException** - *400* - Error Generating the table
- PaLM got an error generating the table
"""
try:
for i in data.products:
print("Product Description------")
print(i)
product_1 = json.loads(data.products[0])
del product_1["image"]
del product_1["quantity"]
del product_1["id"]
del product_1["features"]
del product_1["categories"]
product_2 = json.loads(data.products[1])
del product_2["image"]
del product_2["quantity"]
del product_2["id"]
del product_2["features"]
del product_2["categories"]
comparison = utils_gemini.generate_gemini_pro_text(
prompt=config["compare"]["prompt_compare"].format(
product_title_1=product_1["title"],
product_description_1=product_1["description"],
product_title_2=product_2["title"],
product_description_2=product_2["description"]
),
temperature=0.2,
top_k=40,
top_p=0.8
)
return HTMLResponse(content=comparison)
except GoogleAPICallError as e:
raise HTTPException(
status_code=400, detail="Error generating the HTML. " + str(e)
) from e