跳到主要内容

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

WxClientMessageDto

推送到微信客户端的消息内容

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

text

string

需要转换成语音的文字

voiceType

number

需要转换成的语音类型, 输出声音类型 101004:通用男声 101005:通用女声 601004:咨询男声 501001:咨询女声 101010:通用男声(大模型) 101035:通用女声(大模型)

Returns

Promise\<TextToSpeechResult>

使用示例

const result = await this.botContext.bot.tools.textToSpeech(
this.botContext.info.botId,
input.text,
input.voiceType
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`文字转语音失败: ${result?.message}`);
}

getTextToSpeech()

getTextToSpeech(botId, taskId): Promise\<GetTextToSpeechResult>

获取文字转语音结果

参数

botId

string

botId,即函数型 Agent 的 ID

taskId

string

textToSpeech 接口返回的 taskID

Returns

Promise\<GetTextToSpeechResult>

使用示例

const result = await this.botContext.bot.tools.getTextToSpeech(
this.botContext.info.botId,
input.taskId
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`查询文字转语音状态失败: ${result?.message}`);
}

getWxMediaContent()

getWxMediaContent(botId, triggerSrc, media): Promise\<GetWxMediaContentResult>

获取微信回调中语音内容

参数

botId

string

botId,即函数型 Agent 的 ID

triggerSrc

string

微信回调来源

media

string

微信语音 media ID

Returns

Promise\<GetWxMediaContentResult>

使用示例

const mediaResult = await this.botContext.bot.tools.getWxMediaContent(
this.botContext.bot.botId,
triggerSrc,
mediaId
);

content = mediaResult?.content;

类型

ChatDBSearchResult

属性

answerPrompt

answerPrompt: string

relateTables

relateTables: unknown[]


SearchDBResult

属性

code?

optional code: string

message?

optional message: string

searchResult

searchResult: ChatDBSearchResult


SearchFileResult

Properties

code?

optional code: string

content

content: string

message?

optional message: string


KnowledgeBaseDocument

属性

data

data: object

allParentParagraphTitles

allParentParagraphTitles: string[]

endPos

endPos: number

next

next: unknown[]

paragraphTitle

paragraphTitle: string

pre

pre: unknown[]

startPos

startPos: number

text

text: string

documentSet

documentSet: object

author

author: string

documentSetId

documentSetId: string

documentSetName

documentSetName: string

fileId

fileId: string

fileMetaData

fileMetaData: string

fileTitle

fileTitle: string


score

score: number


SearchKnowledgeResult

属性

code?

optional code: string

documents

documents: KnowledgeBaseDocument

knowledgeBase?

optional knowledgeBase: string[]

knowledgeMeta?

optional knowledgeMeta: string[]

message?

optional message: string


SearchResult

Properties

abstract

abstract: string

extra?

optional extra: string

index

index: number

publisher

publisher: string

publishTime

publishTime: number

source

source: "thirdparty" | "knowledgebase"

title

title: string

url

url: string


SearchInfo

Properties

searchResults

searchResults: SearchResult[]


SearchNetworkResult

Properties

code?

optional code: string

content

content: string

message?

optional message: string

searchInfo

searchInfo: SearchInfo


toolsCommonResp

属性

code?

optional code: string

message?

optional message: string


WxClientMessageDto

属性

msgId

msgId: string

msgType

msgType: string

openKfId?

optional openKfId: string

text

text: object

content

content: string

touser

touser: string


SpeechToTextResult

属性

code?

optional code: string

message?

optional message: string

result

result: string


TextToSpeechResult

属性

code?

optional code: string

message?

optional message: string

taskId

taskId: string


GetTextToSpeechResult

属性

code?

optional code: string

message?

optional message: string

resultUrl

resultUrl: string

status

status: number

statusStr

statusStr: string

taskId

taskId: string


GetWxMediaContentResult

属性

code?

optional code: string

content

content: string

message?

optional message: string