Spaces:
Sleeping
Sleeping
Ultra-optimize AI and Scraper for niche items (needles, toothpicks, etc.) and product discovery logic
Browse files
server/src/controllers/search.controller.js
CHANGED
|
@@ -83,10 +83,15 @@ async function handleSearch(req, res, next) {
|
|
| 83 |
const checkSatisfaction = () => {
|
| 84 |
if (!intent.isSpecific || !intent.specificItem) return true;
|
| 85 |
const item = intent.specificItem.toLowerCase();
|
| 86 |
-
return data.results.some(r =>
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
};
|
| 91 |
|
| 92 |
const isDeeplySatisfied = checkSatisfaction();
|
|
|
|
| 83 |
const checkSatisfaction = () => {
|
| 84 |
if (!intent.isSpecific || !intent.specificItem) return true;
|
| 85 |
const item = intent.specificItem.toLowerCase();
|
| 86 |
+
return data.results.some(r => {
|
| 87 |
+
const searchSpace = [
|
| 88 |
+
r.name,
|
| 89 |
+
...(r.features || []),
|
| 90 |
+
r.rawCategory || '',
|
| 91 |
+
r.reviewSummary || ''
|
| 92 |
+
].join(' ').toLowerCase();
|
| 93 |
+
return searchSpace.includes(item);
|
| 94 |
+
});
|
| 95 |
};
|
| 96 |
|
| 97 |
const isDeeplySatisfied = checkSatisfaction();
|
server/src/services/ai.service.js
CHANGED
|
@@ -24,24 +24,28 @@ async function parseIntent(query, clarificationContext = null) {
|
|
| 24 |
.replace(/\b(near me|around me|close to me|nearby|here)\b/gi, '')
|
| 25 |
.trim();
|
| 26 |
|
| 27 |
-
let systemPrompt = `You are a
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
{
|
| 30 |
-
"reasoning": "string (
|
| 31 |
-
"isOutOfScope": "boolean (
|
| 32 |
-
"scopeMessage": "string or null
|
| 33 |
-
"needsClarification": "boolean (
|
| 34 |
-
"clarificationQuestion": "string or null
|
| 35 |
-
"category": "string (The
|
| 36 |
-
"isSpecific": "boolean (true if the user
|
| 37 |
-
"specificItem": "string or null (The exact
|
| 38 |
-
"location": "string or null (Extract
|
| 39 |
-
"neighborhood": "string or null
|
| 40 |
"budget": { "min": number|null, "max": number|null, "currency": "string" },
|
| 41 |
-
"features": ["array of
|
| 42 |
"occasion": "string or null",
|
| 43 |
"sortBy": "string (rating|price|distance|relevance)"
|
| 44 |
-
}
|
|
|
|
|
|
|
| 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}".
|
|
|
|
| 24 |
.replace(/\b(near me|around me|close to me|nearby|here)\b/gi, '')
|
| 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 |
+
Even for tiny items (e.g., "needle", "toothpick", "string"), your job is to find the most logical place where they are sold.
|
| 29 |
+
|
| 30 |
+
Return ONLY valid JSON:
|
| 31 |
{
|
| 32 |
+
"reasoning": "string (Why you picked this category for this item)",
|
| 33 |
+
"isOutOfScope": "boolean (false for almost everything except pure knowledge queries like 'who is Newton' or 'math')",
|
| 34 |
+
"scopeMessage": "string or null",
|
| 35 |
+
"needsClarification": "boolean (ONLY true if the query is a single nonsense word. If it's a real word like 'string', pick a 'stationary' or 'hardware' category and proceed.)",
|
| 36 |
+
"clarificationQuestion": "string or null",
|
| 37 |
+
"category": "string (The BEST physical store type, e.g., stationary, pharmacy, hardware_store, department_store, grocery, electronics)",
|
| 38 |
+
"isSpecific": "boolean (Always true if the user mentions a specific product or tiny item beyond a general place name)",
|
| 39 |
+
"specificItem": "string or null (The exact item, e.g., 'needle')",
|
| 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 for this search"],
|
| 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}".
|