From 8b3be83703dd7c16d01590f59990064b021148f1 Mon Sep 17 00:00:00 2001 From: ucev Date: Sun, 12 Jan 2025 11:28:47 +0800 Subject: [PATCH] feat: update google_calendar params type, BaseLLM -> BaseChatModel --- examples/src/tools/google_calendar.ts | 16 ++++++---------- .../src/tools/google_calendar/base.ts | 6 +++--- .../commands/run-create-events.ts | 4 ++-- .../google_calendar/commands/run-view-events.ts | 4 ++-- .../src/tools/tests/google_calendar.test.ts | 8 ++++---- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/examples/src/tools/google_calendar.ts b/examples/src/tools/google_calendar.ts index 293f1551b8cc..e36b5f414389 100644 --- a/examples/src/tools/google_calendar.ts +++ b/examples/src/tools/google_calendar.ts @@ -1,6 +1,6 @@ -import { AgentExecutor, createOpenAIToolsAgent } from "langchain/agents"; +import { AgentExecutor, createReactAgent } from "langchain/agents"; import { pull } from "langchain/hub"; -import { OpenAI, ChatOpenAI } from "@langchain/openai"; +import { ChatOpenAI } from "@langchain/openai"; import { Calculator } from "@langchain/community/tools/calculator"; import { GoogleCalendarCreateTool, @@ -9,7 +9,7 @@ import { import { ChatPromptTemplate } from "@langchain/core/prompts"; export async function run() { - const model = new OpenAI({ + const model = new ChatOpenAI({ temperature: 0, apiKey: process.env.OPENAI_API_KEY, }); @@ -33,13 +33,9 @@ export async function run() { new GoogleCalendarViewTool(googleCalendarParams), ]; - const llm = new ChatOpenAI({ - temperature: 0, - apiKey: process.env.OPENAI_API_KEY, - }); - const prompt: ChatPromptTemplate = await pull("hwchase17/openai-tools-agent"); - const calendarAgent = await createOpenAIToolsAgent({ - llm, + const prompt: ChatPromptTemplate = await pull("hwchase17/react"); + const calendarAgent = await createReactAgent({ + llm: model, tools, prompt, }); diff --git a/libs/langchain-community/src/tools/google_calendar/base.ts b/libs/langchain-community/src/tools/google_calendar/base.ts index 1f8916e4c2ab..9da0c8f1b487 100644 --- a/libs/langchain-community/src/tools/google_calendar/base.ts +++ b/libs/langchain-community/src/tools/google_calendar/base.ts @@ -1,7 +1,7 @@ import { google } from "googleapis"; import { Tool } from "@langchain/core/tools"; import { getEnvironmentVariable } from "@langchain/core/utils/env"; -import { BaseLLM } from "@langchain/core/language_models/llms"; +import { BaseChatModel } from "@langchain/core/language_models/chat_models"; export interface GoogleCalendarAgentParams { credentials?: { @@ -10,7 +10,7 @@ export interface GoogleCalendarAgentParams { calendarId?: string; }; scopes?: string[]; - model?: BaseLLM; + model?: BaseChatModel; } export class GoogleCalendarBase extends Tool { @@ -27,7 +27,7 @@ export class GoogleCalendarBase extends Tool { protected scopes: string[]; - protected llm: BaseLLM; + protected llm: BaseChatModel; constructor( fields: GoogleCalendarAgentParams = { diff --git a/libs/langchain-community/src/tools/google_calendar/commands/run-create-events.ts b/libs/langchain-community/src/tools/google_calendar/commands/run-create-events.ts index 8ec8e46bdc08..6abcd9a792b9 100644 --- a/libs/langchain-community/src/tools/google_calendar/commands/run-create-events.ts +++ b/libs/langchain-community/src/tools/google_calendar/commands/run-create-events.ts @@ -2,7 +2,7 @@ import { google, calendar_v3 } from "googleapis"; import type { JWT, GaxiosResponse } from "googleapis-common"; import { PromptTemplate } from "@langchain/core/prompts"; import { CallbackManagerForToolRun } from "@langchain/core/callbacks/manager"; -import { BaseLLM } from "@langchain/core/language_models/llms"; +import { BaseChatModel } from "@langchain/core/language_models/chat_models"; import { StringOutputParser } from "@langchain/core/output_parsers"; import { CREATE_EVENT_PROMPT } from "../prompts/index.js"; import { getTimezoneOffsetInHours } from "../utils/get-timezone-offset-in-hours.js"; @@ -61,7 +61,7 @@ const createEvent = async ( type RunCreateEventParams = { calendarId: string; auth: JWT; - model: BaseLLM; + model: BaseChatModel; }; const runCreateEvent = async ( diff --git a/libs/langchain-community/src/tools/google_calendar/commands/run-view-events.ts b/libs/langchain-community/src/tools/google_calendar/commands/run-view-events.ts index 1cc721535916..731f9cad162c 100644 --- a/libs/langchain-community/src/tools/google_calendar/commands/run-view-events.ts +++ b/libs/langchain-community/src/tools/google_calendar/commands/run-view-events.ts @@ -1,7 +1,7 @@ import { calendar_v3 } from "googleapis"; import type { JWT } from "googleapis-common"; import { PromptTemplate } from "@langchain/core/prompts"; -import { BaseLLM } from "@langchain/core/language_models/llms"; +import { BaseChatModel } from "@langchain/core/language_models/chat_models"; import { CallbackManagerForToolRun } from "@langchain/core/callbacks/manager"; import { StringOutputParser } from "@langchain/core/output_parsers"; @@ -11,7 +11,7 @@ import { getTimezoneOffsetInHours } from "../utils/get-timezone-offset-in-hours. type RunViewEventParams = { calendarId: string; auth: JWT; - model: BaseLLM; + model: BaseChatModel; }; const runViewEvents = async ( diff --git a/libs/langchain-community/src/tools/tests/google_calendar.test.ts b/libs/langchain-community/src/tools/tests/google_calendar.test.ts index f777ae8999a2..10531cc72991 100644 --- a/libs/langchain-community/src/tools/tests/google_calendar.test.ts +++ b/libs/langchain-community/src/tools/tests/google_calendar.test.ts @@ -1,5 +1,5 @@ import { jest, expect, describe } from "@jest/globals"; -import { LLM } from "@langchain/core/language_models/llms"; +import { BaseChatModel } from "@langchain/core/language_models/chat_models"; import { GoogleCalendarCreateTool, GoogleCalendarViewTool, @@ -25,13 +25,13 @@ jest.mock("@langchain/core/utils/env", () => ({ // runViewEvents: jest.fn(), // })); -class FakeLLM extends LLM { +class FakeLLM extends BaseChatModel { _llmType() { return "fake"; } - async _call(prompt: string): Promise { - return prompt; + async _generate() { + return {} as any; } }