@cloudbase/ai 2.11.0 → 2.12.0

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 (59) 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/type.d.ts +5 -0
  23. package/dist/cjs/type.js +1 -1
  24. package/dist/esm/AI.js +6 -4
  25. package/dist/esm/bot/index.d.ts +15 -15
  26. package/dist/esm/bot/index.js +56 -22
  27. package/dist/esm/models/Ark/index.d.ts +3 -3
  28. package/dist/esm/models/Ark/index.js +5 -3
  29. package/dist/esm/models/DashScope/index.d.ts +3 -3
  30. package/dist/esm/models/DashScope/index.js +5 -3
  31. package/dist/esm/models/DeepSeek/index.d.ts +3 -3
  32. package/dist/esm/models/DeepSeek/index.js +5 -3
  33. package/dist/esm/models/HunYuan/index.d.ts +3 -3
  34. package/dist/esm/models/HunYuan/index.js +5 -3
  35. package/dist/esm/models/HunYuanBeta/index.d.ts +3 -3
  36. package/dist/esm/models/HunYuanBeta/index.js +5 -3
  37. package/dist/esm/models/HunYuanOpen/index.d.ts +3 -3
  38. package/dist/esm/models/HunYuanOpen/index.js +5 -3
  39. package/dist/esm/models/Moonshot/index.d.ts +3 -3
  40. package/dist/esm/models/Moonshot/index.js +5 -3
  41. package/dist/esm/models/Yi/index.d.ts +3 -3
  42. package/dist/esm/models/Yi/index.js +5 -3
  43. package/dist/esm/models/ZhiPu/index.d.ts +3 -3
  44. package/dist/esm/models/ZhiPu/index.js +5 -3
  45. package/dist/esm/type.d.ts +5 -0
  46. package/dist/esm/type.js +1 -1
  47. package/package.json +4 -4
  48. package/src/AI.ts +5 -3
  49. package/src/bot/index.ts +56 -22
  50. package/src/models/Ark/index.ts +5 -2
  51. package/src/models/DashScope/index.ts +5 -2
  52. package/src/models/DeepSeek/index.ts +5 -2
  53. package/src/models/HunYuan/index.ts +5 -2
  54. package/src/models/HunYuanBeta/index.ts +5 -2
  55. package/src/models/HunYuanOpen/index.ts +5 -2
  56. package/src/models/Moonshot/index.ts +5 -2
  57. package/src/models/Yi/index.ts +5 -2
  58. package/src/models/ZhiPu/index.ts +5 -2
  59. package/src/type.ts +7 -1
package/src/bot/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type ParsedEvent } from '../eventsource_parser'
2
- import { BotReq } from '../type'
2
+ import { BotReq, ReqOptions } from '../type'
3
3
  import {
4
4
  IBotPreview,
5
5
  IBotSendMessage,
@@ -36,91 +36,125 @@ export class Bot {
36
36
  }
37
37
  }
38
38
 
39
- list(props: IGetBotList) {
39
+ list(props: IGetBotList, options?: ReqOptions) {
40
40
  return this.req({
41
41
  method: 'get',
42
42
  url: this.join('bots'),
43
43
  data: props,
44
+ timeout: options?.timeout,
44
45
  })
45
46
  }
46
47
 
47
- create({ botInfo }: ICreateBot) {
48
+ create({ botInfo }: ICreateBot, options?: ReqOptions) {
48
49
  return this.req({
49
50
  method: 'post',
50
51
  url: this.join('bots'),
51
52
  data: botInfo,
53
+ timeout: options?.timeout,
52
54
  })
53
55
  }
54
56
 
55
- get({ botId }: IGetBot) {
57
+ get({ botId }: IGetBot, options?: ReqOptions) {
56
58
  return this.req({
57
59
  method: 'get',
58
60
  url: this.join(`bots/${botId}`),
61
+ timeout: options?.timeout,
59
62
  })
60
63
  }
61
64
 
62
- update({ botId, botInfo }: IUpdateBot) {
65
+ update({ botId, botInfo }: IUpdateBot, options?: ReqOptions) {
63
66
  return this.req({
64
67
  method: 'PATCH',
65
68
  url: this.join(`bots/${botId}`),
66
69
  data: botInfo,
70
+ timeout: options?.timeout,
67
71
  })
68
72
  }
69
73
 
70
- delete({ botId }: IDeleteBot) {
71
- return this.req({ method: 'delete', url: this.join(`bots/${botId}`) })
74
+ delete({ botId }: IDeleteBot, options?: ReqOptions) {
75
+ return this.req({ method: 'delete', url: this.join(`bots/${botId}`), timeout: options?.timeout })
72
76
  }
73
77
 
74
- getChatRecords(props: IGetBotChatRecords) {
75
- return this.req({ method: 'get', url: this.join(`bots/${props.botId}/records`), data: props })
78
+ getChatRecords(props: IGetBotChatRecords, options?: ReqOptions) {
79
+ return this.req({
80
+ method: 'get',
81
+ url: this.join(`bots/${props.botId}/records`),
82
+ data: props,
83
+ timeout: options?.timeout,
84
+ })
76
85
  }
77
86
 
78
- sendFeedback({ userFeedback }: ISendBotFeedback) {
79
- return this.req({ method: 'post', url: this.join(`bots/${userFeedback.botId}/feedback`), data: userFeedback })
87
+ sendFeedback({ userFeedback }: ISendBotFeedback, options?: ReqOptions) {
88
+ return this.req({
89
+ method: 'post',
90
+ url: this.join(`bots/${userFeedback.botId}/feedback`),
91
+ data: userFeedback,
92
+ timeout: options?.timeout,
93
+ })
80
94
  }
81
95
 
82
- getFeedback(props: IGetBotFeedback) {
83
- return this.req({ method: 'get', url: this.join(`bots/${props.botId}/feedback`), data: props })
96
+ getFeedback(props: IGetBotFeedback, options?: ReqOptions) {
97
+ return this.req({
98
+ method: 'get',
99
+ url: this.join(`bots/${props.botId}/feedback`),
100
+ data: props,
101
+ timeout: options?.timeout,
102
+ })
84
103
  }
85
104
 
86
- async uploadFiles(props: IBotUploadFiles) {
105
+ async uploadFiles(props: IBotUploadFiles, options?: ReqOptions) {
87
106
  return this.req({
88
107
  method: 'post',
89
108
  url: this.join(`bots/${props.botId}/files`),
90
109
  data: props,
110
+ timeout: options?.timeout,
91
111
  })
92
112
  }
93
113
 
94
- async getRecommendQuestions(props: IGetBotRecommendQuestions) {
114
+ async getRecommendQuestions(props: IGetBotRecommendQuestions, options?: ReqOptions) {
95
115
  const res = await this.req({
96
116
  method: 'post',
97
117
  url: this.join(`bots/${props.botId}/recommend-questions`),
98
118
  data: props,
99
119
  stream: true,
120
+ timeout: options?.timeout,
100
121
  })
101
122
  return new StreamResult(res)
102
123
  }
103
124
 
104
- async generateBot(props: IGenerateBot) {
105
- const res = await this.req({ method: 'post', url: this.join('generate-bot'), data: props, stream: true })
125
+ async generateBot(props: IGenerateBot, options?: ReqOptions) {
126
+ const res = await this.req({
127
+ method: 'post',
128
+ url: this.join('generate-bot'),
129
+ data: props,
130
+ stream: true,
131
+ timeout: options?.timeout,
132
+ })
106
133
  return new StreamResult(res)
107
134
  }
108
135
 
109
- async getPreview(props: IBotPreview) {
110
- const res = await this.req({ method: 'post', url: this.join('preview'), data: props, stream: true })
136
+ async getPreview(props: IBotPreview, options?: ReqOptions) {
137
+ const res = await this.req({
138
+ method: 'post',
139
+ url: this.join('preview'),
140
+ data: props,
141
+ stream: true,
142
+ timeout: options?.timeout,
143
+ })
111
144
  return new StreamResult(res)
112
145
  }
113
146
 
114
- generateImage(props: IGenerateImage) {
115
- return this.req({ method: 'post', url: this.join('generate-image'), data: props })
147
+ generateImage(props: IGenerateImage, options?: ReqOptions) {
148
+ return this.req({ method: 'post', url: this.join('generate-image'), data: props, timeout: options?.timeout })
116
149
  }
117
150
 
118
- async sendMessage(props: IBotSendMessage) {
151
+ async sendMessage(props: IBotSendMessage, options?: ReqOptions) {
119
152
  const res = await this.req({
120
153
  method: 'post',
121
154
  url: this.join(`bots/${props.botId}/send-message`),
122
155
  data: props,
123
156
  stream: true,
157
+ timeout: options?.timeout,
124
158
  })
125
159
  return new StreamResult(res)
126
160
  }
@@ -13,6 +13,7 @@ import type {
13
13
  DoGenerateOutput,
14
14
  DoStreamOutput,
15
15
  BaseDoStreamOutputChunk,
16
+ ReqOptions,
16
17
  } from '../../type'
17
18
 
18
19
  function processInput(input: BaseChatModelInput): ArkInputData {
@@ -40,7 +41,7 @@ export class ArkSimpleModel 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 ArkSimpleModel implements SimpleChatModel {
48
49
  stream: false,
49
50
  },
50
51
  stream: false,
52
+ timeout: options?.timeout,
51
53
  })) as ArkGenerateTextOutput
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 ArkSimpleModel 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): DSInput {
@@ -41,7 +42,7 @@ export class DSSimpleModel 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 DSSimpleModel implements SimpleChatModel {
49
50
  stream: false,
50
51
  },
51
52
  stream: false,
53
+ timeout: options?.timeout,
52
54
  })) as DSGenerateOutput
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 DSSimpleModel 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
 
@@ -12,6 +12,7 @@ import type {
12
12
  DoStreamOutput,
13
13
  BaseDoStreamOutputChunk,
14
14
  DoGenerateOutput,
15
+ ReqOptions,
15
16
  } from '../../type'
16
17
 
17
18
  export class DeepSeekSimpleModel implements SimpleChatModel {
@@ -26,7 +27,7 @@ export class DeepSeekSimpleModel implements SimpleChatModel {
26
27
  return `${this.baseUrl}/${this.subUrl}`
27
28
  }
28
29
 
29
- public async doGenerate(data: BaseChatModelInput): Promise<DoGenerateOutput> {
30
+ public async doGenerate(data: BaseChatModelInput, options?: ReqOptions): Promise<DoGenerateOutput> {
30
31
  const res = (await this.req({
31
32
  url: this.url,
32
33
  data: {
@@ -34,11 +35,12 @@ export class DeepSeekSimpleModel implements SimpleChatModel {
34
35
  stream: false,
35
36
  },
36
37
  stream: false,
38
+ timeout: options?.timeout,
37
39
  })) as DoGenerateOutput
38
40
  return { ...res, rawResponse: res }
39
41
  }
40
42
 
41
- public async doStream(data: BaseChatModelInput): Promise<DoStreamOutput> {
43
+ public async doStream(data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput> {
42
44
  let isToolCall: null | boolean = null
43
45
  const _stream = await this.req({
44
46
  url: this.url,
@@ -47,6 +49,7 @@ export class DeepSeekSimpleModel implements SimpleChatModel {
47
49
  stream: true,
48
50
  },
49
51
  stream: true,
52
+ timeout: options?.timeout,
50
53
  })
51
54
  const stream = toPolyfillReadable(_stream) as typeof _stream
52
55
 
@@ -12,6 +12,7 @@ import type {
12
12
  DoStreamOutput,
13
13
  SimpleChatModel,
14
14
  DoGenerateOutput,
15
+ ReqOptions,
15
16
  } from '../../type'
16
17
  import { processInput, titleCaseToSnakeCase } from './util'
17
18
  import { HunYuanGenerateTextOutput, HunYuanStreamTextOutput } from './type'
@@ -28,7 +29,7 @@ export class HunYuanSimpleModel 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
  headers: {
@@ -39,6 +40,7 @@ export class HunYuanSimpleModel implements SimpleChatModel {
39
40
  stream: false,
40
41
  },
41
42
  stream: false,
43
+ timeout: options?.timeout,
42
44
  })) as { Response: any }
43
45
  const output = titleCaseToSnakeCase(res.Response) as HunYuanGenerateTextOutput
44
46
  return {
@@ -47,7 +49,7 @@ export class HunYuanSimpleModel implements SimpleChatModel {
47
49
  }
48
50
  }
49
51
 
50
- public async doStream(data: BaseChatModelInput): Promise<DoStreamOutput> {
52
+ public async doStream(data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput> {
51
53
  let isToolCall: null | boolean = null
52
54
 
53
55
  const _stream = await this.req({
@@ -60,6 +62,7 @@ export class HunYuanSimpleModel implements SimpleChatModel {
60
62
  stream: true,
61
63
  },
62
64
  stream: true,
65
+ timeout: options?.timeout,
63
66
  })
64
67
  const stream = toPolyfillReadable(_stream) as typeof _stream
65
68
 
@@ -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
 
package/src/type.ts CHANGED
@@ -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>(