feat: improve prompt

This commit is contained in:
Han Xiao 2025-02-11 21:18:16 +08:00
parent b819af4e57
commit b773a27514
2 changed files with 22 additions and 15 deletions

View File

@ -174,20 +174,24 @@ ${learnedStrategy}
// Build actions section // Build actions section
if (allURLs && Object.keys(allURLs).length > 0 && allowRead) { if (allowRead) {
const urlList = Object.entries(allURLs) let urlList = '';
.map(([url, desc]) => ` + "${url}": "${desc}"`) if (allURLs && Object.keys(allURLs).length > 0) {
.join('\n'); urlList = Object.entries(allURLs)
.map(([url, desc]) => ` + "${url}": "${desc}"`)
.join('\n');
}
actionSections.push(` actionSections.push(`
<action-visit> <action-visit>
- This allows you to access the full content behind any URLs.
- If the <question> contains a URL, you must visit the URL to gather more information.
${urlList ? `
- Visit any URLs from below to gather external knowledge, choose the most relevant URLs that might contain the answer - Visit any URLs from below to gather external knowledge, choose the most relevant URLs that might contain the answer
<url-list> <url-list>
${urlList} ${urlList}
</url-list> </url-list>
- When you have enough search result in the context and want to deep dive into specific URLs `.trim() : ''}
- It allows you to access the full content behind any URLs
</action-visit> </action-visit>
`); `);
} }
@ -213,8 +217,10 @@ ${allKeywords.join('\n')}
actionSections.push(` actionSections.push(`
<action-answer> <action-answer>
- If <question> is a simple greeting, chit-chat, or general knowledge, provide the answer directly. - If <question> is a simple greeting, chit-chat, or general knowledge, provide the answer directly.
- Provide final response only when 100% certain - Must provide "references" and each must specify "exactQuote" and "url"
- Responses must be definitive (no ambiguity, uncertainty, or disclaimers)${allowReflect ? '\n- If doubts remain, use <action-reflect> instead' : ''} - In the answer, use markdown footnote syntax like [^1], [^2] to refer to the references
- Responses must be definitive (no ambiguity, uncertainty, or disclaimers)
- Provide final response only when 100% certain${allowReflect ? '\n- If doubts remain, use <action-reflect> instead' : ''}
</action-answer> </action-answer>
`); `);
} }
@ -323,7 +329,7 @@ export async function getResponse(question: string, tokenBudget: number = 1_000_
} }
// update all urls with buildURLMap // update all urls with buildURLMap
allowRead = allowRead && (Object.keys(allURLs).length > 0); // allowRead = allowRead && (Object.keys(allURLs).length > 0);
allowSearch = allowSearch && (Object.keys(allURLs).length < 50); // disable search when too many urls already allowSearch = allowSearch && (Object.keys(allURLs).length < 50); // disable search when too many urls already
// generate prompt for this step // generate prompt for this step

View File

@ -45,12 +45,13 @@ function buildMdFromAnswer(answer: AnswerAction) {
let refStr = ''; let refStr = '';
if (answer.references?.length > 0) { if (answer.references?.length > 0) {
refStr = ` refStr = `
<references>
## References
${answer.references.map((ref, i) => ` ${answer.references.map((ref, i) => `
${i + 1}. [${ref.exactQuote}](${ref.url})`).join('')}`; ${i + 1}. [${ref.exactQuote}](${ref.url})`).join('')}
</references>
`.trim();
} }
return `${answer.answer.replace(/\(REF_(\d+)\)/g, (_, num) => `[^${num}]`)}${refStr}`; return `${answer.answer.replace(/\(REF_(\d+)\)/g, (_, num) => `[^${num}]`)}\n${refStr}`;
} }