From 6ec1ca54e170b27a56ad7eb439480c733325543c Mon Sep 17 00:00:00 2001 From: "quemingyi.wudong" Date: Mon, 28 Apr 2025 19:32:59 +0800 Subject: [PATCH] feat: support ark bot & fix function call type --- src/config/common.ts | 20 ++++++++++++-------- src/config/config.ts | 37 +++++++++++++++++++++++++++++++++++++ src/utils/handler.ts | 4 +--- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/config/common.ts b/src/config/common.ts index fa53073..5cd5cc1 100644 --- a/src/config/common.ts +++ b/src/config/common.ts @@ -87,7 +87,7 @@ export enum AI_MODEL { DOUBAO_PRO_32K = 'Doubao-pro-32k', DOUBAO_PRO_128K = 'Doubao-pro-128k', VISION = 'Vision', - // VISION2 = 'ArkVLM', + ARK_BOT = 'ArkBot', } /** @@ -107,26 +107,30 @@ export const AI_MODE_MAP: Partial> = { [AI_MODEL.DOUBAO_PRO_32K]: AI_MODEL_MODE.ARK_V3, [AI_MODEL.DOUBAO_PRO_128K]: AI_MODEL_MODE.ARK_V3, [AI_MODEL.VISION]: AI_MODEL_MODE.ARK_V3, + [AI_MODEL.ARK_BOT]: AI_MODEL_MODE.ARK_V3, }; /** - * @brief 豆包模型的 ID + * @brief 方舟模型的 ID * @note 具体的模型 ID 请至 https://console.volcengine.com/ark/region:ark+cn-beijing/endpoint?config=%7B%7D&s=g 参看/创建 * 模型 ID 即接入点 ID, 在上述链接中表格内 "接入点名称" 列中, 类似于 "ep-2024xxxxxx-xxx" 格式即是模型 ID。 */ export const ARK_V3_MODEL_ID: Partial> = { - [AI_MODEL.DOUBAO_LITE_4K]: '************** 此处填充方舟上的模型 ID *************', - [AI_MODEL.DOUBAO_PRO_4K]: '************** 此处填充方舟上的模型 ID *************', - [AI_MODEL.DOUBAO_PRO_32K]: '************** 此处填充方舟上的模型 ID *************', - [AI_MODEL.DOUBAO_PRO_128K]: '************** 此处填充方舟上的模型 ID *************', - [AI_MODEL.VISION]: '************** 此处填充方舟上的模型 ID *************', + [AI_MODEL.DOUBAO_LITE_4K]: '************** 此处填充方舟上的模型 ID *************', + [AI_MODEL.DOUBAO_PRO_4K]: '************** 此处填充方舟上的模型 ID *************', + [AI_MODEL.DOUBAO_PRO_32K]: '************** 此处填充方舟上的模型 ID *************', + [AI_MODEL.DOUBAO_PRO_128K]: '************** 此处填充方舟上的模型 ID *************', + [AI_MODEL.VISION]: '************** 此处填充方舟上的模型 ID *************', // ... 可根据所开通的模型进行扩充 }; /** - * @brief 豆包智能体 BotID + * @brief 方舟智能体 BotID + * @note 具体的智能体 ID 请至 https://console.volcengine.com/ark/region:ark+cn-beijing/assistant?s=g 参看/创建 + * Bot ID 即页面上的应用 ID, 类似于 "bot-2025xxxxxx-xxx" 格式即是应用 ID。 */ export const LLM_BOT_ID: Partial> = { + [AI_MODEL.ARK_BOT]: '************** 此处填充方舟上的 Bot ID *************', // ... 可根据所开通的模型进行扩充 }; diff --git a/src/config/config.ts b/src/config/config.ts index 21af3c1..2dd8ee6 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -16,6 +16,7 @@ import { AI_MODEL, AI_MODE_MAP, AI_MODEL_MODE, + LLM_BOT_ID, isVisionMode, } from '.'; @@ -137,7 +138,12 @@ export class ConfigFactory { get LLMConfig() { const params: Record = { Mode: AI_MODE_MAP[this.Model || ''] || AI_MODEL_MODE.CUSTOM, + /** + * @note EndPointId 与 BotId 不可同时填写,若同时填写,则 EndPointId 生效。 + * 当前仅支持自定义推理接入点,不支持预置推理接入点。 + */ EndPointId: ARK_V3_MODEL_ID[this.Model], + BotId: LLM_BOT_ID[this.Model], MaxTokens: 1024, Temperature: 0.1, TopP: 0.3, @@ -150,6 +156,37 @@ export class ConfigFactory { Url: this.Url, Feature: JSON.stringify({ Http: true }), }; + if (LLM_BOT_ID[this.Model]) { + /** + * @note 如果您配置了方舟智能体, 并且开启了 Function Call 能力, 需要传入 Tools 字段, 描述函数相关信息。 + * 相关配置可查看 https://www.volcengine.com/docs/6348/1404673?s=g#llmconfig%EF%BC%88%E7%81%AB%E5%B1%B1%E6%96%B9%E8%88%9F%E5%B9%B3%E5%8F%B0%EF%BC%89 + * 对应的调用定义于 src/utils/handler.ts 文件中, 可参考对应逻辑。 + */ + params.Tools = [ + { + type: 'function', + function: { + name: 'get_current_weather', + description: '获取给定地点的天气', + parameters: { + type: 'object', + properties: { + location: { + type: 'string', + description: '地理位置,比如北京市', + }, + unit: { + type: 'string', + description: '', + enum: ['摄氏度', '华氏度'], + }, + }, + required: ['location'], + }, + }, + }, + ]; + } if (isVisionMode(this.Model)) { params.VisionConfig = { Enable: true, diff --git a/src/utils/handler.ts b/src/utils/handler.ts index b232bf1..1b90428 100644 --- a/src/utils/handler.ts +++ b/src/utils/handler.ts @@ -19,7 +19,7 @@ export type AnyRecord = Record; export enum MESSAGE_TYPE { BRIEF = 'conv', SUBTITLE = 'subv', - FUNCTION_CALL = 'func', + FUNCTION_CALL = 'tool', } export enum AGENT_BRIEF { @@ -134,8 +134,6 @@ export const useMessageHandler = () => { console.log('[Function Call] - Called by sendUserBinaryMessage'); const map: Record = { getcurrentweather: '今天下雪, 最低气温零下10度', - musicplayer: '查询到李四的歌曲, 名称是千里之内', - sendmessage: '发送成功', }; RtcClient.engine.sendUserBinaryMessage(