Skip to content

Commit

Permalink
Adds docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Sep 4, 2024
1 parent 3233096 commit a2b1ceb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
30 changes: 30 additions & 0 deletions docs/core_docs/docs/integrations/chat/anthropic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,36 @@
"For more on how prompt caching works, see [Anthropic's docs](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#how-prompt-caching-works)."
]
},
{
"cell_type": "markdown",
"id": "f8dece4e",
"metadata": {},
"source": [
"## Custom clients\n",
"\n",
"Anthropic models [may be hosted on cloud services such as Google Vertex](https://docs.anthropic.com/en/api/claude-on-vertex-ai) that rely on a different underlying client with the same interface as the primary Anthropic client. You can access these services by providing a `createClient` method that returns an initialized instance of an Anthropic client. Here's an example:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00ec6d41",
"metadata": {},
"outputs": [],
"source": [
"import { AnthropicVertex } from \"@anthropic-ai/vertex-sdk\";\n",
"\n",
"const customClient = new AnthropicVertex();\n",
"\n",
"const modelWithCustomClient = new ChatAnthropic({\n",
" modelName: \"claude-3-sonnet-20240229\",\n",
" maxRetries: 0,\n",
" createClient: () => customClient,\n",
"});\n",
"\n",
"await modelWithCustomClient.invoke([{ role: \"user\", content: \"Hello!\" }]);"
]
},
{
"cell_type": "markdown",
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3",
Expand Down
1 change: 1 addition & 0 deletions docs/core_docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"validate": "yarn notebook_validate"
},
"dependencies": {
"@anthropic-ai/vertex-sdk": "^0.4.1",
"@docusaurus/core": "2.4.3",
"@docusaurus/preset-classic": "2.4.3",
"@docusaurus/remark-plugin-npm2yarn": "2.4.3",
Expand Down
13 changes: 12 additions & 1 deletion libs/langchain-anthropic/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ export interface AnthropicInput {
*/
streamUsage?: boolean;

createClient?: (options: ClientOptions) => Anthropic;
/**
* Optional method that returns an initialized underlying Anthropic client.
* Useful for accessing Anthropic models hosted on other cloud services
* such as Google Vertex.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
createClient?: (options: ClientOptions) => any;
}

/**
Expand Down Expand Up @@ -613,6 +619,11 @@ export class ChatAnthropicMessages<

streamUsage = true;

/**
* Optional method that returns an initialized underlying Anthropic client.
* Useful for accessing Anthropic models hosted on other cloud services
* such as Google Vertex.
*/
createClient: (options: ClientOptions) => Anthropic;

constructor(fields?: AnthropicInput & BaseChatModelParams) {
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23288,6 +23288,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "core_docs@workspace:docs/core_docs"
dependencies:
"@anthropic-ai/vertex-sdk": ^0.4.1
"@babel/eslint-parser": ^7.18.2
"@docusaurus/core": 2.4.3
"@docusaurus/preset-classic": 2.4.3
Expand Down

0 comments on commit a2b1ceb

Please sign in to comment.