@xsai/generate-text 0.4.0-beta.1 → 0.4.0-beta.3
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 +30 -39
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ import { chat, determineStepType, executeTool } from '@xsai/shared-chat';
|
|
|
4
4
|
const rawGenerateText = async (options) => chat({
|
|
5
5
|
...options,
|
|
6
6
|
maxSteps: void 0,
|
|
7
|
-
messages: options.messages,
|
|
8
7
|
steps: void 0,
|
|
9
8
|
stream: false
|
|
10
9
|
}).then(responseJSON).then(async (res) => {
|
|
@@ -27,39 +26,18 @@ const rawGenerateText = async (options) => chat({
|
|
|
27
26
|
...message,
|
|
28
27
|
reasoning_content: void 0
|
|
29
28
|
}));
|
|
30
|
-
if (finishReason
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
finishReason,
|
|
44
|
-
messages,
|
|
45
|
-
reasoningText: message.reasoning_content,
|
|
46
|
-
steps,
|
|
47
|
-
text: message.content,
|
|
48
|
-
toolCalls,
|
|
49
|
-
toolResults,
|
|
50
|
-
usage
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
for (const toolCall of msgToolCalls) {
|
|
54
|
-
const { completionToolCall, completionToolResult, message: message2 } = await executeTool({
|
|
55
|
-
abortSignal: options.abortSignal,
|
|
56
|
-
messages,
|
|
57
|
-
toolCall,
|
|
58
|
-
tools: options.tools
|
|
59
|
-
});
|
|
60
|
-
toolCalls.push(completionToolCall);
|
|
61
|
-
toolResults.push(completionToolResult);
|
|
62
|
-
messages.push(message2);
|
|
29
|
+
if (finishReason !== "stop" && stepType !== "done") {
|
|
30
|
+
for (const toolCall of msgToolCalls) {
|
|
31
|
+
const { completionToolCall, completionToolResult, message: message2 } = await executeTool({
|
|
32
|
+
abortSignal: options.abortSignal,
|
|
33
|
+
messages,
|
|
34
|
+
toolCall,
|
|
35
|
+
tools: options.tools
|
|
36
|
+
});
|
|
37
|
+
toolCalls.push(completionToolCall);
|
|
38
|
+
toolResults.push(completionToolResult);
|
|
39
|
+
messages.push(message2);
|
|
40
|
+
}
|
|
63
41
|
}
|
|
64
42
|
const step = {
|
|
65
43
|
finishReason,
|
|
@@ -72,11 +50,24 @@ const rawGenerateText = async (options) => chat({
|
|
|
72
50
|
steps.push(step);
|
|
73
51
|
if (options.onStepFinish)
|
|
74
52
|
await options.onStepFinish(step);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
53
|
+
if (step.finishReason === "stop" || step.stepType === "done") {
|
|
54
|
+
return {
|
|
55
|
+
finishReason: step.finishReason,
|
|
56
|
+
messages,
|
|
57
|
+
reasoningText: message.reasoning_content,
|
|
58
|
+
steps,
|
|
59
|
+
text: step.text,
|
|
60
|
+
toolCalls: step.toolCalls,
|
|
61
|
+
toolResults: step.toolResults,
|
|
62
|
+
usage: step.usage
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
65
|
+
return async () => rawGenerateText({
|
|
66
|
+
...options,
|
|
67
|
+
messages,
|
|
68
|
+
steps
|
|
69
|
+
});
|
|
70
|
+
}
|
|
80
71
|
});
|
|
81
72
|
const generateText = async (options) => trampoline(async () => rawGenerateText(options));
|
|
82
73
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsai/generate-text",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.0-beta.
|
|
4
|
+
"version": "0.4.0-beta.3",
|
|
5
5
|
"description": "extra-small AI SDK.",
|
|
6
6
|
"author": "Moeru AI",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@xsai/shared": "~0.4.0-beta.
|
|
33
|
-
"@xsai/shared-chat": "~0.4.0-beta.
|
|
32
|
+
"@xsai/shared": "~0.4.0-beta.3",
|
|
33
|
+
"@xsai/shared-chat": "~0.4.0-beta.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"valibot": "^1.0.0",
|
|
37
|
-
"@xsai/tool": "~0.4.0-beta.
|
|
37
|
+
"@xsai/tool": "~0.4.0-beta.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "pkgroll",
|