fix(pos): chatbot busca partes automaticamente con traduccion ES→EN
- System prompt: SIEMPRE devuelve search_query en ingles - Diccionario de traducciones (balatas→Brake Pad, etc.) - Busca directo sin preguntar mas info - Fallback: extrae keywords si AI no da search_query Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -46,10 +46,23 @@ def chat():
|
||||
vehicle_match = _resolve_vehicle(master, vehicle)
|
||||
|
||||
# Run catalog search if we have a search query
|
||||
if search_query and master and tenant:
|
||||
# Also search if AI identified a vehicle but didn't give a search_query
|
||||
effective_query = search_query
|
||||
if not effective_query and vehicle:
|
||||
# Extract likely part keywords from the user's message
|
||||
import re
|
||||
# Remove brand/model/year from message to get the part description
|
||||
part_words = user_message.lower()
|
||||
for remove in [vehicle.get('brand',''), vehicle.get('model',''), str(vehicle.get('year',''))]:
|
||||
part_words = part_words.replace(remove.lower(), '')
|
||||
part_words = re.sub(r'necesito|quiero|busco|para|un|una|el|la|de|del|los|las|mi|\d{4}', '', part_words).strip()
|
||||
if len(part_words) >= 3:
|
||||
effective_query = part_words
|
||||
|
||||
if effective_query and master and tenant:
|
||||
try:
|
||||
results = catalog_service.smart_search(
|
||||
master, search_query, tenant, branch_id, limit=10
|
||||
master, effective_query, tenant, branch_id, limit=10
|
||||
)
|
||||
search_results = results if results else []
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user