UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

26 lines (18 loc) 1.05 kB
import { Md5 } from 'ts-md5'; import { PLUGIN_SCHEMA_API_MD5_PREFIX, PLUGIN_SCHEMA_SEPARATOR } from '@/const/plugin'; // OpenAI GPT function_call name can't be longer than 64 characters // So we need to use md5 to shorten the name export const genToolCallShortMD5Hash = (name: string) => Md5.hashStr(name).toString().slice(0, 16); export const genToolCallingName = (identifier: string, name: string, type: string = 'default') => { const pluginType = type && type !== 'default' ? `${PLUGIN_SCHEMA_SEPARATOR + type}` : ''; // 将插件的 identifier 作为前缀,避免重复 let apiName = identifier + PLUGIN_SCHEMA_SEPARATOR + name + pluginType; // OpenAI GPT function_call name can't be longer than 64 characters // So we need to use md5 to shorten the name // and then find the correct apiName in response by md5 if (apiName.length >= 64) { const md5Content = PLUGIN_SCHEMA_API_MD5_PREFIX + genToolCallShortMD5Hash(name); apiName = identifier + PLUGIN_SCHEMA_SEPARATOR + md5Content + pluginType; } return apiName; };