refactor: Update Langchain to 0.1.41 & add support for Claude 3 (#8825)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
oleg
2024-03-07 11:36:36 +01:00
committed by GitHub
parent c6f6254c0e
commit 0f7ae3f50a
76 changed files with 908 additions and 451 deletions

View File

@@ -6,9 +6,9 @@ import {
} from 'n8n-workflow';
import { initializeAgentExecutorWithOptions } from 'langchain/agents';
import type { BaseChatMemory } from 'langchain/memory';
import type { BaseOutputParser } from 'langchain/schema/output_parser';
import { PromptTemplate } from 'langchain/prompts';
import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';
import type { BaseOutputParser } from '@langchain/core/output_parsers';
import { PromptTemplate } from '@langchain/core/prompts';
import { CombiningOutputParser } from 'langchain/output_parsers';
import {
isChatInstance,

View File

@@ -7,11 +7,11 @@ import {
import type { AgentExecutorInput } from 'langchain/agents';
import { AgentExecutor, OpenAIAgent } from 'langchain/agents';
import type { BaseOutputParser } from 'langchain/schema/output_parser';
import { PromptTemplate } from 'langchain/prompts';
import type { BaseOutputParser } from '@langchain/core/output_parsers';
import { PromptTemplate } from '@langchain/core/prompts';
import { CombiningOutputParser } from 'langchain/output_parsers';
import { BufferMemory, type BaseChatMemory } from 'langchain/memory';
import { ChatOpenAI } from 'langchain/chat_models/openai';
import { ChatOpenAI } from '@langchain/openai';
import {
getConnectedTools,
getOptionalOutputParsers,

View File

@@ -5,10 +5,10 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import type { BaseOutputParser } from 'langchain/schema/output_parser';
import { PromptTemplate } from 'langchain/prompts';
import type { BaseOutputParser } from '@langchain/core/output_parsers';
import { PromptTemplate } from '@langchain/core/prompts';
import { CombiningOutputParser } from 'langchain/output_parsers';
import type { BaseChatModel } from 'langchain/chat_models/base';
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
import { PlanAndExecuteAgentExecutor } from 'langchain/experimental/plan_and_execute';
import {
getConnectedTools,

View File

@@ -7,10 +7,10 @@ import {
import { AgentExecutor, ChatAgent, ZeroShotAgent } from 'langchain/agents';
import type { BaseLanguageModel } from 'langchain/base_language';
import type { BaseOutputParser } from 'langchain/schema/output_parser';
import { PromptTemplate } from 'langchain/prompts';
import type { BaseOutputParser } from '@langchain/core/output_parsers';
import { PromptTemplate } from '@langchain/core/prompts';
import { CombiningOutputParser } from 'langchain/output_parsers';
import type { BaseChatModel } from 'langchain/chat_models/base';
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
import {
getConnectedTools,
getOptionalOutputParsers,

View File

@@ -3,13 +3,14 @@ import {
type INodeExecutionData,
NodeConnectionType,
NodeOperationError,
type IDataObject,
} from 'n8n-workflow';
import { SqlDatabase } from 'langchain/sql_db';
import type { SqlCreatePromptArgs } from 'langchain/agents/toolkits/sql';
import { SqlToolkit, createSqlAgent } from 'langchain/agents/toolkits/sql';
import type { BaseLanguageModel } from 'langchain/dist/base_language';
import type { BaseChatMemory } from 'langchain/memory';
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';
import type { DataSource } from '@n8n/typeorm';
import { getPromptInputByType, serializeChatHistory } from '../../../../../utils/helpers';
@@ -123,7 +124,7 @@ export async function sqlAgentAgentExecute(
chatHistory = serializeChatHistory(messages);
}
let response;
let response: IDataObject;
try {
response = await agentExecutor.call({
input,
@@ -131,10 +132,10 @@ export async function sqlAgentAgentExecute(
chatHistory,
});
} catch (error) {
if (error.message?.output) {
response = error.message;
if ((error.message as IDataObject)?.output) {
response = error.message as IDataObject;
} else {
throw new NodeOperationError(this.getNode(), error.message, { itemIndex: i });
throw new NodeOperationError(this.getNode(), error.message as string, { itemIndex: i });
}
}

View File

@@ -1,6 +1,6 @@
import { zodToJsonSchema } from 'zod-to-json-schema';
import type { OpenAI as OpenAIClient } from 'openai';
import type { StructuredTool } from 'langchain/tools';
import type { StructuredTool } from '@langchain/core/tools';
// Copied from langchain(`langchain/src/tools/convert_to_openai.ts`)
// since these functions are not exported