各位微信开发者:
在小程序基础库3.7.1及以上,微信云开发新增 wx.cloud.extend 对象,用于拓展能力的调用,本次具体新增接口如下:
1.wx.cloud.extend.AI
此能力由腾讯云开发提供,用于AI相关扩展能力的调用,包含调用大模型、调用AI智能体等能力,示例如下:
调用大模型:
const hy = wx.cloud.extend.AI.createModel("hunyuan-exp"); // 创建模型
const res = await hy.streamText({
data: {
model: "hunyuan-turbo", // 具体模型型号
messages: [
{
role: "user",
content: "What is Tencent CloudBase" // 对话内容
}
]
}
});
for await (let str of res.textStream) {
console.log(str); // 打印生成的文本
}
for await (let event of res.eventStream) {
console.log(event); // 打印每次返回的完整数据
}
调用智能体(Bot):
const res = await wx.cloud.extend.AI.bot.sendMessage({
data: {
botId: 'xxx-bot-id', // 填入对应的 Agent ID
msg: "微信云开发是什么" // 对话内容
}
});
for await (let x of res.textStream) {
console.log(x); // 打印生成的文本
}