import { TcbContext } from '../types' import * as tools from './tools' export * from './tools' export class AITools { private baseURL: string private token: string constructor(context: TcbContext) { // 这里这种写法只能配合 @cloudbase/functions-framework 使用 if (typeof context?.extendedContext?.envId !== 'string') { throw new Error('env is required') } if (typeof context?.extendedContext?.accessToken !== 'string') { throw new Error('accessToken is required') } this.baseURL = `https://${context.extendedContext.envId}.api.tcloudbasegateway.com` this.token = context?.extendedContext?.accessToken?.replace('Bearer ', '').trim() } async searchFile(botId: string, msg: string, files: string[]): Promise { return await tools.searchFile(this.baseURL, this.token, botId, msg, files) } async searchDB(botId: string, msg: string, databaseModel: string[]): Promise { return await tools.searchDB(this.baseURL, this.token, botId, msg, databaseModel) } async searchKnowledgeBase(botId: string, msg: string, knowledgeBase: string[]): Promise { return await tools.searchKnowledgeBase(this.baseURL, this.token, botId, msg, knowledgeBase) } async searchNetwork(botId: string, msg: string): Promise { return await tools.searchNetwork(this.baseURL, this.token, botId, msg) } async speechToText(botId: string, engSerViceType: string, voiceFormat: string, voiceUrl: string): Promise { return await tools.speechToText(this.baseURL, this.token, botId, engSerViceType, voiceFormat, voiceUrl) } async textToSpeech(botId: string, text: string, voiceType: number): Promise { return await tools.textToSpeech(this.baseURL, this.token, botId, text, voiceType) } async getTextToSpeech(botId: string, taskId: string): Promise { return await tools.getTextToSpeech(this.baseURL, this.token, botId, taskId) } async getWxMediaContent(botId: string, triggerSrc: string, media: string): Promise { return await tools.getWxMediaContent(this.baseURL, this.token, botId, triggerSrc, media) } async sendWxClientMessage(botId: string, triggerSrc: string, wxClientMessage: tools.WxClientMessageDto): Promise { return await tools.sendWxClientMessage(this.baseURL, this.token, botId, triggerSrc, wxClientMessage) } }