diff --git a/app/lib/enum.ts b/app/lib/enum.ts index a37bf73..51d7776 100644 --- a/app/lib/enum.ts +++ b/app/lib/enum.ts @@ -1,14 +1,14 @@ /** -* Copyright (c) 2023 - present TinyEngine Authors. -* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. -* -* Use of this source code is governed by an MIT-style license. -* -* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, -* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR -* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. -* -*/ + * Copyright (c) 2023 - present TinyEngine Authors. + * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. + * + * Use of this source code is governed by an MIT-style license. + * + * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, + * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR + * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. + * + */ // 请求method export enum E_Method { Get = 'GET', @@ -289,5 +289,6 @@ export enum E_Public { export enum E_FOUNDATION_MODEL { GPT_35_TURBO = 'gpt-3.5-turbo', // openai Local_GPT = 'loacl-compatible-gpt-3.5', //本地兼容opanai-api接口的 大语言模型,如chatGLM6b,通义千问 等。 - ERNIE_BOT_TURBO = 'ERNIE-Bot-turbo' // 文心一言 + ERNIE_BOT_TURBO = 'ERNIE-Bot-turbo', // 文心一言 + MOONSHOT_V1_8K = 'moonshot-v1-8k' // kimi } diff --git a/app/service/app-center/aiChat.ts b/app/service/app-center/aiChat.ts index 972499a..85d3edf 100644 --- a/app/service/app-center/aiChat.ts +++ b/app/service/app-center/aiChat.ts @@ -54,10 +54,8 @@ export default class AiChat extends Service { const { httpRequestUrl, httpRequestOption } = aiChatConfig[chatConfig.model]; this.ctx.logger.debug(httpRequestOption); res = await ctx.curl(httpRequestUrl, httpRequestOption); - } catch (e: any) { this.ctx.logger.debug(`调用AI大模型接口失败: ${(e as Error).message}`); - return this.ctx.helper.getResponseData(`调用AI大模型接口失败: ${(e as Error).message}`); } diff --git a/config/config.default.ts b/config/config.default.ts index c54f7ba..ac0d902 100644 --- a/config/config.default.ts +++ b/config/config.default.ts @@ -246,7 +246,7 @@ export default (appInfo) => { }; //ai大模型相关配置,请自行替换服务配置 - config.aiChat = (messages = [], accessToken: string) => { + config.aiChat = (messages = [], token: string) => { return { [E_FOUNDATION_MODEL.GPT_35_TURBO]: { httpRequestUrl: (process.env.OPENAI_API_URL || 'https://api.openai.com') + '/v1/chat/completions', @@ -278,7 +278,7 @@ export default (appInfo) => { manufacturer: '!openai' }, [E_FOUNDATION_MODEL.ERNIE_BOT_TURBO]: { - httpRequestUrl: `https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=${accessToken || process.env.WENXIN_ACCESS_TOKEN}`, + httpRequestUrl: `https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=${token || process.env.WENXIN_ACCESS_TOKEN}`, httpRequestOption: { ...commonRequestOption, data: { @@ -287,6 +287,20 @@ export default (appInfo) => { } }, manufacturer: 'baidu' + }, + [E_FOUNDATION_MODEL.MOONSHOT_V1_8K]: { + httpRequestUrl: `https://api.moonshot.cn/v1/chat/completions`, + httpRequestOption: { + ...commonRequestOption, + data: { + model: E_FOUNDATION_MODEL.MOONSHOT_V1_8K, + messages + }, + headers: { + Authorization: `Bearer ${token}` + } + }, + manufacturer: 'kimi' } }; };