-
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
cohere[minor]: Add support for tool calling cohere #5810
Merged
jacoblee93
merged 15 commits into
langchain-ai:main
from
Anirudh31415926535:anirudh/support-tool-calling-cohere
Jul 9, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
36f86ea
feat: Add support for tool calling cohere
Anirudh31415926535 6de2f8e
fix: lint errors + minor fixes
Anirudh31415926535 8d98b04
fix: apply format and lint, revert some unexpected changes to json files
Anirudh31415926535 2442d5a
Update tsconfig.json
Anirudh31415926535 100e7ef
Remove added deps from package json file
Anirudh31415926535 1f7f7e1
nit: Fix typo
Anirudh31415926535 bb5d9a3
address PR comments
Anirudh31415926535 77d3f46
make methods private
Anirudh31415926535 834addc
Merge branch 'main' into anirudh/support-tool-calling-cohere
Anirudh31415926535 827cfc0
update yarn lock
Anirudh31415926535 f7debe4
nit
Anirudh31415926535 457d6fa
Merge branch 'main' of https://github.com/hwchase17/langchainjs into …
jacoblee93 3ff35b8
Lint, support OpenAI tool schemas
jacoblee93 41c8210
Fix and enable standard tool calling tests
jacoblee93 aa82799
Bump lower-bound dep
jacoblee93 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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ChatCohere } from "@langchain/cohere"; | ||
import { HumanMessage } from "@langchain/core/messages"; | ||
import { z } from "zod"; | ||
import { DynamicStructuredTool } from "@langchain/core/tools"; | ||
|
||
const model = new ChatCohere({ | ||
apiKey: process.env.COHERE_API_KEY, // Default | ||
}); | ||
|
||
const magicFunctionTool = new DynamicStructuredTool({ | ||
name: "magic_function", | ||
description: "Apply a magic function to the input number", | ||
schema: z.object({ | ||
num: z.number().describe("The number to apply the magic function for"), | ||
}), | ||
func: async ({ num }) => { | ||
return `The magic function of ${num} is ${num + 5}`; | ||
}, | ||
}); | ||
|
||
const tools = [magicFunctionTool]; | ||
const modelWithTools = model.bindTools(tools); | ||
|
||
const messages = [new HumanMessage("What is the magic function of number 5?")]; | ||
const response = await modelWithTools.invoke(messages); | ||
/* | ||
AIMessage { | ||
content: 'I will use the magic_function tool to answer this question.', | ||
name: undefined, | ||
additional_kwargs: { | ||
response_id: 'd0b189e5-3dbf-493c-93f8-99ed4b01d96d', | ||
generationId: '8982a68f-c64c-48f8-bf12-0b4bea0018b6', | ||
chatHistory: [ [Object], [Object] ], | ||
finishReason: 'COMPLETE', | ||
meta: { apiVersion: [Object], billedUnits: [Object], tokens: [Object] }, | ||
toolCalls: [ [Object] ] | ||
}, | ||
response_metadata: { | ||
estimatedTokenUsage: { completionTokens: 54, promptTokens: 920, totalTokens: 974 }, | ||
response_id: 'd0b189e5-3dbf-493c-93f8-99ed4b01d96d', | ||
generationId: '8982a68f-c64c-48f8-bf12-0b4bea0018b6', | ||
chatHistory: [ [Object], [Object] ], | ||
finishReason: 'COMPLETE', | ||
meta: { apiVersion: [Object], billedUnits: [Object], tokens: [Object] }, | ||
toolCalls: [ [Object] ] | ||
}, | ||
tool_calls: [ | ||
{ | ||
name: 'magic_function', | ||
args: [Object], | ||
id: '4ec98550-ba9a-4043-adfe-566230e5' | ||
} | ||
], | ||
invalid_tool_calls: [], | ||
usage_metadata: { input_tokens: 920, output_tokens: 54, total_tokens: 974 } | ||
} | ||
*/ |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -35,8 +35,11 @@ | |
"author": "LangChain", | ||
"license": "MIT", | ||
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. Hey there! I noticed that a new dependency "zod" has been added to the "dependencies" section, which is a change in the project's dependencies. This comment is to flag the change for maintainers to review. Great work! |
||
"dependencies": { | ||
"@langchain/core": ">=0.2.5 <0.3.0", | ||
"cohere-ai": "^7.10.5" | ||
"@langchain/core": ">=0.2.14 <0.3.0", | ||
"cohere-ai": "^7.10.5", | ||
"uuid": "^10.0.0", | ||
"zod": "^3.23.8", | ||
"zod-to-json-schema": "^3.23.1" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.5.0", | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
Hey there! 👋 This is a friendly flag to highlight that the recent code change explicitly accesses an environment variable using
process.env
. This is an important point for maintainers to review. Keep up the great work! 🚀