Spaces:
Sleeping
Sleeping
Fix: Make AI intent parsing more lenient and prevent clarification loops for queries like 'test labs'
Browse files
server/src/services/ai.service.js
CHANGED
|
@@ -29,19 +29,19 @@ Extract structured intent from user queries. Return ONLY valid JSON with these f
|
|
| 29 |
{
|
| 30 |
"reasoning": "string (Short one-sentence explanation of how you interpreted this query)",
|
| 31 |
"isOutOfScope": "boolean (true if the query is NOT about finding a place, service, or specific product/brand. e.g., 'how to cook', 'who is the president', 'solve 2+2')",
|
| 32 |
-
"scopeMessage": "string or null (If isOutOfScope is true, provide a polite
|
| 33 |
-
"needsClarification": "boolean (true if the query is a
|
| 34 |
"clarificationQuestion": "string or null (If needsClarification is true, provide a conversational follow-up question.)",
|
| 35 |
-
"category": "string (The broad type of place, e.g., shop, restaurant, electronics_store)",
|
| 36 |
-
"isSpecific": "boolean (true if the user is looking for a VERY specific brand, product, or niche item
|
| 37 |
"specificItem": "string or null (The exact name of the brand/product/item requested)",
|
| 38 |
-
"location": "string or null (Extract ONLY the major city name
|
| 39 |
"neighborhood": "string or null (Extract specific area if mentioned)",
|
| 40 |
"budget": { "min": number|null, "max": number|null, "currency": "string" },
|
| 41 |
"features": ["array of desired features"],
|
| 42 |
"occasion": "string or null",
|
| 43 |
"sortBy": "string (rating|price|distance|relevance)"
|
| 44 |
-
} - Note:
|
| 45 |
|
| 46 |
if (clarificationContext) {
|
| 47 |
systemPrompt += `\n\nCRITICAL CONTEXT: The user previously searched for "${clarificationContext.originalQuery}", and you asked them: "${clarificationContext.question}". The user answered: "${clarificationContext.answer}".
|
|
|
|
| 29 |
{
|
| 30 |
"reasoning": "string (Short one-sentence explanation of how you interpreted this query)",
|
| 31 |
"isOutOfScope": "boolean (true if the query is NOT about finding a place, service, or specific product/brand. e.g., 'how to cook', 'who is the president', 'solve 2+2')",
|
| 32 |
+
"scopeMessage": "string or null (If isOutOfScope is true, provide a polite response explaining that RedThread is a specialized discovery engine for locations, services, and local products.)",
|
| 33 |
+
"needsClarification": "boolean (true ONLY if the query is a single ambiguous word like 'apple' or 'monster' and you have NO idea what it means. false if it's a multi-word category like 'test labs' or 'coffee shop')",
|
| 34 |
"clarificationQuestion": "string or null (If needsClarification is true, provide a conversational follow-up question.)",
|
| 35 |
+
"category": "string (The broad type of place, e.g., shop, restaurant, electronics_store, medical_lab, coworking_space)",
|
| 36 |
+
"isSpecific": "boolean (true if the user is looking for a VERY specific brand, product, or niche item)",
|
| 37 |
"specificItem": "string or null (The exact name of the brand/product/item requested)",
|
| 38 |
+
"location": "string or null (Extract ONLY the major city name. Do NOT extract words like 'me', 'here', or 'nearby'. If no city is found, return null. DO NOT set needsClarification=true just because the location is missing.)",
|
| 39 |
"neighborhood": "string or null (Extract specific area if mentioned)",
|
| 40 |
"budget": { "min": number|null, "max": number|null, "currency": "string" },
|
| 41 |
"features": ["array of desired features"],
|
| 42 |
"occasion": "string or null",
|
| 43 |
"sortBy": "string (rating|price|distance|relevance)"
|
| 44 |
+
} - Note: If the query is multi-word (e.g. 'test labs'), match it to the closest category and set needsClarification: false. If it is completely unrelated to discovery, set isOutOfScope: true.`;
|
| 45 |
|
| 46 |
if (clarificationContext) {
|
| 47 |
systemPrompt += `\n\nCRITICAL CONTEXT: The user previously searched for "${clarificationContext.originalQuery}", and you asked them: "${clarificationContext.question}". The user answered: "${clarificationContext.answer}".
|