mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
🗃️ fix: revise RAG prompt (#3006)
This commit is contained in:
parent
baf0848021
commit
084cf266a2
1 changed files with 20 additions and 19 deletions
|
@ -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}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue