Spaces:
Running
Running
revert removed commits
Browse files- app/api/ask/route.ts +5 -39
app/api/ask/route.ts
CHANGED
@@ -324,41 +324,9 @@ export async function PUT(request: NextRequest) {
|
|
324 |
const systemPrompt = FOLLOW_UP_SYSTEM_PROMPT + (isNew ? PROMPT_FOR_PROJECT_NAME : "");
|
325 |
const userContext = "You are modifying the HTML file based on the user's request.";
|
326 |
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
const indexPage = pages.find(p => p.path === '/' || p.path === '/index' || p.path === 'index');
|
331 |
-
const otherPages = pages.filter(p => p !== indexPage);
|
332 |
-
|
333 |
-
if (selectedElementHtml) {
|
334 |
-
const elementKeywords = selectedElementHtml.toLowerCase().match(/class=["']([^"']*)["']|id=["']([^"']*)["']/g) || [];
|
335 |
-
const relevantPages = otherPages.filter(page => {
|
336 |
-
const pageContent = page.html.toLowerCase();
|
337 |
-
return elementKeywords.some((keyword: string) => pageContent.includes(keyword.toLowerCase()));
|
338 |
-
});
|
339 |
-
|
340 |
-
return indexPage ? [indexPage, ...relevantPages.slice(0, maxPages - 1)] : relevantPages.slice(0, maxPages);
|
341 |
-
}
|
342 |
-
|
343 |
-
const keywords = prompt.toLowerCase().split(/\s+/).filter(word => word.length > 3);
|
344 |
-
const scoredPages = otherPages.map(page => {
|
345 |
-
const pageContent = (page.path + ' ' + page.html).toLowerCase();
|
346 |
-
const score = keywords.reduce((acc, keyword) => {
|
347 |
-
return acc + (pageContent.includes(keyword) ? 1 : 0);
|
348 |
-
}, 0);
|
349 |
-
return { page, score };
|
350 |
-
});
|
351 |
-
|
352 |
-
const topPages = scoredPages
|
353 |
-
.sort((a, b) => b.score - a.score)
|
354 |
-
.slice(0, maxPages - (indexPage ? 1 : 0))
|
355 |
-
.map(item => item.page);
|
356 |
-
|
357 |
-
return indexPage ? [indexPage, ...topPages] : topPages;
|
358 |
-
};
|
359 |
-
|
360 |
-
const relevantPages = getRelevantPages(pages || [], prompt);
|
361 |
-
const pagesContext = relevantPages
|
362 |
.map((p: Page) => `- ${p.path}\n${p.html}`)
|
363 |
.join("\n\n");
|
364 |
|
@@ -366,7 +334,7 @@ export async function PUT(request: NextRequest) {
|
|
366 |
selectedElementHtml
|
367 |
? `\n\nYou have to update ONLY the following element, NOTHING ELSE: \n\n\`\`\`html\n${selectedElementHtml}\n\`\`\` Could be in multiple pages, if so, update all the pages.`
|
368 |
: ""
|
369 |
-
}. Current pages (${
|
370 |
|
371 |
const estimatedInputTokens = estimateInputTokens(systemPrompt, prompt, userContext + assistantContext);
|
372 |
const dynamicMaxTokens = calculateMaxTokens(selectedProvider, estimatedInputTokens, false);
|
@@ -691,7 +659,6 @@ pinned: false
|
|
691 |
tags:
|
692 |
- deepsite-v3
|
693 |
---
|
694 |
-
|
695 |
# Welcome to your new DeepSite project!
|
696 |
This project was created with [DeepSite](https://deepsite.hf.co).
|
697 |
`;
|
@@ -745,5 +712,4 @@ This project was created with [DeepSite](https://deepsite.hf.co).
|
|
745 |
{ status: 500 }
|
746 |
);
|
747 |
}
|
748 |
-
}
|
749 |
-
|
|
|
324 |
const systemPrompt = FOLLOW_UP_SYSTEM_PROMPT + (isNew ? PROMPT_FOR_PROJECT_NAME : "");
|
325 |
const userContext = "You are modifying the HTML file based on the user's request.";
|
326 |
|
327 |
+
// Send all pages without filtering
|
328 |
+
const allPages = pages || [];
|
329 |
+
const pagesContext = allPages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
.map((p: Page) => `- ${p.path}\n${p.html}`)
|
331 |
.join("\n\n");
|
332 |
|
|
|
334 |
selectedElementHtml
|
335 |
? `\n\nYou have to update ONLY the following element, NOTHING ELSE: \n\n\`\`\`html\n${selectedElementHtml}\n\`\`\` Could be in multiple pages, if so, update all the pages.`
|
336 |
: ""
|
337 |
+
}. Current pages (${allPages.length} total): ${pagesContext}. ${files?.length > 0 ? `Available images: ${files?.map((f: string) => f).join(', ')}.` : ""}`;
|
338 |
|
339 |
const estimatedInputTokens = estimateInputTokens(systemPrompt, prompt, userContext + assistantContext);
|
340 |
const dynamicMaxTokens = calculateMaxTokens(selectedProvider, estimatedInputTokens, false);
|
|
|
659 |
tags:
|
660 |
- deepsite-v3
|
661 |
---
|
|
|
662 |
# Welcome to your new DeepSite project!
|
663 |
This project was created with [DeepSite](https://deepsite.hf.co).
|
664 |
`;
|
|
|
712 |
{ status: 500 }
|
713 |
);
|
714 |
}
|
715 |
+
}
|
|