ai 6.0.322 → 6.0.323

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,13 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.323
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8b1acb6]
8
+ - Updated dependencies [cafcf53]
9
+ - @ai-sdk/gateway@3.0.229
10
+
3
11
  ## 6.0.322
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1335,7 +1335,7 @@ function detectMediaType({
1335
1335
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1336
1336
 
1337
1337
  // src/version.ts
1338
- var VERSION = true ? "6.0.322" : "0.0.0-test";
1338
+ var VERSION = true ? "6.0.323" : "0.0.0-test";
1339
1339
 
1340
1340
  // src/util/download/download.ts
1341
1341
  var download = async ({
package/dist/index.mjs CHANGED
@@ -1225,7 +1225,7 @@ import {
1225
1225
  } from "@ai-sdk/provider-utils";
1226
1226
 
1227
1227
  // src/version.ts
1228
- var VERSION = true ? "6.0.322" : "0.0.0-test";
1228
+ var VERSION = true ? "6.0.323" : "0.0.0-test";
1229
1229
 
1230
1230
  // src/util/download/download.ts
1231
1231
  var download = async ({
@@ -164,7 +164,7 @@ function detectMediaType({
164
164
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
165
165
 
166
166
  // src/version.ts
167
- var VERSION = true ? "6.0.322" : "0.0.0-test";
167
+ var VERSION = true ? "6.0.323" : "0.0.0-test";
168
168
 
169
169
  // src/util/download/download.ts
170
170
  var download = async ({
@@ -144,7 +144,7 @@ import {
144
144
  } from "@ai-sdk/provider-utils";
145
145
 
146
146
  // src/version.ts
147
- var VERSION = true ? "6.0.322" : "0.0.0-test";
147
+ var VERSION = true ? "6.0.323" : "0.0.0-test";
148
148
 
149
149
  // src/util/download/download.ts
150
150
  var download = async ({
@@ -377,6 +377,7 @@ export const yourLogMiddleware: LanguageModelV3Middleware = {
377
377
  ### Caching
378
378
 
379
379
  This example shows how to build a simple cache for the generated text of a language model call.
380
+ The cache key includes the provider, model ID, and call parameters so responses are only reused for the same model and request.
380
381
 
381
382
  ```ts
382
383
  import type { LanguageModelV3Middleware } from '@ai-sdk/provider';
@@ -386,8 +387,12 @@ const cache = new Map<string, any>();
386
387
  export const yourCacheMiddleware: LanguageModelV3Middleware = {
387
388
  specificationVersion: 'v3',
388
389
 
389
- wrapGenerate: async ({ doGenerate, params }) => {
390
- const cacheKey = JSON.stringify(params);
390
+ wrapGenerate: async ({ doGenerate, params, model }) => {
391
+ const cacheKey = JSON.stringify({
392
+ provider: model.provider,
393
+ modelId: model.modelId,
394
+ params,
395
+ });
391
396
 
392
397
  if (cache.has(cacheKey)) {
393
398
  return cache.get(cacheKey);
@@ -14,6 +14,7 @@ and the [`simulateReadableStream`](/docs/reference/ai-sdk-core/simulate-readable
14
14
 
15
15
  Language model middleware is a way to enhance the behavior of language models by intercepting and modifying the calls to the language model.
16
16
  Let's see how you can use language model middleware to cache responses.
17
+ Include the provider and model ID in the cache key alongside the call parameters to keep cached responses separate across models and providers.
17
18
 
18
19
  ```ts filename="ai/middleware.ts"
19
20
  import { Redis } from '@upstash/redis';
@@ -30,8 +31,12 @@ const redis = new Redis({
30
31
  });
31
32
 
32
33
  export const cacheMiddleware: LanguageModelV3Middleware = {
33
- wrapGenerate: async ({ doGenerate, params }) => {
34
- const cacheKey = JSON.stringify(params);
34
+ wrapGenerate: async ({ doGenerate, params, model }) => {
35
+ const cacheKey = JSON.stringify({
36
+ provider: model.provider,
37
+ modelId: model.modelId,
38
+ params,
39
+ });
35
40
 
36
41
  const cached = (await redis.get(cacheKey)) as Awaited<
37
42
  ReturnType<LanguageModelV3['doGenerate']>
@@ -55,8 +60,12 @@ export const cacheMiddleware: LanguageModelV3Middleware = {
55
60
 
56
61
  return result;
57
62
  },
58
- wrapStream: async ({ doStream, params }) => {
59
- const cacheKey = JSON.stringify(params);
63
+ wrapStream: async ({ doStream, params, model }) => {
64
+ const cacheKey = JSON.stringify({
65
+ provider: model.provider,
66
+ modelId: model.modelId,
67
+ params,
68
+ });
60
69
 
61
70
  // Check if the result is in the cache
62
71
  const cached = await redis.get(cacheKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "6.0.322",
3
+ "version": "6.0.323",
4
4
  "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@opentelemetry/api": "^1.9.0",
48
- "@ai-sdk/gateway": "3.0.228",
48
+ "@ai-sdk/gateway": "3.0.229",
49
49
  "@ai-sdk/provider": "3.0.19",
50
50
  "@ai-sdk/provider-utils": "4.0.64"
51
51
  },