feat(whatsapp): QWEN primary AI backend, Hermes fallback, conversation history, vehicle persistence, demo prompts
- Add QWEN (qwen3.6) as primary AI backend with short system prompt - Hermes remains as fallback with 45s timeout - Increase QWEN timeout to 35s, max_tokens to 4000 - Add conversation history loading from whatsapp_messages (last 4 msgs) - Persist detected vehicle in whatsapp_sessions table - Add 'limpiar chat' / 'nuevo chat' / 'reset' commands to clear history - Fix CSS conflict: rename whatsapp chat-panel classes to wa-chat-panel - Fix JS ID conflicts with chat.js widget (waChatPanel, waChatMessages, etc.) - Improve no-stock response: conversational with alternatives - Split search_query by | for multi-part lookups - Add DEMO_PROMPTS.md and DEMO_PROMPTS_V2.md
This commit is contained in:
@@ -403,3 +403,56 @@ def save_qwen_fitment(tenant_conn, inventory_id, fitment_result):
|
||||
tenant_conn.commit()
|
||||
cur.close()
|
||||
return inserted
|
||||
|
||||
|
||||
def get_inventory_by_vehicle(tenant_conn, master_conn, mye_id, branch_id=None):
|
||||
"""Return local inventory items compatible with a given vehicle (MYE).
|
||||
|
||||
Args:
|
||||
tenant_conn: Connection to tenant DB.
|
||||
master_conn: Connection to master DB (kept for API consistency).
|
||||
mye_id: model_year_engine_id.
|
||||
branch_id: Optional branch filter for stock.
|
||||
|
||||
Returns:
|
||||
List of tuples: (id, part_number, name, brand, price_1, price_2, price_3,
|
||||
image_url, description, stock)
|
||||
"""
|
||||
cur = tenant_conn.cursor()
|
||||
|
||||
if branch_id:
|
||||
# Stock for specific branch
|
||||
cur.execute("""
|
||||
SELECT i.id, i.part_number, i.name, i.brand,
|
||||
i.price_1, i.price_2, i.price_3,
|
||||
i.image_url, i.description,
|
||||
COALESCE(s.stock, 0) as stock
|
||||
FROM inventory i
|
||||
JOIN inventory_vehicle_compat ivc ON ivc.inventory_id = i.id
|
||||
LEFT JOIN inventory_stock_summary s
|
||||
ON s.inventory_id = i.id AND s.branch_id = %s
|
||||
WHERE ivc.model_year_engine_id = %s
|
||||
AND i.is_active = true
|
||||
ORDER BY i.name
|
||||
""", (branch_id, mye_id))
|
||||
else:
|
||||
# Total stock across all branches
|
||||
cur.execute("""
|
||||
SELECT i.id, i.part_number, i.name, i.brand,
|
||||
i.price_1, i.price_2, i.price_3,
|
||||
i.image_url, i.description,
|
||||
COALESCE(SUM(s.stock), 0) as stock
|
||||
FROM inventory i
|
||||
JOIN inventory_vehicle_compat ivc ON ivc.inventory_id = i.id
|
||||
LEFT JOIN inventory_stock_summary s ON s.inventory_id = i.id
|
||||
WHERE ivc.model_year_engine_id = %s
|
||||
AND i.is_active = true
|
||||
GROUP BY i.id, i.part_number, i.name, i.brand,
|
||||
i.price_1, i.price_2, i.price_3,
|
||||
i.image_url, i.description
|
||||
ORDER BY i.name
|
||||
""", (mye_id,))
|
||||
|
||||
rows = cur.fetchall()
|
||||
cur.close()
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user