🗃️ fix: revise RAG prompt (#3006)

This commit is contained in:
Danny Avila 2024-06-07 20:51:43 -04:00 committed by GitHub
parent baf0848021
commit 084cf266a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,8 +8,6 @@ In your response, remember to follow these guidelines:
- If you don't know the answer, simply say that you don't know. - If you don't know the answer, simply say that you don't know.
- If you are unsure how to answer, ask for clarification. - If you are unsure how to answer, ask for clarification.
- Avoid mentioning that you obtained the information from the context. - Avoid mentioning that you obtained the information from the context.
Answer appropriately in the user's language.
`; `;
function createContextHandlers(req, userMessageContent) { function createContextHandlers(req, userMessageContent) {
@ -94,37 +92,40 @@ function createContextHandlers(req, userMessageContent) {
const resolvedQueries = await Promise.all(queryPromises); const resolvedQueries = await Promise.all(queryPromises);
const context = resolvedQueries const context =
.map((queryResult, index) => { resolvedQueries.length === 0
const file = processedFiles[index]; ? '\n\tThe semantic search did not return any results.'
let contextItems = queryResult.data; : resolvedQueries
.map((queryResult, index) => {
const file = processedFiles[index];
let contextItems = queryResult.data;
const generateContext = (currentContext) => const generateContext = (currentContext) =>
` `
<file> <file>
<filename>${file.filename}</filename> <filename>${file.filename}</filename>
<context>${currentContext} <context>${currentContext}
</context> </context>
</file>`; </file>`;
if (useFullContext) { if (useFullContext) {
return generateContext(`\n${contextItems}`); return generateContext(`\n${contextItems}`);
} }
contextItems = queryResult.data contextItems = queryResult.data
.map((item) => { .map((item) => {
const pageContent = item[0].page_content; const pageContent = item[0].page_content;
return ` return `
<contextItem> <contextItem>
<![CDATA[${pageContent?.trim()}]]> <![CDATA[${pageContent?.trim()}]]>
</contextItem>`; </contextItem>`;
})
.join('');
return generateContext(contextItems);
}) })
.join(''); .join('');
return generateContext(contextItems);
})
.join('');
if (useFullContext) { if (useFullContext) {
const prompt = `${header} const prompt = `${header}
${context} ${context}