Skip to content

Commit b34f9ec

Browse files
committed
improve ask ai prompt
1 parent aa50235 commit b34f9ec

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

app/api/chat/route.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ const openrouter = createOpenRouter({
5656
});
5757

5858
const systemPrompt = [
59-
'You are an AI assistant for a documentation site.',
60-
'Use the `search` tool to retrieve relevant docs context before answering when needed.',
61-
'The `search` tool returns raw JSON results from documentation. Use those results to ground your answer and cite sources as markdown links using the document `url` field when available.',
62-
'If you cannot find the answer in search results, say you do not know and suggest a better search query.',
59+
'You are a helpful technical assistant for Next Commerce developer documentation.',
60+
'Your job is to answer developer questions clearly and concisely based on the documentation.',
61+
'Always use the `search` tool first to find relevant documentation before answering.',
62+
'Base your answers on the search results. Cite sources as markdown links using the document `url` field.',
63+
'When writing code examples, use the language shown in the documentation.',
64+
'If the search results do not contain enough information to answer the question, say so honestly.',
65+
'Do not make up API endpoints, parameters, or behaviours that are not in the documentation.',
66+
'Keep answers focused and practical. Avoid lengthy preambles — get straight to the answer.',
6367
].join('\n');
6468

6569
export async function POST(req: Request) {
@@ -68,9 +72,8 @@ export async function POST(req: Request) {
6872
let contextPrompt = systemPrompt;
6973
if (reqJson.pageUrl) {
7074
const page = source.getPages().find((p) => p.url === reqJson.pageUrl);
71-
if (page && 'getText' in page.data) {
72-
const content = await page.data.getText('processed');
73-
contextPrompt += `\n\nThe user is currently viewing the page "${page.data.title}" (${reqJson.pageUrl}). Here is its content for context:\n\n${content}`;
75+
if (page) {
76+
contextPrompt += `\n\nThe user is currently viewing the page "${page.data.title}" (${reqJson.pageUrl}). Use this to prioritize relevant search results.`;
7477
}
7578
}
7679

0 commit comments

Comments
 (0)