优化商品
This commit is contained in:
@@ -468,10 +468,32 @@ async def _generate_product_response(state: AgentState) -> AgentState:
|
|||||||
if tool_name == "search_products" or tool_name == "recommend_products":
|
if tool_name == "search_products" or tool_name == "recommend_products":
|
||||||
products = data.get("products", []) if isinstance(data, dict) else []
|
products = data.get("products", []) if isinstance(data, dict) else []
|
||||||
if products:
|
if products:
|
||||||
product_summaries = [f"- {p.get('product_name', 'N/A')}: {p.get('price', 'N/A')}" for p in products[:3]]
|
# Keep top 5 products with more details
|
||||||
summary = f"Found {len(products)} products:\n" + "\n".join(product_summaries)
|
product_items = []
|
||||||
if len(products) > 3:
|
for p in products[:5]: # Increased from 3 to 5
|
||||||
summary += f"\n(and {len(products) - 3} more)"
|
name = p.get('product_name', 'N/A')
|
||||||
|
price = p.get('price', 'N/A')
|
||||||
|
special_price = p.get('special_price')
|
||||||
|
spu_id = p.get('spu_id', '')
|
||||||
|
|
||||||
|
# Show special price if available
|
||||||
|
if special_price and float(special_price) > 0:
|
||||||
|
price_str = f"原价: {price}, 特价: {special_price}"
|
||||||
|
else:
|
||||||
|
price_str = str(price)
|
||||||
|
|
||||||
|
# Format: [ID] Name - Price
|
||||||
|
if spu_id:
|
||||||
|
product_items.append(f"- [{spu_id}] {name} - {price_str}")
|
||||||
|
else:
|
||||||
|
product_items.append(f"- {name} - {price_str}")
|
||||||
|
|
||||||
|
summary = f"Found {len(products)} products:\n" + "\n".join(product_items)
|
||||||
|
|
||||||
|
# Add note if there are more products
|
||||||
|
if len(products) > 5:
|
||||||
|
summary += f"\n(and {len(products) - 5} more products, visit website for full selection)"
|
||||||
|
|
||||||
tool_context.append(summary)
|
tool_context.append(summary)
|
||||||
else:
|
else:
|
||||||
tool_context.append("No products found")
|
tool_context.append("No products found")
|
||||||
|
|||||||
Reference in New Issue
Block a user