Skip to content

Commit

Permalink
feat: update google_calendar params type, BaseLLM -> BaseChatModel
Browse files Browse the repository at this point in the history
  • Loading branch information
ucev committed Jan 12, 2025
1 parent f94be5f commit 8b3be83
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
16 changes: 6 additions & 10 deletions examples/src/tools/google_calendar.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
});
Expand All @@ -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,
});
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 { BaseChatModel } from "@langchain/core/language_models/chat_models";

export interface GoogleCalendarAgentParams {
credentials?: {
Expand All @@ -10,7 +10,7 @@ export interface GoogleCalendarAgentParams {
calendarId?: string;
};
scopes?: string[];
model?: BaseLLM;
model?: BaseChatModel;
}

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

protected scopes: string[];

protected llm: BaseLLM;
protected llm: BaseChatModel;

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 { 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";
Expand Down Expand Up @@ -61,7 +61,7 @@ const createEvent = async (
type RunCreateEventParams = {
calendarId: string;
auth: JWT;
model: BaseLLM;
model: BaseChatModel;
};

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 { BaseChatModel } from "@langchain/core/language_models/chat_models";
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: BaseChatModel;
};

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 8b3be83

Please sign in to comment.