From e1c82127ad3ff381e4b68f867cf0dc2caad73ee5 Mon Sep 17 00:00:00 2001 From: ucev Date: Sat, 18 Jan 2025 15:52:52 +0800 Subject: [PATCH] docs: Resolves #7483, resolves #7274 (#7505) Co-authored-by: jacoblee93 --- .../integrations/tools/google_calendar.mdx | 2 +- examples/src/tools/google_calendar.ts | 21 ++++++++++++------- .../src/tools/google_calendar/base.ts | 6 +++--- .../commands/run-create-events.ts | 4 ++-- .../commands/run-view-events.ts | 4 ++-- .../src/tools/tests/google_calendar.test.ts | 8 +++---- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/docs/core_docs/docs/integrations/tools/google_calendar.mdx b/docs/core_docs/docs/integrations/tools/google_calendar.mdx index 14cfa036c75f..c1ba5b19bc12 100644 --- a/docs/core_docs/docs/integrations/tools/google_calendar.mdx +++ b/docs/core_docs/docs/integrations/tools/google_calendar.mdx @@ -25,7 +25,7 @@ import IntegrationInstallTooltip from "@mdx_components/integration_install_toolt ```bash npm2yarn -npm install @langchain/openai @langchain/core +npm install @langchain/openai @langchain/core @langchain/community @langchain/langgraph ``` {ToolExample} diff --git a/examples/src/tools/google_calendar.ts b/examples/src/tools/google_calendar.ts index 6dee71adca24..948af910c161 100644 --- a/examples/src/tools/google_calendar.ts +++ b/examples/src/tools/google_calendar.ts @@ -1,5 +1,5 @@ -import { initializeAgentExecutorWithOptions } from "langchain/agents"; -import { OpenAI } from "@langchain/openai"; +import { createReactAgent } from "@langchain/langgraph/prebuilt"; +import { ChatOpenAI } from "@langchain/openai"; import { Calculator } from "@langchain/community/tools/calculator"; import { GoogleCalendarCreateTool, @@ -7,9 +7,10 @@ import { } from "@langchain/community/tools/google_calendar"; export async function run() { - const model = new OpenAI({ + const model = new ChatOpenAI({ temperature: 0, apiKey: process.env.OPENAI_API_KEY, + model: "gpt-4o-mini", }); const googleCalendarParams = { @@ -31,14 +32,16 @@ export async function run() { new GoogleCalendarViewTool(googleCalendarParams), ]; - const calendarAgent = await initializeAgentExecutorWithOptions(tools, model, { - agentType: "zero-shot-react-description", - verbose: true, + const calendarAgent = createReactAgent({ + llm: model, + tools, }); const createInput = `Create a meeting with John Doe next Friday at 4pm - adding to the agenda of it the result of 99 + 99`; - const createResult = await calendarAgent.invoke({ input: createInput }); + const createResult = await calendarAgent.invoke({ + messages: [{ role: "user", content: createInput }], + }); // Create Result { // output: 'A meeting with John Doe on 29th September at 4pm has been created and the result of 99 + 99 has been added to the agenda.' // } @@ -46,7 +49,9 @@ export async function run() { const viewInput = `What meetings do I have this week?`; - const viewResult = await calendarAgent.invoke({ input: viewInput }); + const viewResult = await calendarAgent.invoke({ + messages: [{ role: "user", content: viewInput }], + }); // View Result { // output: "You have no meetings this week between 8am and 8pm." // } diff --git a/libs/langchain-community/src/tools/google_calendar/base.ts b/libs/langchain-community/src/tools/google_calendar/base.ts index 1f8916e4c2ab..f1962091acf9 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 { BaseLanguageModel } from "@langchain/core/language_models/base"; export interface GoogleCalendarAgentParams { credentials?: { @@ -10,7 +10,7 @@ export interface GoogleCalendarAgentParams { calendarId?: string; }; scopes?: string[]; - model?: BaseLLM; + model?: BaseLanguageModel; } export class GoogleCalendarBase extends Tool { @@ -27,7 +27,7 @@ export class GoogleCalendarBase extends Tool { protected scopes: string[]; - protected llm: BaseLLM; + protected llm: BaseLanguageModel; 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..2eea293ab68c 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 { BaseLanguageModel } from "@langchain/core/language_models/base"; 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: BaseLanguageModel; }; 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..52767d80bff9 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 { BaseLanguageModel } from "@langchain/core/language_models/base"; 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: BaseLanguageModel; }; 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; } }