Spaces:
Running
Running
Upgrade AI 'Neural Context' to understand cultural/anime references (Your Name red thread)
Browse files
server/src/services/ai.service.js
CHANGED
|
@@ -25,27 +25,30 @@ async function parseIntent(query, clarificationContext = null) {
|
|
| 25 |
.trim();
|
| 26 |
|
| 27 |
let systemPrompt = `You are a high-intelligence discovery engine. Your goal is to map ANY user query to a physical location, service, or product source.
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
Return ONLY valid JSON:
|
| 31 |
{
|
| 32 |
-
"reasoning": "string (
|
| 33 |
-
"isOutOfScope": "boolean (false for almost everything except pure
|
| 34 |
"scopeMessage": "string or null",
|
| 35 |
-
"needsClarification": "boolean (ONLY true
|
| 36 |
"clarificationQuestion": "string or null",
|
| 37 |
-
"category": "string (The BEST physical store type, e.g.,
|
| 38 |
-
"isSpecific": "boolean (Always true if the user mentions a specific product or
|
| 39 |
-
"specificItem": "string or null (The exact item, e.g., '
|
| 40 |
"location": "string or null (Extract city name. Use null if missing.)",
|
| 41 |
"neighborhood": "string or null",
|
| 42 |
"budget": { "min": number|null, "max": number|null, "currency": "string" },
|
| 43 |
-
"features": ["array of likely features
|
| 44 |
"occasion": "string or null",
|
| 45 |
"sortBy": "string (rating|price|distance|relevance)"
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
Thinking logic: If someone wants a "needle", they likely need a "stationary" or "tailoring_shop". If they want "monster", they want a "supermarket" or "convenience_store". Map the item to the STORES that likely carry it.`;
|
| 49 |
|
| 50 |
if (clarificationContext) {
|
| 51 |
systemPrompt += `\n\nCRITICAL CONTEXT: The user previously searched for "${clarificationContext.originalQuery}", and you asked them: "${clarificationContext.question}". The user answered: "${clarificationContext.answer}".
|
|
|
|
| 25 |
.trim();
|
| 26 |
|
| 27 |
let systemPrompt = `You are a high-intelligence discovery engine. Your goal is to map ANY user query to a physical location, service, or product source.
|
| 28 |
+
Use your VAST WORLD KNOWLEDGE to interpret the "Vibe" and "Context" of the search.
|
| 29 |
+
|
| 30 |
+
CRITICAL DISCOVERY RULES:
|
| 31 |
+
1. CONTEXTUAL INTELLIGENCE: If someone mentions a movie, anime, or culture (e.g., "red thread from Your Name"), do NOT just treat it as keywords. Recognize that they are looking for "Kumihimo" or "Japanese traditional lucky charms". Map it to "Japanese Gift Shop", "Traditional Craft Store", or "Anime Merch Store".
|
| 32 |
+
2. NICHE ITEMS: Even for tiny items (e.g., "needle", "toothpick"), find the most logical place (e.g., "stationary" or "pharmacy").
|
| 33 |
+
3. NO CLARIFICATION LOOPS: If the query is a real word/phrase, proceed with a "Best Guess" category.
|
| 34 |
|
| 35 |
Return ONLY valid JSON:
|
| 36 |
{
|
| 37 |
+
"reasoning": "string (Explain your high-level cultural/logical interpretation, e.g., 'Targeting Japanese gift shops for Kumihimo as seen in Kimi no Na wa')",
|
| 38 |
+
"isOutOfScope": "boolean (false for almost everything except pure info like 'Who is Elon Musk')",
|
| 39 |
"scopeMessage": "string or null",
|
| 40 |
+
"needsClarification": "boolean (ONLY true for single nonsense words)",
|
| 41 |
"clarificationQuestion": "string or null",
|
| 42 |
+
"category": "string (The BEST physical store type, e.g., japanese_gift_shop, anime_store, craft_store, hardware_store)",
|
| 43 |
+
"isSpecific": "boolean (Always true if the user mentions a specific product or cultural item)",
|
| 44 |
+
"specificItem": "string or null (The exact cultural/product item, e.g., 'Kumihimo Braided Cord')",
|
| 45 |
"location": "string or null (Extract city name. Use null if missing.)",
|
| 46 |
"neighborhood": "string or null",
|
| 47 |
"budget": { "min": number|null, "max": number|null, "currency": "string" },
|
| 48 |
+
"features": ["array of likely features, e.g., 'Traditional Japanese', 'Anime Merch'"],
|
| 49 |
"occasion": "string or null",
|
| 50 |
"sortBy": "string (rating|price|distance|relevance)"
|
| 51 |
+
}`;
|
|
|
|
|
|
|
| 52 |
|
| 53 |
if (clarificationContext) {
|
| 54 |
systemPrompt += `\n\nCRITICAL CONTEXT: The user previously searched for "${clarificationContext.originalQuery}", and you asked them: "${clarificationContext.question}". The user answered: "${clarificationContext.answer}".
|