mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2026-04-10 13:54:28 +00:00
feat(search): handle empty context better
This commit is contained in:
@@ -5,9 +5,10 @@ import Researcher from './researcher';
|
|||||||
import { getWriterPrompt } from '@/lib/prompts/search/writer';
|
import { getWriterPrompt } from '@/lib/prompts/search/writer';
|
||||||
import { WidgetExecutor } from './widgets';
|
import { WidgetExecutor } from './widgets';
|
||||||
import db from '@/lib/db';
|
import db from '@/lib/db';
|
||||||
import { chats, messages } from '@/lib/db/schema';
|
import { messages } from '@/lib/db/schema';
|
||||||
import { and, eq, gt } from 'drizzle-orm';
|
import { and, eq, gt } from 'drizzle-orm';
|
||||||
import { TextBlock } from '@/lib/types';
|
import { TextBlock } from '@/lib/types';
|
||||||
|
import { getTokenCount } from '@/lib/utils/splitText';
|
||||||
|
|
||||||
class SearchAgent {
|
class SearchAgent {
|
||||||
async searchAsync(session: SessionManager, input: SearchAgentInput) {
|
async searchAsync(session: SessionManager, input: SearchAgentInput) {
|
||||||
@@ -98,13 +99,17 @@ class SearchAgent {
|
|||||||
type: 'researchComplete',
|
type: 'researchComplete',
|
||||||
});
|
});
|
||||||
|
|
||||||
const finalContext =
|
let finalContext =
|
||||||
searchResults?.searchFindings
|
'<Query to be answered without searching; Search not made>';
|
||||||
|
|
||||||
|
if (searchResults) {
|
||||||
|
finalContext = searchResults?.searchFindings
|
||||||
.map(
|
.map(
|
||||||
(f, index) =>
|
(f, index) =>
|
||||||
`<result index=${index + 1} title=${f.metadata.title}>${f.content}</result>`,
|
`<result index=${index + 1} title=${f.metadata.title}>${f.content}</result>`,
|
||||||
)
|
)
|
||||||
.join('\n') || '';
|
.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
const widgetContext = widgetOutputs
|
const widgetContext = widgetOutputs
|
||||||
.map((o) => {
|
.map((o) => {
|
||||||
@@ -119,6 +124,7 @@ class SearchAgent {
|
|||||||
input.config.systemInstructions,
|
input.config.systemInstructions,
|
||||||
input.config.mode,
|
input.config.mode,
|
||||||
);
|
);
|
||||||
|
|
||||||
const answerStream = input.config.llm.streamText({
|
const answerStream = input.config.llm.streamText({
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user