@cloudbase/ai 2.11.0 → 2.12.1

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.
Files changed (64) hide show
  1. package/dist/cjs/AI.js +6 -4
  2. package/dist/cjs/bot/index.d.ts +15 -15
  3. package/dist/cjs/bot/index.js +56 -22
  4. package/dist/cjs/models/Ark/index.d.ts +3 -3
  5. package/dist/cjs/models/Ark/index.js +5 -3
  6. package/dist/cjs/models/DashScope/index.d.ts +3 -3
  7. package/dist/cjs/models/DashScope/index.js +5 -3
  8. package/dist/cjs/models/DeepSeek/index.d.ts +3 -3
  9. package/dist/cjs/models/DeepSeek/index.js +5 -3
  10. package/dist/cjs/models/HunYuan/index.d.ts +3 -3
  11. package/dist/cjs/models/HunYuan/index.js +5 -3
  12. package/dist/cjs/models/HunYuanBeta/index.d.ts +3 -3
  13. package/dist/cjs/models/HunYuanBeta/index.js +5 -3
  14. package/dist/cjs/models/HunYuanOpen/index.d.ts +3 -3
  15. package/dist/cjs/models/HunYuanOpen/index.js +5 -3
  16. package/dist/cjs/models/Moonshot/index.d.ts +3 -3
  17. package/dist/cjs/models/Moonshot/index.js +5 -3
  18. package/dist/cjs/models/Yi/index.d.ts +3 -3
  19. package/dist/cjs/models/Yi/index.js +5 -3
  20. package/dist/cjs/models/ZhiPu/index.d.ts +3 -3
  21. package/dist/cjs/models/ZhiPu/index.js +5 -3
  22. package/dist/cjs/models/model.d.ts +3 -3
  23. package/dist/cjs/models/model.js +5 -5
  24. package/dist/cjs/type.d.ts +7 -2
  25. package/dist/cjs/type.js +1 -1
  26. package/dist/esm/AI.js +6 -4
  27. package/dist/esm/bot/index.d.ts +15 -15
  28. package/dist/esm/bot/index.js +56 -22
  29. package/dist/esm/models/Ark/index.d.ts +3 -3
  30. package/dist/esm/models/Ark/index.js +5 -3
  31. package/dist/esm/models/DashScope/index.d.ts +3 -3
  32. package/dist/esm/models/DashScope/index.js +5 -3
  33. package/dist/esm/models/DeepSeek/index.d.ts +3 -3
  34. package/dist/esm/models/DeepSeek/index.js +5 -3
  35. package/dist/esm/models/HunYuan/index.d.ts +3 -3
  36. package/dist/esm/models/HunYuan/index.js +5 -3
  37. package/dist/esm/models/HunYuanBeta/index.d.ts +3 -3
  38. package/dist/esm/models/HunYuanBeta/index.js +5 -3
  39. package/dist/esm/models/HunYuanOpen/index.d.ts +3 -3
  40. package/dist/esm/models/HunYuanOpen/index.js +5 -3
  41. package/dist/esm/models/Moonshot/index.d.ts +3 -3
  42. package/dist/esm/models/Moonshot/index.js +5 -3
  43. package/dist/esm/models/Yi/index.d.ts +3 -3
  44. package/dist/esm/models/Yi/index.js +5 -3
  45. package/dist/esm/models/ZhiPu/index.d.ts +3 -3
  46. package/dist/esm/models/ZhiPu/index.js +5 -3
  47. package/dist/esm/models/model.d.ts +3 -3
  48. package/dist/esm/models/model.js +5 -5
  49. package/dist/esm/type.d.ts +7 -2
  50. package/dist/esm/type.js +1 -1
  51. package/package.json +4 -4
  52. package/src/AI.ts +5 -3
  53. package/src/bot/index.ts +56 -22
  54. package/src/models/Ark/index.ts +5 -2
  55. package/src/models/DashScope/index.ts +5 -2
  56. package/src/models/DeepSeek/index.ts +5 -2
  57. package/src/models/HunYuan/index.ts +5 -2
  58. package/src/models/HunYuanBeta/index.ts +5 -2
  59. package/src/models/HunYuanOpen/index.ts +5 -2
  60. package/src/models/Moonshot/index.ts +5 -2
  61. package/src/models/Yi/index.ts +5 -2
  62. package/src/models/ZhiPu/index.ts +5 -2
  63. package/src/models/model.ts +5 -4
  64. package/src/type.ts +9 -3
@@ -12,6 +12,7 @@ import type {
12
12
  DoStreamOutput,
13
13
  BaseDoStreamOutputChunk,
14
14
  DoGenerateOutput,
15
+ ReqOptions,
15
16
  } from '../../type'
16
17
  import { processInput } from '../HunYuan/util'
17
18
  import { HunYuanGenerateTextOutput, HunYuanStreamTextOutput } from '../HunYuan/type'
@@ -28,7 +29,7 @@ export class HunYuanBetaSimpleModel implements SimpleChatModel {
28
29
  return `${this.baseUrl}/${this.subUrl}`
29
30
  }
30
31
 
31
- public async doGenerate(data: BaseChatModelInput): Promise<DoGenerateOutput> {
32
+ public async doGenerate(data: BaseChatModelInput, options?: ReqOptions): Promise<DoGenerateOutput> {
32
33
  const res = (await this.req({
33
34
  url: this.url,
34
35
  data: {
@@ -36,11 +37,12 @@ export class HunYuanBetaSimpleModel implements SimpleChatModel {
36
37
  stream: false,
37
38
  },
38
39
  stream: false,
40
+ timeout: options?.timeout,
39
41
  })) as HunYuanGenerateTextOutput
40
42
  return { ...res, rawResponse: res }
41
43
  }
42
44
 
43
- public async doStream(data: BaseChatModelInput): Promise<DoStreamOutput> {
45
+ public async doStream(data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput> {
44
46
  let isToolCall: null | boolean = null
45
47
 
46
48
  const _stream = await this.req({
@@ -50,6 +52,7 @@ export class HunYuanBetaSimpleModel implements SimpleChatModel {
50
52
  stream: true,
51
53
  },
52
54
  stream: true,
55
+ timeout: options?.timeout,
53
56
  })
54
57
  const stream = toPolyfillReadable(_stream) as typeof _stream
55
58
 
@@ -12,6 +12,7 @@ import type {
12
12
  DoStreamOutput,
13
13
  BaseDoStreamOutputChunk,
14
14
  DoGenerateOutput,
15
+ ReqOptions,
15
16
  } from '../../type'
16
17
  import { processInput } from '../HunYuan/util'
17
18
  import { HunYuanGenerateTextOutput, HunYuanStreamTextOutput } from '../HunYuan/type'
@@ -28,7 +29,7 @@ export class HunYuanOpenSimpleModel implements SimpleChatModel {
28
29
  return `${this.baseUrl}/${this.subUrl}`
29
30
  }
30
31
 
31
- public async doGenerate(data: BaseChatModelInput): Promise<DoGenerateOutput> {
32
+ public async doGenerate(data: BaseChatModelInput, options?: ReqOptions): Promise<DoGenerateOutput> {
32
33
  const res = (await this.req({
33
34
  url: this.url,
34
35
  data: {
@@ -36,11 +37,12 @@ export class HunYuanOpenSimpleModel implements SimpleChatModel {
36
37
  stream: false,
37
38
  },
38
39
  stream: false,
40
+ timeout: options?.timeout,
39
41
  })) as HunYuanGenerateTextOutput
40
42
  return { ...res, rawResponse: res }
41
43
  }
42
44
 
43
- public async doStream(data: BaseChatModelInput): Promise<DoStreamOutput> {
45
+ public async doStream(data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput> {
44
46
  let isToolCall: null | boolean = null
45
47
 
46
48
  const _stream = await this.req({
@@ -50,6 +52,7 @@ export class HunYuanOpenSimpleModel implements SimpleChatModel {
50
52
  stream: true,
51
53
  },
52
54
  stream: true,
55
+ timeout: options?.timeout,
53
56
  })
54
57
  const stream = toPolyfillReadable(_stream) as typeof _stream
55
58
 
@@ -13,6 +13,7 @@ import type {
13
13
  DoStreamOutput,
14
14
  SimpleChatModel,
15
15
  BaseChatModelInput,
16
+ ReqOptions,
16
17
  } from '../../type'
17
18
 
18
19
  function processInput(input: BaseChatModelInput): MoonshotInputData {
@@ -40,7 +41,7 @@ export class MoonshotSimpleModel implements SimpleChatModel {
40
41
  return `${this.baseUrl}/${this.subUrl}`
41
42
  }
42
43
 
43
- public async doGenerate(data: BaseChatModelInput): Promise<DoGenerateOutput> {
44
+ public async doGenerate(data: BaseChatModelInput, options?: ReqOptions): Promise<DoGenerateOutput> {
44
45
  const res = (await this.req({
45
46
  url: this.url,
46
47
  data: {
@@ -48,11 +49,12 @@ export class MoonshotSimpleModel implements SimpleChatModel {
48
49
  stream: false,
49
50
  },
50
51
  stream: false,
52
+ timeout: options?.timeout,
51
53
  })) as MoonshotGenerateTextOutput
52
54
  return { ...res, rawResponse: res }
53
55
  }
54
56
 
55
- public async doStream(data: BaseChatModelInput): Promise<DoStreamOutput> {
57
+ public async doStream(data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput> {
56
58
  let isToolCall: null | boolean = null
57
59
  const _stream = await this.req({
58
60
  url: this.url,
@@ -61,6 +63,7 @@ export class MoonshotSimpleModel implements SimpleChatModel {
61
63
  stream: true,
62
64
  },
63
65
  stream: true,
66
+ timeout: options?.timeout,
64
67
  })
65
68
  const stream = toPolyfillReadable(_stream) as typeof _stream
66
69
 
@@ -13,6 +13,7 @@ import type {
13
13
  DoStreamOutput,
14
14
  BaseDoStreamOutputChunk,
15
15
  SimpleChatModel,
16
+ ReqOptions,
16
17
  } from '../../type'
17
18
 
18
19
  function processInput(input: BaseChatModelInput): YiInput {
@@ -41,7 +42,7 @@ export class YiSimpleModel implements SimpleChatModel {
41
42
  return `${this.baseUrl}/${this.subUrl}`
42
43
  }
43
44
 
44
- public async doGenerate(data: BaseChatModelInput): Promise<DoGenerateOutput> {
45
+ public async doGenerate(data: BaseChatModelInput, options?: ReqOptions): Promise<DoGenerateOutput> {
45
46
  const res = (await this.req({
46
47
  url: this.url,
47
48
  data: {
@@ -49,11 +50,12 @@ export class YiSimpleModel implements SimpleChatModel {
49
50
  stream: false,
50
51
  },
51
52
  stream: false,
53
+ timeout: options?.timeout,
52
54
  })) as YiGenerateOutput
53
55
  return { ...res, rawResponse: res }
54
56
  }
55
57
 
56
- public async doStream(data: BaseChatModelInput): Promise<DoStreamOutput> {
58
+ public async doStream(data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput> {
57
59
  let isToolCall: null | boolean = null
58
60
  const _stream = await this.req({
59
61
  url: this.url,
@@ -62,6 +64,7 @@ export class YiSimpleModel implements SimpleChatModel {
62
64
  stream: true,
63
65
  },
64
66
  stream: true,
67
+ timeout: options?.timeout,
65
68
  })
66
69
  const stream = toPolyfillReadable(_stream) as typeof _stream
67
70
 
@@ -13,6 +13,7 @@ import type {
13
13
  DoStreamOutput,
14
14
  BaseDoStreamOutputChunk,
15
15
  DoGenerateOutput,
16
+ ReqOptions,
16
17
  } from '../../type'
17
18
 
18
19
  function processInput(input: BaseChatModelInput): ZhiPuInputData {
@@ -48,7 +49,7 @@ export class ZhiPuSimpleModel implements SimpleChatModel {
48
49
  return `${this.baseUrl}/${this.subUrl}`
49
50
  }
50
51
 
51
- public async doGenerate(_data: BaseChatModelInput): Promise<DoGenerateOutput> {
52
+ public async doGenerate(_data: BaseChatModelInput, options?: ReqOptions): Promise<DoGenerateOutput> {
52
53
  const data = processInput(_data)
53
54
  const res = (await this.req({
54
55
  url: this.url,
@@ -57,11 +58,12 @@ export class ZhiPuSimpleModel implements SimpleChatModel {
57
58
  stream: false,
58
59
  },
59
60
  stream: false,
61
+ timeout: options?.timeout,
60
62
  })) as ZhiPuGenerateTextOutput
61
63
  return { ...res, rawResponse: res }
62
64
  }
63
65
 
64
- public async doStream(_data: BaseChatModelInput): Promise<DoStreamOutput> {
66
+ public async doStream(_data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput> {
65
67
  const data = processInput(_data)
66
68
  let isToolCall: null | boolean = null
67
69
  const _stream = await this.req({
@@ -71,6 +73,7 @@ export class ZhiPuSimpleModel implements SimpleChatModel {
71
73
  stream: true,
72
74
  },
73
75
  stream: true,
76
+ timeout: options?.timeout,
74
77
  })
75
78
  const stream = toPolyfillReadable(_stream) as typeof _stream
76
79
 
@@ -18,6 +18,7 @@ import {
18
18
  ToolCallAssistantMessage,
19
19
  ModelTool,
20
20
  FunctionTool,
21
+ ReqOptions,
21
22
  } from '../type'
22
23
 
23
24
  type ReactModelInput = ReactProps &
@@ -69,7 +70,7 @@ function processInput(obj: ReactModelInput): [ReactProps, BaseChatModelInput] {
69
70
  export class ReactModel {
70
71
  constructor(private model: SimpleChatModel) {}
71
72
 
72
- public async generateText(_input: ReactModelInput): Promise<{
73
+ public async generateText(_input: ReactModelInput, options?: ReqOptions): Promise<{
73
74
  text: string
74
75
  messages: Array<ChatModelMessage>
75
76
  usage: Usage
@@ -81,7 +82,7 @@ export class ReactModel {
81
82
 
82
83
  const [{ onStepFinish, maxSteps = 10 }, input] = processInput(_input)
83
84
 
84
- const doGenerate = () => this.model.doGenerate(input) // 后续代码会直接对 input.messages 原地修改,这里一直用同一个对象就行
85
+ const doGenerate = () => this.model.doGenerate(input, options) // 后续代码会直接对 input.messages 原地修改,这里一直用同一个对象就行
85
86
  let currentRes = await doGenerate()
86
87
  let currentStep = 1
87
88
  currentRes.rawResponse && rawResponses.push(currentRes.rawResponse)
@@ -152,7 +153,7 @@ export class ReactModel {
152
153
  }
153
154
  }
154
155
 
155
- public async streamText(_input: ReactModelInput): Promise<{
156
+ public async streamText(_input: ReactModelInput, options?: ReqOptions): Promise<{
156
157
  dataStream: DoStreamOutput
157
158
  textStream: AsyncIterableReadableStream<string>
158
159
  messages: Promise<Array<ChatModelMessage>>
@@ -162,7 +163,7 @@ export class ReactModel {
162
163
  const totalUsage: Usage = { completion_tokens: 0, prompt_tokens: 0, total_tokens: 0 }
163
164
 
164
165
  const [{ onStepFinish, maxSteps = 10 }, input] = processInput(_input)
165
- const doStream = () => this.model.doStream(input) // 后续代码会直接对 input.messages 原地修改,这里一直用同一个对象就行
166
+ const doStream = () => this.model.doStream(input, options) // 后续代码会直接对 input.messages 原地修改,这里一直用同一个对象就行
166
167
  let currentRes = await doStream()
167
168
  const currentStep = 1
168
169
  let readResult: { message: ToolCallAssistantMessage; usage: Usage } | null = null
package/src/type.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export abstract class SimpleChatModel {
2
- public abstract doGenerate(data: BaseChatModelInput): Promise<DoGenerateOutput>
2
+ public abstract doGenerate(data: BaseChatModelInput, options?: ReqOptions): Promise<DoGenerateOutput>
3
3
 
4
- public abstract doStream(data: BaseChatModelInput): Promise<DoStreamOutput>
4
+ public abstract doStream(data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput>
5
5
  }
6
6
 
7
7
  type RawResponse = { rawResponse?: any }
@@ -20,7 +20,8 @@ export interface IModelReqInput {
20
20
  url: string
21
21
  headers?: Record<string, string>
22
22
  data?: Object
23
- stream?: boolean
23
+ stream?: boolean,
24
+ timeout?: number
24
25
  }
25
26
 
26
27
  export type ModelReq = <T extends IModelReqInput>(
@@ -33,6 +34,11 @@ export interface IBotReqInput {
33
34
  headers?: Record<string, string>
34
35
  data?: Object
35
36
  stream?: boolean
37
+ timeout?: number
38
+ }
39
+
40
+ export interface ReqOptions {
41
+ timeout?: number
36
42
  }
37
43
 
38
44
  export type BotReq = <T extends IBotReqInput>(