feat(search): use single prompt for all focus modes

This commit is contained in:
ItzCrazyKns
2025-09-03 14:37:11 +05:30
parent bb9eab7aa7
commit 536ec24093
8 changed files with 106 additions and 367 deletions

View File

@@ -11,7 +11,7 @@ import {
RunnableMap,
RunnableSequence,
} from '@langchain/core/runnables';
import { BaseMessage } from '@langchain/core/messages';
import { BaseMessage, BaseMessageLike } from '@langchain/core/messages';
import { StringOutputParser } from '@langchain/core/output_parsers';
import LineListOutputParser from '../outputParsers/listLineOutputParser';
import LineOutputParser from '../outputParsers/lineOutputParser';
@@ -40,9 +40,9 @@ export interface MetaSearchAgentType {
interface Config {
searchWeb: boolean;
rerank: boolean;
summarizer: boolean;
rerankThreshold: number;
queryGeneratorPrompt: string;
queryGeneratorFewShots: BaseMessageLike[];
responsePrompt: string;
activeEngines: string[];
}
@@ -64,7 +64,19 @@ class MetaSearchAgent implements MetaSearchAgentType {
(llm as unknown as ChatOpenAI).temperature = 0;
return RunnableSequence.from([
PromptTemplate.fromTemplate(this.config.queryGeneratorPrompt),
ChatPromptTemplate.fromMessages([
['system', this.config.queryGeneratorPrompt],
...this.config.queryGeneratorFewShots,
['user', `
<conversation>
{chat_history}
</conversation>
<query>
{query}
</query>
`]
]),
llm,
this.strParser,
RunnableLambda.from(async (input: string) => {
@@ -75,11 +87,9 @@ class MetaSearchAgent implements MetaSearchAgentType {
const questionOutputParser = new LineOutputParser({
key: 'question',
});
const links = await linksOutputParser.parse(input);
let question = this.config.summarizer
? await questionOutputParser.parse(input)
: input;
let question = await questionOutputParser.parse(input) ?? input;
if (question === 'not_needed') {
return { query: '', docs: [] };