@ai-sdk/google-vertex 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ai-sdk/google-vertex
2
2
 
3
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b284e2c: feat (provider/google-vertex): support prompt caching for Anthropic Claude models
8
+ - Updated dependencies [e7a9ec9]
9
+ - Updated dependencies [858f934]
10
+ - Updated dependencies [b284e2c]
11
+ - Updated dependencies [0a699f1]
12
+ - @ai-sdk/provider-utils@2.1.1
13
+ - @ai-sdk/anthropic@1.1.1
14
+ - @ai-sdk/provider@1.0.5
15
+ - @ai-sdk/google@1.1.1
16
+
3
17
  ## 2.1.0
4
18
 
5
19
  ### Minor Changes
package/README.md CHANGED
@@ -78,6 +78,60 @@ const { text } = await generateText({
78
78
  });
79
79
  ```
80
80
 
81
+ ## Prompt Caching Support for Anthropic Claude Models
82
+
83
+ The Google Vertex Anthropic provider supports prompt caching for Anthropic Claude models. Prompt caching can help reduce latency and costs by reusing cached results for identical requests. Caches are unique to Google Cloud projects and have a five-minute lifetime.
84
+
85
+ ### Enabling Prompt Caching
86
+
87
+ To enable prompt caching, you can use the `cacheControl` property in the settings. Here is an example demonstrating how to enable prompt caching:
88
+
89
+ ```ts
90
+ import { vertexAnthropic } from '@ai-sdk/google-vertex/anthropic';
91
+ import { generateText } from 'ai';
92
+ import fs from 'node:fs';
93
+
94
+ const errorMessage = fs.readFileSync('data/error-message.txt', 'utf8');
95
+
96
+ async function main() {
97
+ const result = await generateText({
98
+ model: vertexAnthropic('claude-3-5-sonnet-v2@20241022', {
99
+ cacheControl: true,
100
+ }),
101
+ messages: [
102
+ {
103
+ role: 'user',
104
+ content: [
105
+ {
106
+ type: 'text',
107
+ text: 'You are a JavaScript expert.',
108
+ },
109
+ {
110
+ type: 'text',
111
+ text: `Error message: ${errorMessage}`,
112
+ experimental_providerMetadata: {
113
+ anthropic: {
114
+ cacheControl: { type: 'ephemeral' },
115
+ },
116
+ },
117
+ },
118
+ {
119
+ type: 'text',
120
+ text: 'Explain the error message.',
121
+ },
122
+ ],
123
+ },
124
+ ],
125
+ });
126
+
127
+ console.log(result.text);
128
+ console.log(result.experimental_providerMetadata?.anthropic);
129
+ // e.g. { cacheCreationInputTokens: 2118, cacheReadInputTokens: 0 }
130
+ }
131
+
132
+ main().catch(console.error);
133
+ ```
134
+
81
135
  ## Custom Provider Configuration
82
136
 
83
137
  You can create a custom provider instance using the `createVertex` function. This allows you to specify additional configuration options. Below is an example with the default Node.js provider which includes a `googleAuthOptions` object.
@@ -4,7 +4,7 @@ import { AnthropicMessagesSettings, anthropicTools } from '@ai-sdk/anthropic/int
4
4
  import { GoogleAuthOptions } from 'google-auth-library';
5
5
 
6
6
  type GoogleVertexAnthropicMessagesModelId = 'claude-3-5-sonnet-v2@20241022' | 'claude-3-5-haiku@20241022' | 'claude-3-5-sonnet@20240620' | 'claude-3-haiku@20240307' | 'claude-3-sonnet@20240229' | 'claude-3-opus@20240229' | (string & {});
7
- interface GoogleVertexAnthropicMessagesSettings extends Omit<AnthropicMessagesSettings, 'cacheControl'> {
7
+ interface GoogleVertexAnthropicMessagesSettings extends AnthropicMessagesSettings {
8
8
  }
9
9
 
10
10
  interface GoogleVertexAnthropicProvider extends ProviderV1 {
@@ -4,7 +4,7 @@ import { AnthropicMessagesSettings, anthropicTools } from '@ai-sdk/anthropic/int
4
4
  import { GoogleAuthOptions } from 'google-auth-library';
5
5
 
6
6
  type GoogleVertexAnthropicMessagesModelId = 'claude-3-5-sonnet-v2@20241022' | 'claude-3-5-haiku@20241022' | 'claude-3-5-sonnet@20240620' | 'claude-3-haiku@20240307' | 'claude-3-sonnet@20240229' | 'claude-3-opus@20240229' | (string & {});
7
- interface GoogleVertexAnthropicMessagesSettings extends Omit<AnthropicMessagesSettings, 'cacheControl'> {
7
+ interface GoogleVertexAnthropicMessagesSettings extends AnthropicMessagesSettings {
8
8
  }
9
9
 
10
10
  interface GoogleVertexAnthropicProvider extends ProviderV1 {
@@ -21,7 +21,7 @@ interface GoogleCredentials {
21
21
  }
22
22
 
23
23
  type GoogleVertexAnthropicMessagesModelId = 'claude-3-5-sonnet-v2@20241022' | 'claude-3-5-haiku@20241022' | 'claude-3-5-sonnet@20240620' | 'claude-3-haiku@20240307' | 'claude-3-sonnet@20240229' | 'claude-3-opus@20240229' | (string & {});
24
- interface GoogleVertexAnthropicMessagesSettings extends Omit<AnthropicMessagesSettings, 'cacheControl'> {
24
+ interface GoogleVertexAnthropicMessagesSettings extends AnthropicMessagesSettings {
25
25
  }
26
26
 
27
27
  interface GoogleVertexAnthropicProvider extends ProviderV1 {
@@ -21,7 +21,7 @@ interface GoogleCredentials {
21
21
  }
22
22
 
23
23
  type GoogleVertexAnthropicMessagesModelId = 'claude-3-5-sonnet-v2@20241022' | 'claude-3-5-haiku@20241022' | 'claude-3-5-sonnet@20240620' | 'claude-3-haiku@20240307' | 'claude-3-sonnet@20240229' | 'claude-3-opus@20240229' | (string & {});
24
- interface GoogleVertexAnthropicMessagesSettings extends Omit<AnthropicMessagesSettings, 'cacheControl'> {
24
+ interface GoogleVertexAnthropicMessagesSettings extends AnthropicMessagesSettings {
25
25
  }
26
26
 
27
27
  interface GoogleVertexAnthropicProvider extends ProviderV1 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google-vertex",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -37,10 +37,10 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@ai-sdk/anthropic": "1.1.0",
41
- "@ai-sdk/google": "1.1.0",
42
- "@ai-sdk/provider": "1.0.4",
43
- "@ai-sdk/provider-utils": "2.1.0",
40
+ "@ai-sdk/anthropic": "1.1.1",
41
+ "@ai-sdk/google": "1.1.1",
42
+ "@ai-sdk/provider": "1.0.5",
43
+ "@ai-sdk/provider-utils": "2.1.1",
44
44
  "google-auth-library": "^9.15.0"
45
45
  },
46
46
  "devDependencies": {