@xsai/generate-text 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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ChatOptions, Tool, FinishReason, AssistantMessageResponse, Usage, Message, CompletionToolCall, CompletionToolResult, StepType } from '@xsai/shared-chat';
1
+ import { ChatOptions, FinishReason, StepType, CompletionToolCall, CompletionToolResult, Usage, Tool, AssistantMessageResponse, Message } from '@xsai/shared-chat';
2
2
 
3
3
  interface GenerateTextOptions extends ChatOptions {
4
4
  /** @default 1 */
package/dist/index.js CHANGED
@@ -1,12 +1,16 @@
1
- // src/index.ts
2
- import { chat, determineStepType, executeTool } from "@xsai/shared-chat";
3
- var rawGenerateText = async (options) => chat({
1
+ import { responseJSON } from '@xsai/shared';
2
+ import { chat, determineStepType, executeTool } from '@xsai/shared-chat';
3
+
4
+ const rawGenerateText = async (options) => chat({
4
5
  ...options,
5
6
  maxSteps: void 0,
6
7
  messages: options.messages,
7
8
  steps: void 0,
8
9
  stream: false
9
- }).then(async (res) => res.json()).then(async ({ choices, usage }) => {
10
+ }).then(responseJSON).then(async (res) => {
11
+ const { choices, usage } = res;
12
+ if (!choices?.length)
13
+ throw new Error(`No choices returned, response body: ${JSON.stringify(res)}`);
10
14
  const messages = structuredClone(options.messages);
11
15
  const steps = options.steps ? structuredClone(options.steps) : [];
12
16
  const toolCalls = [];
@@ -75,12 +79,11 @@ var rawGenerateText = async (options) => chat({
75
79
  steps
76
80
  });
77
81
  });
78
- var generateText = async (options) => {
82
+ const generateText = async (options) => {
79
83
  let result = await rawGenerateText(options);
80
84
  while (typeof result === "function")
81
85
  result = await result();
82
86
  return result;
83
87
  };
84
- export {
85
- generateText
86
- };
88
+
89
+ export { generateText };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/generate-text",
3
3
  "type": "module",
4
- "version": "0.1.3",
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",
@@ -29,14 +29,15 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
+ "@xsai/shared": "",
32
33
  "@xsai/shared-chat": ""
33
34
  },
34
35
  "devDependencies": {
35
36
  "@xsai/tool": "",
36
- "valibot": "^1.0.0-rc.3"
37
+ "valibot": "^1.0.0"
37
38
  },
38
39
  "scripts": {
39
- "build": "tsup",
40
+ "build": "pkgroll",
40
41
  "test": "vitest run",
41
42
  "test:watch": "vitest"
42
43
  },