@langchain/anthropic
Advanced tools
Comparing version 0.3.0-rc.0 to 0.3.0
@@ -510,3 +510,2 @@ import { Anthropic, type ClientOptions } from "@anthropic-ai/sdk"; | ||
* @returns {AnthropicTool[] | undefined} The formatted tools, or undefined if none are passed. | ||
* @throws {Error} If a mix of AnthropicTools and StructuredTools are passed. | ||
*/ | ||
@@ -557,4 +556,13 @@ formatStructuredToolToAnthropic(tools: ChatAnthropicCallOptions["tools"]): AnthropicTool[] | undefined; | ||
id: string; | ||
/** Does nucleus sampling, in which we compute the | ||
* cumulative distribution over all the options for each | ||
* subsequent token in decreasing probability order and | ||
* cut it off once it reaches a particular probability | ||
* specified by top_p. Defaults to -1, which disables it. | ||
* Note that you should either alter temperature or top_p, | ||
* but not both. | ||
*/ | ||
model: Anthropic.Messages.Model; | ||
stop_reason: "tool_use" | "stop_sequence" | "end_turn" | "max_tokens" | null; | ||
/** Anthropic API URL */ | ||
stop_sequence: string | null; | ||
@@ -561,0 +569,0 @@ usage: Anthropic.Messages.Usage; |
@@ -553,3 +553,3 @@ import { Anthropic } from "@anthropic-ai/sdk"; | ||
getEnvironmentVariable("ANTHROPIC_API_KEY"); | ||
if (!this.anthropicApiKey) { | ||
if (!this.anthropicApiKey && !fields?.createClient) { | ||
throw new Error("Anthropic API key not found"); | ||
@@ -594,3 +594,2 @@ } | ||
* @returns {AnthropicTool[] | undefined} The formatted tools, or undefined if none are passed. | ||
* @throws {Error} If a mix of AnthropicTools and StructuredTools are passed. | ||
*/ | ||
@@ -601,28 +600,22 @@ formatStructuredToolToAnthropic(tools) { | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
if (tools.every((tool) => isAnthropicTool(tool))) { | ||
// If the tool is already an anthropic tool, return it | ||
return tools; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
if (tools.every((tool) => isOpenAITool(tool))) { | ||
// Formatted as OpenAI tool, convert to Anthropic tool | ||
return tools.map((tc) => ({ | ||
name: tc.function.name, | ||
description: tc.function.description, | ||
input_schema: tc.function.parameters, | ||
})); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
if (tools.some((tool) => isAnthropicTool(tool))) { | ||
throw new Error(`Can not pass in a mix of tool schemas to ChatAnthropic`); | ||
} | ||
if (tools.every(isLangChainTool)) { | ||
return tools.map((t) => ({ | ||
name: t.name, | ||
description: t.description, | ||
input_schema: zodToJsonSchema(t.schema), | ||
})); | ||
} | ||
throw new Error("Unsupported tool type passed to ChatAnthropic"); | ||
return tools.map((tool) => { | ||
if (isAnthropicTool(tool)) { | ||
return tool; | ||
} | ||
if (isOpenAITool(tool)) { | ||
return { | ||
name: tool.function.name, | ||
description: tool.function.description, | ||
input_schema: tool.function.parameters, | ||
}; | ||
} | ||
if (isLangChainTool(tool)) { | ||
return { | ||
name: tool.name, | ||
description: tool.description, | ||
input_schema: zodToJsonSchema(tool.schema), | ||
}; | ||
} | ||
throw new Error(`Unknown tool type passed to ChatAnthropic: ${JSON.stringify(tool, null, 2)}`); | ||
}); | ||
} | ||
@@ -794,5 +787,2 @@ bindTools(tools, kwargs) { | ||
const options = this.apiUrl ? { baseURL: this.apiUrl } : undefined; | ||
if (!this.apiKey) { | ||
throw new Error("Missing Anthropic API key."); | ||
} | ||
this.batchClient = this.createClient({ | ||
@@ -799,0 +789,0 @@ ...this.clientOptions, |
@@ -102,2 +102,3 @@ /** | ||
const contentBlocks = content.map((contentPart) => { | ||
const cacheControl = "cache_control" in contentPart ? contentPart.cache_control : undefined; | ||
if (contentPart.type === "image_url") { | ||
@@ -114,2 +115,3 @@ let source; | ||
source, | ||
...(cacheControl ? { cache_control: cacheControl } : {}), | ||
}; | ||
@@ -123,2 +125,3 @@ } | ||
text: contentPart.text, | ||
...(cacheControl ? { cache_control: cacheControl } : {}), | ||
}; | ||
@@ -149,2 +152,3 @@ } | ||
...contentPartCopy, | ||
...(cacheControl ? { cache_control: cacheControl } : {}), | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -151,0 +155,0 @@ }; |
{ | ||
"name": "@langchain/anthropic", | ||
"version": "0.3.0-rc.0", | ||
"version": "0.3.0", | ||
"description": "Anthropic integrations for LangChain.js", | ||
@@ -44,3 +44,3 @@ "type": "module", | ||
"peerDependencies": { | ||
"@langchain/core": ">=0.2.21 <0.4.0 || 0.3.0-rc.0" | ||
"@langchain/core": ">=0.2.21 <0.4.0" | ||
}, | ||
@@ -47,0 +47,0 @@ "devDependencies": { |
@@ -8,3 +8,3 @@ # @langchain/anthropic | ||
```bash npm2yarn | ||
npm install @langchain/anthropic | ||
npm install @langchain/anthropic @langchain/core | ||
``` | ||
@@ -11,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179856
4699