ai 2.1.21 → 2.1.23
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.d.ts +3 -3
- package/dist/index.js +6 -2
- package/dist/index.mjs +6 -2
- package/package.json +24 -2
- package/prompts/dist/index.d.ts +37 -0
- package/prompts/dist/index.js +65 -0
- package/prompts/dist/index.mjs +37 -0
package/dist/index.d.ts
CHANGED
@@ -11,9 +11,9 @@ interface FunctionCallPayload {
|
|
11
11
|
* @interface
|
12
12
|
*/
|
13
13
|
interface AIStreamCallbacks {
|
14
|
-
onStart?: () => Promise<void
|
15
|
-
onCompletion?: (completion: string) => Promise<void
|
16
|
-
onToken?: (token: string) => Promise<void
|
14
|
+
onStart?: () => Promise<void> | void;
|
15
|
+
onCompletion?: (completion: string) => Promise<void> | void;
|
16
|
+
onToken?: (token: string) => Promise<void> | void;
|
17
17
|
}
|
18
18
|
/**
|
19
19
|
* Custom parser for AIStream data.
|
package/dist/index.js
CHANGED
@@ -272,7 +272,11 @@ function createFunctionCallTransformer(callbacks) {
|
|
272
272
|
controller.enqueue(textEncoder.encode(functionResponse));
|
273
273
|
return;
|
274
274
|
}
|
275
|
-
const
|
275
|
+
const filteredCallbacks = __spreadProps(__spreadValues({}, callbacks), {
|
276
|
+
onStart: void 0,
|
277
|
+
onCompletion: void 0
|
278
|
+
});
|
279
|
+
const openAIStream = OpenAIStream(functionResponse, __spreadProps(__spreadValues({}, filteredCallbacks), {
|
276
280
|
[__internal__OpenAIFnMessagesSymbol]: newFunctionCallMessages
|
277
281
|
}));
|
278
282
|
const reader = openAIStream.getReader();
|
@@ -337,7 +341,7 @@ function createParser2(res) {
|
|
337
341
|
controller.close();
|
338
342
|
return;
|
339
343
|
}
|
340
|
-
if (text === "</s>" || text === "<|endoftext|>") {
|
344
|
+
if (text === "</s>" || text === "<|endoftext|>" || text === "<|end|>") {
|
341
345
|
controller.close();
|
342
346
|
} else {
|
343
347
|
controller.enqueue(text);
|
package/dist/index.mjs
CHANGED
@@ -239,7 +239,11 @@ function createFunctionCallTransformer(callbacks) {
|
|
239
239
|
controller.enqueue(textEncoder.encode(functionResponse));
|
240
240
|
return;
|
241
241
|
}
|
242
|
-
const
|
242
|
+
const filteredCallbacks = __spreadProps(__spreadValues({}, callbacks), {
|
243
|
+
onStart: void 0,
|
244
|
+
onCompletion: void 0
|
245
|
+
});
|
246
|
+
const openAIStream = OpenAIStream(functionResponse, __spreadProps(__spreadValues({}, filteredCallbacks), {
|
243
247
|
[__internal__OpenAIFnMessagesSymbol]: newFunctionCallMessages
|
244
248
|
}));
|
245
249
|
const reader = openAIStream.getReader();
|
@@ -304,7 +308,7 @@ function createParser2(res) {
|
|
304
308
|
controller.close();
|
305
309
|
return;
|
306
310
|
}
|
307
|
-
if (text === "</s>" || text === "<|endoftext|>") {
|
311
|
+
if (text === "</s>" || text === "<|endoftext|>" || text === "<|end|>") {
|
308
312
|
controller.close();
|
309
313
|
} else {
|
310
314
|
controller.enqueue(text);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "2.1.
|
3
|
+
"version": "2.1.23",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"sideEffects": false,
|
6
6
|
"main": "./dist/index.js",
|
@@ -10,7 +10,8 @@
|
|
10
10
|
"dist/**/*",
|
11
11
|
"react/dist/**/*",
|
12
12
|
"svelte/dist/**/*",
|
13
|
-
"vue/dist/**/*"
|
13
|
+
"vue/dist/**/*",
|
14
|
+
"prompts/dist/**/*"
|
14
15
|
],
|
15
16
|
"exports": {
|
16
17
|
"./package.json": "./package.json",
|
@@ -20,6 +21,12 @@
|
|
20
21
|
"module": "./dist/index.mjs",
|
21
22
|
"require": "./dist/index.js"
|
22
23
|
},
|
24
|
+
"./prompts": {
|
25
|
+
"types": "./prompts/dist/index.d.ts",
|
26
|
+
"import": "./prompts/dist/index.mjs",
|
27
|
+
"module": "./prompts/dist/index.mjs",
|
28
|
+
"require": "./prompts/dist/index.js"
|
29
|
+
},
|
23
30
|
"./react": {
|
24
31
|
"types": "./react/dist/index.d.ts",
|
25
32
|
"react-server": "./react/dist/index.server.mjs",
|
@@ -88,6 +95,21 @@
|
|
88
95
|
"publishConfig": {
|
89
96
|
"access": "public"
|
90
97
|
},
|
98
|
+
"homepage": "https://github.com/vercel-labs/ai#readme",
|
99
|
+
"repository": {
|
100
|
+
"type": "git",
|
101
|
+
"url": "git+https://github.com/vercel-labs/ai.git"
|
102
|
+
},
|
103
|
+
"bugs": {
|
104
|
+
"url": "https://github.com/vercel-labs/ai/issues"
|
105
|
+
},
|
106
|
+
"keywords": [
|
107
|
+
"ai",
|
108
|
+
"nextjs",
|
109
|
+
"svelte",
|
110
|
+
"react",
|
111
|
+
"vue"
|
112
|
+
],
|
91
113
|
"scripts": {
|
92
114
|
"build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
|
93
115
|
"clean": "rm -rf dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist",
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { ChatCompletionRequestMessageFunctionCall } from 'openai-edge';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Shared types between the API and UI packages.
|
5
|
+
*/
|
6
|
+
type Message = {
|
7
|
+
id: string;
|
8
|
+
createdAt?: Date;
|
9
|
+
content: string;
|
10
|
+
role: 'system' | 'user' | 'assistant' | 'function';
|
11
|
+
/**
|
12
|
+
* If the message has a role of `function`, the `name` field is the name of the function.
|
13
|
+
* Otherwise, the name field should not be set.
|
14
|
+
*/
|
15
|
+
name?: string;
|
16
|
+
/**
|
17
|
+
* If the assistant role makes a function call, the `function_call` field
|
18
|
+
* contains the function call name and arguments. Otherwise, the field should
|
19
|
+
* not be set.
|
20
|
+
*/
|
21
|
+
function_call?: string | ChatCompletionRequestMessageFunctionCall;
|
22
|
+
};
|
23
|
+
|
24
|
+
/**
|
25
|
+
* A prompt constructor for the HuggingFace StarChat Beta model.
|
26
|
+
* Does not support `function` messages.
|
27
|
+
* @see https://huggingface.co/HuggingFaceH4/starchat-beta
|
28
|
+
*/
|
29
|
+
declare function experimental_buildStarChatBetaPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
|
30
|
+
/**
|
31
|
+
* A prompt constructor for HuggingFace OpenAssistant models.
|
32
|
+
* Does not support `function` or `system` messages.
|
33
|
+
* @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5
|
34
|
+
*/
|
35
|
+
declare function experimental_buildOpenAssistantPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
|
36
|
+
|
37
|
+
export { experimental_buildOpenAssistantPrompt, experimental_buildStarChatBetaPrompt };
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// prompts/index.ts
|
21
|
+
var prompts_exports = {};
|
22
|
+
__export(prompts_exports, {
|
23
|
+
experimental_buildOpenAssistantPrompt: () => experimental_buildOpenAssistantPrompt,
|
24
|
+
experimental_buildStarChatBetaPrompt: () => experimental_buildStarChatBetaPrompt
|
25
|
+
});
|
26
|
+
module.exports = __toCommonJS(prompts_exports);
|
27
|
+
|
28
|
+
// prompts/huggingface.ts
|
29
|
+
function experimental_buildStarChatBetaPrompt(messages) {
|
30
|
+
return messages.map(({ content, role }) => {
|
31
|
+
if (role === "user") {
|
32
|
+
return `<|user|>
|
33
|
+
${content}<|end|>
|
34
|
+
`;
|
35
|
+
} else if (role === "assistant") {
|
36
|
+
return `<|assistant|>
|
37
|
+
${content}<|end|>
|
38
|
+
`;
|
39
|
+
} else if (role === "system") {
|
40
|
+
return `<|system|>
|
41
|
+
${content}<|end|>
|
42
|
+
`;
|
43
|
+
} else if (role === "function") {
|
44
|
+
throw new Error("StarChat Beta does not support function calls.");
|
45
|
+
}
|
46
|
+
}).join("") + "<|assistant|>";
|
47
|
+
}
|
48
|
+
function experimental_buildOpenAssistantPrompt(messages) {
|
49
|
+
return messages.map(({ content, role }) => {
|
50
|
+
if (role === "user") {
|
51
|
+
return `<|prompter|>${content}<|endoftext|>`;
|
52
|
+
} else if (role === "function") {
|
53
|
+
throw new Error("OpenAssistant does not support function calls.");
|
54
|
+
} else if (role === "system") {
|
55
|
+
throw new Error("OpenAssistant does not support system messages.");
|
56
|
+
} else {
|
57
|
+
return `<|assistant|>${content}<|endoftext|>`;
|
58
|
+
}
|
59
|
+
}).join("") + "<|assistant|>";
|
60
|
+
}
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
62
|
+
0 && (module.exports = {
|
63
|
+
experimental_buildOpenAssistantPrompt,
|
64
|
+
experimental_buildStarChatBetaPrompt
|
65
|
+
});
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// prompts/huggingface.ts
|
2
|
+
function experimental_buildStarChatBetaPrompt(messages) {
|
3
|
+
return messages.map(({ content, role }) => {
|
4
|
+
if (role === "user") {
|
5
|
+
return `<|user|>
|
6
|
+
${content}<|end|>
|
7
|
+
`;
|
8
|
+
} else if (role === "assistant") {
|
9
|
+
return `<|assistant|>
|
10
|
+
${content}<|end|>
|
11
|
+
`;
|
12
|
+
} else if (role === "system") {
|
13
|
+
return `<|system|>
|
14
|
+
${content}<|end|>
|
15
|
+
`;
|
16
|
+
} else if (role === "function") {
|
17
|
+
throw new Error("StarChat Beta does not support function calls.");
|
18
|
+
}
|
19
|
+
}).join("") + "<|assistant|>";
|
20
|
+
}
|
21
|
+
function experimental_buildOpenAssistantPrompt(messages) {
|
22
|
+
return messages.map(({ content, role }) => {
|
23
|
+
if (role === "user") {
|
24
|
+
return `<|prompter|>${content}<|endoftext|>`;
|
25
|
+
} else if (role === "function") {
|
26
|
+
throw new Error("OpenAssistant does not support function calls.");
|
27
|
+
} else if (role === "system") {
|
28
|
+
throw new Error("OpenAssistant does not support system messages.");
|
29
|
+
} else {
|
30
|
+
return `<|assistant|>${content}<|endoftext|>`;
|
31
|
+
}
|
32
|
+
}).join("") + "<|assistant|>";
|
33
|
+
}
|
34
|
+
export {
|
35
|
+
experimental_buildOpenAssistantPrompt,
|
36
|
+
experimental_buildStarChatBetaPrompt
|
37
|
+
};
|