feat(agents): replace LLMs with chat LLMs
This commit is contained in:
parent
f9ab543bcf
commit
dd1ce4e324
|
@ -9,7 +9,7 @@ import {
|
||||||
RunnableMap,
|
RunnableMap,
|
||||||
RunnableLambda,
|
RunnableLambda,
|
||||||
} from '@langchain/core/runnables';
|
} from '@langchain/core/runnables';
|
||||||
import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
||||||
import { StringOutputParser } from '@langchain/core/output_parsers';
|
import { StringOutputParser } from '@langchain/core/output_parsers';
|
||||||
import { Document } from '@langchain/core/documents';
|
import { Document } from '@langchain/core/documents';
|
||||||
import { searchSearxng } from '../core/searxng';
|
import { searchSearxng } from '../core/searxng';
|
||||||
|
@ -18,16 +18,11 @@ import formatChatHistoryAsString from '../utils/formatHistory';
|
||||||
import eventEmitter from 'events';
|
import eventEmitter from 'events';
|
||||||
import computeSimilarity from '../utils/computeSimilarity';
|
import computeSimilarity from '../utils/computeSimilarity';
|
||||||
|
|
||||||
const chatLLM = new ChatOpenAI({
|
const llm = new ChatOpenAI({
|
||||||
modelName: process.env.MODEL_NAME,
|
modelName: process.env.MODEL_NAME,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
});
|
});
|
||||||
|
|
||||||
const llm = new OpenAI({
|
|
||||||
temperature: 0,
|
|
||||||
modelName: process.env.MODEL_NAME,
|
|
||||||
});
|
|
||||||
|
|
||||||
const embeddings = new OpenAIEmbeddings({
|
const embeddings = new OpenAIEmbeddings({
|
||||||
modelName: 'text-embedding-3-large',
|
modelName: 'text-embedding-3-large',
|
||||||
});
|
});
|
||||||
|
@ -215,7 +210,7 @@ const basicAcademicSearchAnsweringChain = RunnableSequence.from([
|
||||||
new MessagesPlaceholder('chat_history'),
|
new MessagesPlaceholder('chat_history'),
|
||||||
['user', '{query}'],
|
['user', '{query}'],
|
||||||
]),
|
]),
|
||||||
chatLLM,
|
llm,
|
||||||
strParser,
|
strParser,
|
||||||
]).withConfig({
|
]).withConfig({
|
||||||
runName: 'FinalResponseGenerator',
|
runName: 'FinalResponseGenerator',
|
||||||
|
|
|
@ -4,15 +4,15 @@ import {
|
||||||
RunnableLambda,
|
RunnableLambda,
|
||||||
} from '@langchain/core/runnables';
|
} from '@langchain/core/runnables';
|
||||||
import { PromptTemplate } from '@langchain/core/prompts';
|
import { PromptTemplate } from '@langchain/core/prompts';
|
||||||
import { OpenAI } from '@langchain/openai';
|
import { ChatOpenAI } from '@langchain/openai';
|
||||||
import formatChatHistoryAsString from '../utils/formatHistory';
|
import formatChatHistoryAsString from '../utils/formatHistory';
|
||||||
import { BaseMessage } from '@langchain/core/messages';
|
import { BaseMessage } from '@langchain/core/messages';
|
||||||
import { StringOutputParser } from '@langchain/core/output_parsers';
|
import { StringOutputParser } from '@langchain/core/output_parsers';
|
||||||
import { searchSearxng } from '../core/searxng';
|
import { searchSearxng } from '../core/searxng';
|
||||||
|
|
||||||
const llm = new OpenAI({
|
const llm = new ChatOpenAI({
|
||||||
temperature: 0,
|
|
||||||
modelName: process.env.MODEL_NAME,
|
modelName: process.env.MODEL_NAME,
|
||||||
|
temperature: 0.7,
|
||||||
});
|
});
|
||||||
|
|
||||||
const imageSearchChainPrompt = `
|
const imageSearchChainPrompt = `
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
RunnableMap,
|
RunnableMap,
|
||||||
RunnableLambda,
|
RunnableLambda,
|
||||||
} from '@langchain/core/runnables';
|
} from '@langchain/core/runnables';
|
||||||
import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
||||||
import { StringOutputParser } from '@langchain/core/output_parsers';
|
import { StringOutputParser } from '@langchain/core/output_parsers';
|
||||||
import { Document } from '@langchain/core/documents';
|
import { Document } from '@langchain/core/documents';
|
||||||
import { searchSearxng } from '../core/searxng';
|
import { searchSearxng } from '../core/searxng';
|
||||||
|
@ -18,16 +18,11 @@ import formatChatHistoryAsString from '../utils/formatHistory';
|
||||||
import eventEmitter from 'events';
|
import eventEmitter from 'events';
|
||||||
import computeSimilarity from '../utils/computeSimilarity';
|
import computeSimilarity from '../utils/computeSimilarity';
|
||||||
|
|
||||||
const chatLLM = new ChatOpenAI({
|
const llm = new ChatOpenAI({
|
||||||
modelName: process.env.MODEL_NAME,
|
modelName: process.env.MODEL_NAME,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
});
|
});
|
||||||
|
|
||||||
const llm = new OpenAI({
|
|
||||||
temperature: 0,
|
|
||||||
modelName: process.env.MODEL_NAME,
|
|
||||||
});
|
|
||||||
|
|
||||||
const embeddings = new OpenAIEmbeddings({
|
const embeddings = new OpenAIEmbeddings({
|
||||||
modelName: 'text-embedding-3-large',
|
modelName: 'text-embedding-3-large',
|
||||||
});
|
});
|
||||||
|
@ -211,7 +206,7 @@ const basicRedditSearchAnsweringChain = RunnableSequence.from([
|
||||||
new MessagesPlaceholder('chat_history'),
|
new MessagesPlaceholder('chat_history'),
|
||||||
['user', '{query}'],
|
['user', '{query}'],
|
||||||
]),
|
]),
|
||||||
chatLLM,
|
llm,
|
||||||
strParser,
|
strParser,
|
||||||
]).withConfig({
|
]).withConfig({
|
||||||
runName: 'FinalResponseGenerator',
|
runName: 'FinalResponseGenerator',
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
RunnableMap,
|
RunnableMap,
|
||||||
RunnableLambda,
|
RunnableLambda,
|
||||||
} from '@langchain/core/runnables';
|
} from '@langchain/core/runnables';
|
||||||
import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
||||||
import { StringOutputParser } from '@langchain/core/output_parsers';
|
import { StringOutputParser } from '@langchain/core/output_parsers';
|
||||||
import { Document } from '@langchain/core/documents';
|
import { Document } from '@langchain/core/documents';
|
||||||
import { searchSearxng } from '../core/searxng';
|
import { searchSearxng } from '../core/searxng';
|
||||||
|
@ -18,16 +18,11 @@ import formatChatHistoryAsString from '../utils/formatHistory';
|
||||||
import eventEmitter from 'events';
|
import eventEmitter from 'events';
|
||||||
import computeSimilarity from '../utils/computeSimilarity';
|
import computeSimilarity from '../utils/computeSimilarity';
|
||||||
|
|
||||||
const chatLLM = new ChatOpenAI({
|
const llm = new ChatOpenAI({
|
||||||
modelName: process.env.MODEL_NAME,
|
modelName: process.env.MODEL_NAME,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
});
|
});
|
||||||
|
|
||||||
const llm = new OpenAI({
|
|
||||||
temperature: 0,
|
|
||||||
modelName: process.env.MODEL_NAME,
|
|
||||||
});
|
|
||||||
|
|
||||||
const embeddings = new OpenAIEmbeddings({
|
const embeddings = new OpenAIEmbeddings({
|
||||||
modelName: 'text-embedding-3-large',
|
modelName: 'text-embedding-3-large',
|
||||||
});
|
});
|
||||||
|
@ -210,7 +205,7 @@ const basicWebSearchAnsweringChain = RunnableSequence.from([
|
||||||
new MessagesPlaceholder('chat_history'),
|
new MessagesPlaceholder('chat_history'),
|
||||||
['user', '{query}'],
|
['user', '{query}'],
|
||||||
]),
|
]),
|
||||||
chatLLM,
|
llm,
|
||||||
strParser,
|
strParser,
|
||||||
]).withConfig({
|
]).withConfig({
|
||||||
runName: 'FinalResponseGenerator',
|
runName: 'FinalResponseGenerator',
|
||||||
|
|
|
@ -17,16 +17,11 @@ import type { StreamEvent } from '@langchain/core/tracers/log_stream';
|
||||||
import formatChatHistoryAsString from '../utils/formatHistory';
|
import formatChatHistoryAsString from '../utils/formatHistory';
|
||||||
import eventEmitter from 'events';
|
import eventEmitter from 'events';
|
||||||
|
|
||||||
const chatLLM = new ChatOpenAI({
|
const llm = new ChatOpenAI({
|
||||||
modelName: process.env.MODEL_NAME,
|
modelName: process.env.MODEL_NAME,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
});
|
});
|
||||||
|
|
||||||
const llm = new OpenAI({
|
|
||||||
temperature: 0,
|
|
||||||
modelName: process.env.MODEL_NAME,
|
|
||||||
});
|
|
||||||
|
|
||||||
const basicWolframAlphaSearchRetrieverPrompt = `
|
const basicWolframAlphaSearchRetrieverPrompt = `
|
||||||
You will be given a conversation below and a follow up question. You need to rephrase the follow-up question if needed so it is a standalone question that can be used by the LLM to search the web for information.
|
You will be given a conversation below and a follow up question. You need to rephrase the follow-up question if needed so it is a standalone question that can be used by the LLM to search the web for information.
|
||||||
If it is a writing task or a simple hi, hello rather than a question, you need to return \`not_needed\` as the response.
|
If it is a writing task or a simple hi, hello rather than a question, you need to return \`not_needed\` as the response.
|
||||||
|
@ -169,7 +164,7 @@ const basicWolframAlphaSearchAnsweringChain = RunnableSequence.from([
|
||||||
new MessagesPlaceholder('chat_history'),
|
new MessagesPlaceholder('chat_history'),
|
||||||
['user', '{query}'],
|
['user', '{query}'],
|
||||||
]),
|
]),
|
||||||
chatLLM,
|
llm,
|
||||||
strParser,
|
strParser,
|
||||||
]).withConfig({
|
]).withConfig({
|
||||||
runName: 'FinalResponseGenerator',
|
runName: 'FinalResponseGenerator',
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { StringOutputParser } from '@langchain/core/output_parsers';
|
||||||
import type { StreamEvent } from '@langchain/core/tracers/log_stream';
|
import type { StreamEvent } from '@langchain/core/tracers/log_stream';
|
||||||
import eventEmitter from 'events';
|
import eventEmitter from 'events';
|
||||||
|
|
||||||
const chatLLM = new ChatOpenAI({
|
const llm = new ChatOpenAI({
|
||||||
modelName: process.env.MODEL_NAME,
|
modelName: process.env.MODEL_NAME,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
});
|
});
|
||||||
|
@ -50,7 +50,7 @@ const writingAssistantChain = RunnableSequence.from([
|
||||||
new MessagesPlaceholder('chat_history'),
|
new MessagesPlaceholder('chat_history'),
|
||||||
['user', '{query}'],
|
['user', '{query}'],
|
||||||
]),
|
]),
|
||||||
chatLLM,
|
llm,
|
||||||
strParser,
|
strParser,
|
||||||
]).withConfig({
|
]).withConfig({
|
||||||
runName: 'FinalResponseGenerator',
|
runName: 'FinalResponseGenerator',
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
RunnableMap,
|
RunnableMap,
|
||||||
RunnableLambda,
|
RunnableLambda,
|
||||||
} from '@langchain/core/runnables';
|
} from '@langchain/core/runnables';
|
||||||
import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
||||||
import { StringOutputParser } from '@langchain/core/output_parsers';
|
import { StringOutputParser } from '@langchain/core/output_parsers';
|
||||||
import { Document } from '@langchain/core/documents';
|
import { Document } from '@langchain/core/documents';
|
||||||
import { searchSearxng } from '../core/searxng';
|
import { searchSearxng } from '../core/searxng';
|
||||||
|
@ -18,16 +18,11 @@ import formatChatHistoryAsString from '../utils/formatHistory';
|
||||||
import eventEmitter from 'events';
|
import eventEmitter from 'events';
|
||||||
import computeSimilarity from '../utils/computeSimilarity';
|
import computeSimilarity from '../utils/computeSimilarity';
|
||||||
|
|
||||||
const chatLLM = new ChatOpenAI({
|
const llm = new ChatOpenAI({
|
||||||
modelName: process.env.MODEL_NAME,
|
modelName: process.env.MODEL_NAME,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
});
|
});
|
||||||
|
|
||||||
const llm = new OpenAI({
|
|
||||||
temperature: 0,
|
|
||||||
modelName: process.env.MODEL_NAME,
|
|
||||||
});
|
|
||||||
|
|
||||||
const embeddings = new OpenAIEmbeddings({
|
const embeddings = new OpenAIEmbeddings({
|
||||||
modelName: 'text-embedding-3-large',
|
modelName: 'text-embedding-3-large',
|
||||||
});
|
});
|
||||||
|
@ -211,7 +206,7 @@ const basicYoutubeSearchAnsweringChain = RunnableSequence.from([
|
||||||
new MessagesPlaceholder('chat_history'),
|
new MessagesPlaceholder('chat_history'),
|
||||||
['user', '{query}'],
|
['user', '{query}'],
|
||||||
]),
|
]),
|
||||||
chatLLM,
|
llm,
|
||||||
strParser,
|
strParser,
|
||||||
]).withConfig({
|
]).withConfig({
|
||||||
runName: 'FinalResponseGenerator',
|
runName: 'FinalResponseGenerator',
|
||||||
|
|
Loading…
Reference in New Issue