AITools
BotCore 对外提供的一些工具,用户可以使用 tools 快速实现基础功能。
AITools 目前对外提供的工具
AITools 方法名 | 描述 |
|---|---|
searchDB | 查询数据模型内容 |
searchFile | 查询文件内容 |
searchKnowledgeBase | 查询知识库内容 |
searchNetwork | 查询联网内容 |
sendWxClientMessage | 推送信息到微信客户端 |
speechToText | 语音转文字 |
textToSpeech | 文字转语音 |
getTextToSpeech | 获取文字转语音结果 |
getWxMediaContent | 获取微信回调中语音内容 |
方法
searchDB()
searchDB(
botId,msg,databaseModel):Promise<SearchDBResult>
查询数据模型内容
参数
botId
string
botId,即函数型 Agent 的 ID
msg
string
对话消息内容
databaseModel
string[]
数据模型列表
Returns
Promise<SearchDBResult>
使用示例
const result = await this.botContext.bot.tools.searchDB(
this.botContext.info.botId,
msg,
this.botContext.info.databaseModel
);
if (result?.code && result?.code?.length !== 0) {
throw new Error(`查询数据模型内容失败: ${result?.message}`);
}
searchFile()
searchFile(
botId,msg,files):Promise<SearchFileResult>
查询文件内容
参数
botId
string
botId,即函数型 Agent 的 ID
msg
string
对话消息内容
files
string[]
文件上传到云存储中的 fileID
Returns
Promise<SearchFileResult>
使用示例
const result = await this.botContext.bot.tools.searchFile(
this.botContext.info.botId,
msg,
files
);
if (result?.code && result?.code?.length !== 0) {
throw new Error(`查询文件内容失败: ${result?.message}`);
}
searchKnowledgeBase()
searchKnowledgeBase(
botId,msg,knowledgeBase):Promise<SearchKnowledgeResult>
查询知识库内容
参数
botId
string
botId,即函数型 Agent 的 ID
msg
string
对话消息内容
knowledgeBase
string[]
知识库 ID
Returns
Promise<SearchKnowledgeResult>
使用示例
const result = await this.botContext.bot.tools.searchKnowledgeBase(
this.botContext.info.botId,
msg,
this.botContext.info.knowledgeBase
);
if (result?.code && result?.code?.length !== 0) {
throw new Error(`查询知识库内容失败: ${result?.message}`);
}
searchNetwork()
searchNetwork(
botId,msg):Promise<SearchNetworkResult>
查询联网内容
参数
botId
string
botId,即函数型 Agent 的 ID
msg
string
对话消息内容
Returns
Promise<SearchNetworkResult>
使用示例
const result = await this.botContext.bot.tools.searchNetwork(
this.botContext.info.botId,
msg
);
if (result?.code && result?.code?.length !== 0) {
throw new Error(`查询联网内容失败 ${result?.message}`);
}
sendWxClientMessage()
sendWxClientMessage(
botId,triggerSrc,wxClientMessage):Promise<toolsCommonResp>
推送信息到微信客户端
参数
botId
string
botId,即函数型 Agent 的 ID
triggerSrc
string
微信回调来源
wxClientMessage
推送到微信客户端的消息内容
Returns
Promise<toolsCommonResp>
使用示例
const sendResult = await this.botContext.bot.tools.sendWxClientMessage(
this.botContext.bot.botId,
triggerSrc,
{
msgType: toWxMsgData?.msgType,
touser: toWxMsgData?.touser,
text: toWxMsgData?.text,
openKfId: toWxMsgData?.openKfId,
msgId: toWxMsgData?.msgId,
}
);
console.log("sendResult:", sendResult);
speechToText()
speechToText(
botId,engSerViceType,voiceFormat,voiceUrl):Promise<SpeechToTextResult>
语音转文字
参数
botId
string
botId,即函数型 Agent 的 ID
engSerViceType
string
语言类型
voiceFormat
string
语音文件类型,输入语言 16k_zh:中文通用 16k_zh-PY:中英粤 16k_zh_medical:中文医疗 16k_en:英语 16k_yue:粤语
voiceUrl
string
语音文件公网链接
Returns
Promise<SpeechToTextResult>
使用示例
const result = await this.botContext.bot.tools.speechToText(
this.botContext.info.botId,
input.engSerViceType,
input.voiceFormat,
input.url
);
if (result?.code && result?.code?.length !== 0) {
throw new Error(`语音转文字失败: ${result?.message}`);
}
textToSpeech()
textToSpeech(
botId,text,voiceType):Promise<TextToSpeechResult>
文字转语音
参数
botId
string
botId,即函数型 Agent 的 ID