@xsai/generate-text 0.0.21 → 0.0.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 CHANGED
@@ -1,6 +1,6 @@
1
- import { ChatCompletionOptions, FinishReason } from '@xsai/shared-chat-completion';
1
+ import { ChatOptions, FinishReason } from '@xsai/shared-chat';
2
2
 
3
- interface GenerateTextOptions extends ChatCompletionOptions {
3
+ interface GenerateTextOptions extends ChatOptions {
4
4
  /** @default 1 */
5
5
  maxSteps?: number;
6
6
  /** if you want to enable stream, use `@xsai/stream-text` */
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { chatCompletion } from '@xsai/shared-chat-completion';
1
+ import { chat, ChatError } from '@xsai/shared-chat';
2
2
 
3
3
  const generateText = async (options) => {
4
4
  let currentStep = 0;
@@ -13,15 +13,15 @@ const generateText = async (options) => {
13
13
  const messages = options.messages;
14
14
  while (currentStep < (options.maxSteps ?? 1)) {
15
15
  currentStep += 1;
16
- const res = await chatCompletion({
16
+ const res = await chat({
17
17
  ...options,
18
18
  maxSteps: void 0,
19
19
  messages,
20
20
  stream: false
21
21
  });
22
22
  if (!res.ok) {
23
- const error = await res.text();
24
- throw new Error(`Error(${res.status}): ${error}`);
23
+ const error = new ChatError(`Remote sent ${res.status} response`, res);
24
+ error.cause = new Error(await res.text());
25
25
  }
26
26
  const data = await res.json();
27
27
  const { finish_reason, message } = data.choices[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsai/generate-text",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "type": "module",
5
5
  "author": "Moeru AI",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "@xsai/shared-chat-completion": ""
33
+ "@xsai/shared-chat": ""
34
34
  },
35
35
  "devDependencies": {
36
36
  "@xsai/providers": ""