Skip to content

Commit

Permalink
fix(anthropic): Do not check for apiKey existence when createClient p…
Browse files Browse the repository at this point in the history
…arameters are present (#6716)

Co-authored-by: Jacob Lee <jacoblee93@gmail.com>
  • Loading branch information
rxliuli and jacoblee93 authored Sep 10, 2024
1 parent e00236d commit 1e1d8d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/core_docs/docs/integrations/chat/anthropic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@
"const customClient = new AnthropicVertex();\n",
"\n",
"const modelWithCustomClient = new ChatAnthropic({\n",
" modelName: \"claude-3-sonnet-20240229\",\n",
" modelName: \"claude-3-sonnet@20240229\",\n",
" maxRetries: 0,\n",
" createClient: () => customClient,\n",
"});\n",
Expand Down
5 changes: 1 addition & 4 deletions libs/langchain-anthropic/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ export class ChatAnthropicMessages<
fields?.anthropicApiKey ??
getEnvironmentVariable("ANTHROPIC_API_KEY");

if (!this.anthropicApiKey) {
if (!this.anthropicApiKey && !fields?.createClient) {
throw new Error("Anthropic API key not found");
}
this.clientOptions = fields?.clientOptions ?? {};
Expand Down Expand Up @@ -949,9 +949,6 @@ export class ChatAnthropicMessages<
): Promise<Anthropic.Message> {
if (!this.batchClient) {
const options = this.apiUrl ? { baseURL: this.apiUrl } : undefined;
if (!this.apiKey) {
throw new Error("Missing Anthropic API key.");
}
this.batchClient = this.createClient({
...this.clientOptions,
...options,
Expand Down

0 comments on commit 1e1d8d1

Please sign in to comment.