-
Notifications
You must be signed in to change notification settings - Fork 279
fix(integration): fix OpenAI custom tools example in JS #908
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -292,10 +292,10 @@ If you use a model that supports custom tools, you can use the `ChatOpenAI` clas | |||||
|
|
||||||
| ```typescript | ||||||
| import { ChatOpenAI, customTool } from "@langchain/openai"; | ||||||
| import { createAgent } from "@langchain/classic"; | ||||||
| import { createAgent, HumanMessage } from "langchain"; | ||||||
|
|
||||||
| const codeTool = customTool( | ||||||
| async (input) => { | ||||||
| async () => { | ||||||
| // ... Add code to execute the input | ||||||
| return "Code executed successfully"; | ||||||
| }, | ||||||
|
|
@@ -309,11 +309,13 @@ const codeTool = customTool( | |||||
| const model = new ChatOpenAI({ model: "gpt-5" }); | ||||||
|
|
||||||
| const agent = createAgent({ | ||||||
| llm: model, | ||||||
| model, | ||||||
| tools: [codeTool], | ||||||
| }); | ||||||
|
|
||||||
| const result = await agent.invoke("Use the tool to calculate 3^3"); | ||||||
| const result = await agent.invoke({ | ||||||
| messages: [new HumanMessage("Use the tool to execute the code")], | ||||||
| }); | ||||||
| console.log(result); | ||||||
| ``` | ||||||
|
|
||||||
|
|
@@ -324,7 +326,7 @@ OpenAI supports the specification of a [context-free grammar](https://platform.o | |||||
|
|
||||||
| ```typescript | ||||||
| import { ChatOpenAI, customTool } from "@langchain/openai"; | ||||||
| import { createAgent } from "@langchain/classic"; | ||||||
| import { createAgent, HumanMessage } from "langchain"; | ||||||
|
|
||||||
| const MATH_GRAMMAR = ` | ||||||
| start: expr | ||||||
|
|
@@ -340,25 +342,27 @@ MUL: \"*\" | |||||
| `; | ||||||
|
|
||||||
| const doMath = customTool( | ||||||
| async (input) => { | ||||||
| async () => { | ||||||
|
||||||
| async () => { | |
| async (input) => { |
Copilot uses AI. Check for mistakes.
Positive FeedbackNegative Feedback
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The custom tool function signature has been changed to remove the
inputparameter, but the comment on line 299 still references using the input. Either the parameter should be restored or the comment should be updated to match the new signature.Copilot uses AI. Check for mistakes.