@cloudbase/ai 2.12.0 → 2.13.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.
package/src/bot/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { type ParsedEvent } from '../eventsource_parser'
2
2
  import { BotReq, ReqOptions } from '../type'
3
3
  import {
4
+ IBotCreateConversation,
5
+ IBotDeleteConversation,
6
+ IBotGetConversation,
4
7
  IBotPreview,
5
8
  IBotSendMessage,
6
9
  IBotUploadFiles,
@@ -111,6 +114,36 @@ export class Bot {
111
114
  })
112
115
  }
113
116
 
117
+ async createConversation(props: IBotCreateConversation, options?: ReqOptions) {
118
+ return this.req({
119
+ method: 'post',
120
+ url: this.join('conversation'),
121
+ data: props,
122
+ timeout: options?.timeout,
123
+ })
124
+ }
125
+
126
+ async getConversation({ pageSize = 10, pageNumber = 1, ...rest }: IBotGetConversation, options?: ReqOptions) {
127
+ if (pageNumber < 1) throw new Error('pageNumber must be greater than 0')
128
+ const offset = pageSize * (pageNumber - 1)
129
+ const limit = pageSize
130
+ return this.req({
131
+ method: 'get',
132
+ url: this.join('conversation'),
133
+ data: { ...rest, offset, limit },
134
+ timeout: options?.timeout,
135
+ })
136
+ }
137
+
138
+ async deleteConversation(props: IBotDeleteConversation, options?: ReqOptions) {
139
+ return this.req({
140
+ method: 'delete',
141
+ url: this.join(`conversation/${props.conversationId}`),
142
+ data: props,
143
+ timeout: options?.timeout,
144
+ })
145
+ }
146
+
114
147
  async getRecommendQuestions(props: IGetBotRecommendQuestions, options?: ReqOptions) {
115
148
  const res = await this.req({
116
149
  method: 'post',
package/src/bot/types.ts CHANGED
@@ -99,6 +99,23 @@ export interface IBotUploadFiles {
99
99
  }>
100
100
  }
101
101
 
102
+ export interface IBotCreateConversation {
103
+ botId: string
104
+ title?: string
105
+ }
106
+
107
+ export interface IBotGetConversation {
108
+ botId: string
109
+ pageSize?: number
110
+ pageNumber?: number
111
+ isDefault?: boolean
112
+ }
113
+
114
+ export interface IBotDeleteConversation {
115
+ botId: string
116
+ conversationId: string
117
+ }
118
+
102
119
  export interface IUserFeedback {
103
120
  recordId: string
104
121
  type: string
@@ -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 }