Skip to content

Commit be3883f

Browse files
authored
Merge pull request #345 from wechat-miniprogram/feat-cloud-extend
Feat cloud extend
2 parents 9c691dd + 53deacf commit be3883f

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

types/wx/lib.wx.cloud.d.ts

+68-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
SOFTWARE.
2121
***************************************************************************** */
2222

23+
/// <reference lib="es2018.asynciterable" />
24+
2325
/**
2426
* Common interfaces and types
2527
*/
@@ -137,6 +139,7 @@ interface WxCloud {
137139
): Promise<ICloud.ConnectContainerResult>
138140

139141
services: ICloud.CloudServices
142+
extend: ICloud.ICloudExtendServices
140143
}
141144

142145
declare namespace ICloud {
@@ -218,7 +221,7 @@ declare namespace ICloud {
218221
refresh: (session: AsyncSession<string>) => Promise<void>
219222
}
220223
interface GatewayConstructOptions {
221-
id: string
224+
id?: string
222225
appid?: string
223226
domain?: string
224227
keepalive?: boolean
@@ -234,6 +237,70 @@ declare namespace ICloud {
234237
}
235238
// === end ===
236239

240+
// === API: extend ===
241+
interface ICloudExtendServices {
242+
AI: ICloudAI
243+
}
244+
interface ICloudAI {
245+
createModel: (modelName: string) => ICloudAIModel
246+
bot: ICloudBot
247+
}
248+
interface ICloudAICallbackOptions {
249+
onEvent?: (ev: ICloudAIEvent) => void
250+
onText?: (text: string) => void
251+
onFinish?: (text: string) => void
252+
}
253+
interface ICloudBot {
254+
get: ({ botId: string }: any) => any
255+
list: (data: any) => any
256+
create: (data: any) => any
257+
update: (data: any) => any
258+
delete: (data: any) => any
259+
getChatRecords: (data: any) => any
260+
sendFeedback: (data: any) => any
261+
getFeedBack: (data: any) => any
262+
getRecommendQuestions: (options: ICloudAICallbackOptions & ICloudBotOptions) => Promise<ICloudAIStreamResult>
263+
sendMessage: (options: ICloudAICallbackOptions & ICloudBotOptions) => Promise<ICloudAIStreamResult>
264+
}
265+
266+
interface ICloudBotOptions { data: any, botId: string, timeout?: number }
267+
interface ICloudAIModel {
268+
streamText: (opts: ICloudAIOptions & ICloudAICallbackOptions) => Promise<ICloudAIStreamResult>
269+
generateText: (opts: ICloudAIOptions & ICloudAICallbackOptions) => Promise<string>
270+
}
271+
interface ICloudAIChatMessage {
272+
role: 'user' | 'assistant' | string
273+
content: string
274+
}
275+
interface ICloudAIChatModelInput {
276+
model: string
277+
messages: ICloudAIChatMessage[]
278+
temperature?: number
279+
top_p?: number
280+
}
281+
interface ICloudAIOptions{
282+
data: ICloudAIChatModelInput
283+
}
284+
interface ICloudAIEvent {
285+
event: string
286+
id: string
287+
data: string
288+
json?: any
289+
}
290+
291+
interface AsyncIterator<T> {
292+
next(value?: any): Promise<IteratorResult<T>>
293+
return?(value?: any): Promise<IteratorResult<T>>
294+
throw?(e?: any): Promise<IteratorResult<T>>
295+
[Symbol.asyncIterator](): AsyncIterableIterator<T>
296+
}
297+
interface ICloudAIStreamResult {
298+
textStream: AsyncIterator<string>
299+
eventStream: AsyncIterator<ICloudAIEvent>
300+
abort?: () => void
301+
}
302+
// === end ===
303+
237304
// === API: uploadFile ===
238305
interface UploadFileResult extends IAPISuccessParam {
239306
fileID: string

0 commit comments

Comments
 (0)