feat(pos/chat): add 4 AI chatbot improvements — symptom diagnosis, smart quotes, photo ID, multilanguage
1. Symptom diagnosis: AI now detects vehicle symptoms and suggests probable parts 2. Smart quotations: "cotizame frenos completos" returns multiple search_queries (pipe-separated), backend searches each term and deduplicates 3. Photo identification: camera button in chat widget uploads image and sends placeholder prompt (ready for vision model) 4. Multilanguage: AI detects user language and responds accordingly, search_query always in English Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -60,29 +60,39 @@ def chat():
|
||||
effective_query = part_words
|
||||
|
||||
if effective_query and tenant:
|
||||
# First: search local inventory
|
||||
try:
|
||||
local_results = _search_local_inventory(tenant, effective_query, search_query or '', branch_id)
|
||||
if local_results:
|
||||
search_results.extend(local_results)
|
||||
except Exception:
|
||||
pass
|
||||
# Support multiple search queries separated by | (for quotes/cotizaciones)
|
||||
query_terms = [q.strip() for q in effective_query.split('|') if q.strip()]
|
||||
seen_part_numbers = set()
|
||||
|
||||
# Then: search TecDoc catalog
|
||||
if master:
|
||||
for qt in query_terms:
|
||||
# First: search local inventory
|
||||
try:
|
||||
catalog_results = catalog_service.smart_search(
|
||||
master, effective_query, tenant, branch_id, limit=10
|
||||
)
|
||||
if catalog_results:
|
||||
# Mark as catalog results and avoid duplicates
|
||||
local_parts = {r.get('part_number', '') for r in search_results}
|
||||
for cr in catalog_results:
|
||||
if cr.get('oem_part_number', '') not in local_parts:
|
||||
cr['source'] = 'catalog'
|
||||
search_results.append(cr)
|
||||
local_results = _search_local_inventory(tenant, qt, qt, branch_id)
|
||||
if local_results:
|
||||
for lr in local_results:
|
||||
pn = lr.get('part_number', '')
|
||||
if pn not in seen_part_numbers:
|
||||
seen_part_numbers.add(pn)
|
||||
search_results.append(lr)
|
||||
except Exception:
|
||||
pass # search failure is non-fatal
|
||||
pass
|
||||
|
||||
# Then: search TecDoc catalog
|
||||
if master:
|
||||
try:
|
||||
per_query_limit = max(3, 10 // len(query_terms))
|
||||
catalog_results = catalog_service.smart_search(
|
||||
master, qt, tenant, branch_id, limit=per_query_limit
|
||||
)
|
||||
if catalog_results:
|
||||
for cr in catalog_results:
|
||||
pn = cr.get('oem_part_number', '')
|
||||
if pn not in seen_part_numbers:
|
||||
seen_part_numbers.add(pn)
|
||||
cr['source'] = 'catalog'
|
||||
search_results.append(cr)
|
||||
except Exception:
|
||||
pass # search failure is non-fatal
|
||||
|
||||
except Exception:
|
||||
pass # DB failure is non-fatal for chat
|
||||
|
||||
Reference in New Issue
Block a user