Skip to content

Commit

Permalink
docs: Resolves #7483, resolves #7274 (#7505)
Browse files Browse the repository at this point in the history
Co-authored-by: jacoblee93 <[email protected]>
  • Loading branch information
ucev and jacoblee93 authored Jan 18, 2025
1 parent 9314ef1 commit e1c8212
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/core_docs/docs/integrations/tools/google_calendar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import IntegrationInstallTooltip from "@mdx_components/integration_install_toolt
<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/openai @langchain/core
npm install @langchain/openai @langchain/core @langchain/community @langchain/langgraph
```

<CodeBlock language="typescript">{ToolExample}</CodeBlock>
Expand Down
21 changes: 13 additions & 8 deletions examples/src/tools/google_calendar.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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,
GoogleCalendarViewTool,
} 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 = {
Expand All @@ -31,22 +32,26 @@ 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.'
// }
console.log("Create Result", createResult);

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."
// }
Expand Down
6 changes: 3 additions & 3 deletions libs/langchain-community/src/tools/google_calendar/base.ts
Original file line number Diff line number Diff line change
@@ -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?: {
Expand All @@ -10,7 +10,7 @@ export interface GoogleCalendarAgentParams {
calendarId?: string;
};
scopes?: string[];
model?: BaseLLM;
model?: BaseLanguageModel;
}

export class GoogleCalendarBase extends Tool {
Expand All @@ -27,7 +27,7 @@ export class GoogleCalendarBase extends Tool {

protected scopes: string[];

protected llm: BaseLLM;
protected llm: BaseLanguageModel;

constructor(
fields: GoogleCalendarAgentParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -61,7 +61,7 @@ const createEvent = async (
type RunCreateEventParams = {
calendarId: string;
auth: JWT;
model: BaseLLM;
model: BaseLanguageModel;
};

const runCreateEvent = async (
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<string> {
return prompt;
async _generate() {
return {} as any;
}
}

Expand Down

0 comments on commit e1c8212

Please sign in to comment.