@xsai/shared-chat 0.4.3 → 0.4.4
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 +3 -9
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { requestURL, requestHeaders, requestBody,
|
|
1
|
+
import { requestURL, requestHeaders, requestBody, responseCatch } from '@xsai/shared';
|
|
2
2
|
|
|
3
3
|
const chat = async (options) => (options.fetch ?? globalThis.fetch)(requestURL("chat/completions", options.baseURL), {
|
|
4
4
|
body: requestBody({
|
|
5
5
|
...options,
|
|
6
|
-
tools: options.tools?.map((tool) =>
|
|
7
|
-
function: clean({
|
|
8
|
-
...tool.function,
|
|
9
|
-
returns: void 0
|
|
10
|
-
}),
|
|
11
|
-
type: "function"
|
|
12
|
-
}))
|
|
6
|
+
tools: options.tools?.map(({ execute, ...tool }) => tool)
|
|
13
7
|
}),
|
|
14
8
|
headers: requestHeaders({
|
|
15
9
|
"Content-Type": "application/json",
|
|
@@ -53,7 +47,7 @@ const executeTool = async ({ abortSignal, messages, toolCall, tools }) => {
|
|
|
53
47
|
throw new Error(`Missing toolCall.function.name: ${JSON.stringify(toolCall)}`);
|
|
54
48
|
if (toolCall.function.arguments == null)
|
|
55
49
|
throw new Error(`Missing toolCall.function.arguments: ${JSON.stringify(toolCall)}`);
|
|
56
|
-
const parsedArgs = JSON.parse(toolCall.function.arguments);
|
|
50
|
+
const parsedArgs = JSON.parse(toolCall.function.arguments.trim() || "{}");
|
|
57
51
|
const result = wrapToolResult(await tool.execute(parsedArgs, {
|
|
58
52
|
abortSignal,
|
|
59
53
|
messages,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsai/shared-chat",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.4",
|
|
5
5
|
"description": "extra-small AI SDK.",
|
|
6
6
|
"author": "Moeru AI",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@xsai/shared": "~0.4.
|
|
32
|
+
"@xsai/shared": "~0.4.4"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "pkgroll"
|