@xsai/utils-chat 0.1.3 → 0.2.0-beta.2
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 +22 -29
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,43 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// src/message.ts
|
|
8
|
-
var message_exports = {};
|
|
9
|
-
__export(message_exports, {
|
|
10
|
-
assistant: () => assistant,
|
|
11
|
-
imagePart: () => imagePart,
|
|
12
|
-
isToolCall: () => isToolCall,
|
|
13
|
-
messages: () => messages,
|
|
14
|
-
system: () => system,
|
|
15
|
-
textPart: () => textPart,
|
|
16
|
-
tool: () => tool,
|
|
17
|
-
user: () => user
|
|
18
|
-
});
|
|
19
|
-
var messages = (...messages2) => messages2;
|
|
20
|
-
var system = (content) => ({ content, role: "system" });
|
|
21
|
-
var user = (content) => ({ content, role: "user" });
|
|
22
|
-
var textPart = (text) => ({ text, type: "text" });
|
|
23
|
-
var imagePart = (url) => ({ image_url: { url }, type: "image_url" });
|
|
24
|
-
var isToolCall = (content) => {
|
|
1
|
+
const messages = (...messages2) => messages2;
|
|
2
|
+
const system = (content) => ({ content, role: "system" });
|
|
3
|
+
const user = (content) => ({ content, role: "user" });
|
|
4
|
+
const textPart = (text) => ({ text, type: "text" });
|
|
5
|
+
const imagePart = (url) => ({ image_url: { url }, type: "image_url" });
|
|
6
|
+
const isToolCall = (content) => {
|
|
25
7
|
const isElementToolCallLike = (c) => {
|
|
26
8
|
return typeof c === "object" && ("type" in c && c.type === "function" && "id" in c && "function" in c && typeof c.function === "object");
|
|
27
9
|
};
|
|
28
10
|
return isElementToolCallLike(content) || Array.isArray(content) && content.every((part) => isElementToolCallLike(part));
|
|
29
11
|
};
|
|
30
|
-
|
|
12
|
+
const assistant = (content) => {
|
|
31
13
|
if (isToolCall(content)) {
|
|
32
14
|
return Array.isArray(content) ? { role: "assistant", tool_calls: content } : { role: "assistant", tool_calls: [content] };
|
|
33
15
|
}
|
|
34
16
|
return { content, role: "assistant" };
|
|
35
17
|
};
|
|
36
|
-
|
|
18
|
+
const tool = (content, toolCall) => ({
|
|
37
19
|
content,
|
|
38
20
|
role: "tool",
|
|
39
21
|
tool_call_id: toolCall.id
|
|
40
22
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
23
|
+
|
|
24
|
+
var message = /*#__PURE__*/Object.freeze({
|
|
25
|
+
__proto__: null,
|
|
26
|
+
assistant: assistant,
|
|
27
|
+
imagePart: imagePart,
|
|
28
|
+
isToolCall: isToolCall,
|
|
29
|
+
messages: messages,
|
|
30
|
+
system: system,
|
|
31
|
+
textPart: textPart,
|
|
32
|
+
tool: tool,
|
|
33
|
+
user: user
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export { message };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsai/utils-chat",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0-beta.2",
|
|
5
5
|
"description": "extra-small AI SDK for Browser, Node.js, Deno, Bun or Edge Runtime.",
|
|
6
6
|
"author": "Moeru AI",
|
|
7
7
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@xsai/shared-chat": ""
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "
|
|
35
|
+
"build": "pkgroll"
|
|
36
36
|
},
|
|
37
37
|
"main": "./dist/index.js",
|
|
38
38
|
"types": "./dist/index.d.ts"
|