MaxKB api 调用插件

v1.0.0发布于:2025-01-17 15:43

说明文档
回复列表 (0)

介绍

MaxKB = Max Knowledge Base,是一款基于大语言模型和 RAG 的开源知识库问答系统,广泛应用于智能客服、企业内部知识库、学术研究与教育等场景。

本插件集成了 MaxKB 的 api,可以很方便地调用 MaxKB 的接口。

标识

调用插件的时候需要用到标识,标识是唯一的,不能重复,建议使用英文,不要使用中文,对应插件 plugin.json 中的 key 字段

  • 标识:maxKB

配置

{
  "baseUrl": "maxKB 服务地址,http://xxxxxx/api",
  "apiKey": "应用 apiKey",
  "appId": "应用 Id",
  "timeout": "请求超时设置,单位毫秒,默认 120000"
}

方法

下面是插件提供的一些方法

  • getProfile
  /**
   * 获取应用信息
   * @returns 
   */
  async getProfile()
  • getChatId
   /**
   * 获取会话 ID
   * @param appId 应用ID
   * @returns 
   */
  async getChatId(appId?:string)
  • chat
  /**
   * 对话
   * @param options 
   * @returns 
   */
  async chat(options:ChatOptions)

数据类型

// 聊天传参
type ChatOptions = {
  message: string; // 信息体
  appId?: string; // 应用ID
  chatId?: string; // 会话ID
  reChat: boolean; // 是否重新会话 默认:false
  stream?: boolean; // 是否流式 默认:true
  onData?: (data:any)=>void; // 获取数据回调
  onEnd?: ()=>void; // 结束回调
  onError?: (error:any)=>void; // 错误回调
  onAborted?: () => void; // 中止回调
}

调用示例

以工作流为例

@Inject()
pluginService: PluginService;

// 获取插件实例
const instance = await this.pluginService.getInstance('maxKB');

// 非流式执行
await instance.chat({
  message: "你好",
  stream: false,
  onData: (data) => {
    console.log('获取数据',data);
  }
})
// 流式执行
await instance.chat({
  message: "你好",
  onData: (data) => {
    console.log('获取数据',data);
  }
})

未来开发计划

  • 专业版 API 接入

更新日志

  • v1.0.0 (2025-01-17)
    • 初始版本