-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Resolves #7483, resolves #7274 #7505
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { initializeAgentExecutorWithOptions } from "langchain/agents"; | ||
import { OpenAI } from "@langchain/openai"; | ||
import { AgentExecutor, createOpenAIToolsAgent } from "langchain/agents"; | ||
import { pull } from "langchain/hub"; | ||
import { OpenAI, ChatOpenAI } from "@langchain/openai"; | ||
import { Calculator } from "@langchain/community/tools/calculator"; | ||
import { | ||
GoogleCalendarCreateTool, | ||
GoogleCalendarViewTool, | ||
} from "@langchain/community/tools/google_calendar"; | ||
import { ChatPromptTemplate } from "@langchain/core/prompts"; | ||
|
||
export async function run() { | ||
const model = new OpenAI({ | ||
|
@@ -31,22 +33,32 @@ export async function run() { | |
new GoogleCalendarViewTool(googleCalendarParams), | ||
]; | ||
|
||
const calendarAgent = await initializeAgentExecutorWithOptions(tools, model, { | ||
agentType: "zero-shot-react-description", | ||
verbose: true, | ||
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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would still prefer to use it and add install instructions as it's the latest and what people should be using long term. Can make modifications myself too. |
||
llm, | ||
tools, | ||
prompt, | ||
}); | ||
const agentExecutor = new AgentExecutor({ | ||
agent: calendarAgent, | ||
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 agentExecutor.invoke({ input: 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 agentExecutor.invoke({ input: viewInput }); | ||
// View Result { | ||
// output: "You have no meetings this week between 8am and 8pm." | ||
// } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
ChatOpenAI
withmodel: "gpt-4o-mini"
for everything,OpenAI
completions models are deprecatedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Cuz
ChatOpenAI
inheritsBaseChatModel
, notBaseLLM
, I also update google_calendar type definitions.