ai 2.1.20 → 2.1.22

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/dist/index.js CHANGED
@@ -178,20 +178,23 @@ function createEmptyReadableStream() {
178
178
  // streams/openai-stream.ts
179
179
  function parseOpenAIStream() {
180
180
  const trimStartOfStream = trimStartOfStreamHelper();
181
+ let isFunctionStreamingIn;
181
182
  return (data) => {
182
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
183
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
183
184
  const json = JSON.parse(data);
184
185
  if ((_c = (_b = (_a = json.choices[0]) == null ? void 0 : _a.delta) == null ? void 0 : _b.function_call) == null ? void 0 : _c.name) {
186
+ isFunctionStreamingIn = true;
185
187
  return `{"function_call": {"name": "${(_e = (_d = json.choices[0]) == null ? void 0 : _d.delta) == null ? void 0 : _e.function_call.name}", "arguments": "`;
186
188
  } else if ((_h = (_g = (_f = json.choices[0]) == null ? void 0 : _f.delta) == null ? void 0 : _g.function_call) == null ? void 0 : _h.arguments) {
187
189
  const argumentChunk = json.choices[0].delta.function_call.arguments;
188
190
  let escapedPartialJson = argumentChunk.replace(/\\/g, "\\\\").replace(/\//g, "\\/").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/\f/g, "\\f");
189
191
  return `${escapedPartialJson}`;
190
- } else if (((_i = json.choices[0]) == null ? void 0 : _i.finish_reason) === "function_call") {
192
+ } else if ((((_i = json.choices[0]) == null ? void 0 : _i.finish_reason) === "function_call" || ((_j = json.choices[0]) == null ? void 0 : _j.finish_reason) === "stop") && isFunctionStreamingIn) {
193
+ isFunctionStreamingIn = false;
191
194
  return '"}}';
192
195
  }
193
196
  const text = trimStartOfStream(
194
- (_n = (_m = (_k = (_j = json.choices[0]) == null ? void 0 : _j.delta) == null ? void 0 : _k.content) != null ? _m : (_l = json.choices[0]) == null ? void 0 : _l.text) != null ? _n : ""
197
+ (_o = (_n = (_l = (_k = json.choices[0]) == null ? void 0 : _k.delta) == null ? void 0 : _l.content) != null ? _n : (_m = json.choices[0]) == null ? void 0 : _m.text) != null ? _o : ""
195
198
  );
196
199
  return text;
197
200
  };
@@ -334,7 +337,7 @@ function createParser2(res) {
334
337
  controller.close();
335
338
  return;
336
339
  }
337
- if (text === "</s>" || text === "<|endoftext|>") {
340
+ if (text === "</s>" || text === "<|endoftext|>" || text === "<|end|>") {
338
341
  controller.close();
339
342
  } else {
340
343
  controller.enqueue(text);
package/dist/index.mjs CHANGED
@@ -145,20 +145,23 @@ function createEmptyReadableStream() {
145
145
  // streams/openai-stream.ts
146
146
  function parseOpenAIStream() {
147
147
  const trimStartOfStream = trimStartOfStreamHelper();
148
+ let isFunctionStreamingIn;
148
149
  return (data) => {
149
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
150
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
150
151
  const json = JSON.parse(data);
151
152
  if ((_c = (_b = (_a = json.choices[0]) == null ? void 0 : _a.delta) == null ? void 0 : _b.function_call) == null ? void 0 : _c.name) {
153
+ isFunctionStreamingIn = true;
152
154
  return `{"function_call": {"name": "${(_e = (_d = json.choices[0]) == null ? void 0 : _d.delta) == null ? void 0 : _e.function_call.name}", "arguments": "`;
153
155
  } else if ((_h = (_g = (_f = json.choices[0]) == null ? void 0 : _f.delta) == null ? void 0 : _g.function_call) == null ? void 0 : _h.arguments) {
154
156
  const argumentChunk = json.choices[0].delta.function_call.arguments;
155
157
  let escapedPartialJson = argumentChunk.replace(/\\/g, "\\\\").replace(/\//g, "\\/").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/\f/g, "\\f");
156
158
  return `${escapedPartialJson}`;
157
- } else if (((_i = json.choices[0]) == null ? void 0 : _i.finish_reason) === "function_call") {
159
+ } else if ((((_i = json.choices[0]) == null ? void 0 : _i.finish_reason) === "function_call" || ((_j = json.choices[0]) == null ? void 0 : _j.finish_reason) === "stop") && isFunctionStreamingIn) {
160
+ isFunctionStreamingIn = false;
158
161
  return '"}}';
159
162
  }
160
163
  const text = trimStartOfStream(
161
- (_n = (_m = (_k = (_j = json.choices[0]) == null ? void 0 : _j.delta) == null ? void 0 : _k.content) != null ? _m : (_l = json.choices[0]) == null ? void 0 : _l.text) != null ? _n : ""
164
+ (_o = (_n = (_l = (_k = json.choices[0]) == null ? void 0 : _k.delta) == null ? void 0 : _l.content) != null ? _n : (_m = json.choices[0]) == null ? void 0 : _m.text) != null ? _o : ""
162
165
  );
163
166
  return text;
164
167
  };
@@ -301,7 +304,7 @@ function createParser2(res) {
301
304
  controller.close();
302
305
  return;
303
306
  }
304
- if (text === "</s>" || text === "<|endoftext|>") {
307
+ if (text === "</s>" || text === "<|endoftext|>" || text === "<|end|>") {
305
308
  controller.close();
306
309
  } else {
307
310
  controller.enqueue(text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "2.1.20",
3
+ "version": "2.1.22",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -20,6 +20,12 @@
20
20
  "module": "./dist/index.mjs",
21
21
  "require": "./dist/index.js"
22
22
  },
23
+ "./prompts": {
24
+ "types": "./prompts/dist/index.d.ts",
25
+ "import": "./prompts/dist/index.mjs",
26
+ "module": "./prompts/dist/index.mjs",
27
+ "require": "./prompts/dist/index.js"
28
+ },
23
29
  "./react": {
24
30
  "types": "./react/dist/index.d.ts",
25
31
  "react-server": "./react/dist/index.server.mjs",
@@ -88,6 +94,21 @@
88
94
  "publishConfig": {
89
95
  "access": "public"
90
96
  },
97
+ "homepage": "https://github.com/vercel-labs/ai#readme",
98
+ "repository": {
99
+ "type": "git",
100
+ "url": "git+https://github.com/vercel-labs/ai.git"
101
+ },
102
+ "bugs": {
103
+ "url": "https://github.com/vercel-labs/ai/issues"
104
+ },
105
+ "keywords": [
106
+ "ai",
107
+ "nextjs",
108
+ "svelte",
109
+ "react",
110
+ "vue"
111
+ ],
91
112
  "scripts": {
92
113
  "build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
93
114
  "clean": "rm -rf dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist",