mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-12-14 15:48:15 +00:00
feat(search): add better context handling
This commit is contained in:
@@ -55,19 +55,20 @@ class SearchAgent {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const finalContext =
|
const finalContext =
|
||||||
searchResults?.findings
|
searchResults?.searchFindings
|
||||||
.filter((f) => f.type === 'search_results')
|
.map(
|
||||||
.flatMap((f) => f.results)
|
(f, index) =>
|
||||||
.map((f) => `${f.metadata.title}: ${f.content}`)
|
`<result index=${index} title=${f.metadata.title}>${f.content}</result>`,
|
||||||
|
)
|
||||||
.join('\n') || '';
|
.join('\n') || '';
|
||||||
|
|
||||||
const widgetContext = widgetOutputs
|
const widgetContext = widgetOutputs
|
||||||
.map((o) => {
|
.map((o) => {
|
||||||
return `${o.type}: ${o.llmContext}`;
|
return `<result>${o.llmContext}</result>`;
|
||||||
})
|
})
|
||||||
.join('\n-------------\n');
|
.join('\n-------------\n');
|
||||||
|
|
||||||
const finalContextWithWidgets = `<search_results note="These are the search results and you can cite these">${finalContext}</search_results>\n<widgets_result noteForAssistant="Its output is already showed to the user, you can use this information to answer the query but do not CITE this as a souce">${widgetContext}</widgets_result>`;
|
const finalContextWithWidgets = `<search_results note="These are the search results and assistant can cite these">\n${finalContext}\n</search_results>\n<widgets_result noteForAssistant="Its output is already showed to the user, assistant can use this information to answer the query but do not CITE this as a souce">\n${widgetContext}\n</widgets_result>`;
|
||||||
|
|
||||||
const writerPrompt = getWriterPrompt(finalContextWithWidgets);
|
const writerPrompt = getWriterPrompt(finalContextWithWidgets);
|
||||||
const answerStream = input.config.llm.streamText({
|
const answerStream = input.config.llm.streamText({
|
||||||
|
|||||||
Reference in New Issue
Block a user