From 8977665e69ad117a0573d3e70d4deb333208aeaf Mon Sep 17 00:00:00 2001 From: HydroGest <2445691453> Date: Tue, 23 Jul 2024 18:46:42 +0800 Subject: [PATCH] Feat. Add custom url support --- package.json | 2 +- src/index.ts | 10 +++++++--- src/utils/api-adapter.ts | 27 ++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7bb7214..c957ee0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-yesimbot", "description": "Yes! I'm Bot! 机械壳,人类心", - "version": "1.1.6", + "version": "1.1.6-fix", "main": "lib/index.js", "typings": "lib/index.d.ts", "homepage": "https://github.com/HydroGest/YesImBot", diff --git a/src/index.ts b/src/index.ts index 3a39050..cd1e075 100644 --- a/src/index.ts +++ b/src/index.ts @@ -79,12 +79,12 @@ export const Config: Schema < Config > = Schema.object({ }).description("群聊设置"), API: Schema.object({ APIList: Schema.array(Schema.object({ - APIType: Schema.union(["OpenAI", "Cloudflare", "脑力计算"]).default("OpenAI").description( + APIType: Schema.union(["OpenAI", "Cloudflare", "Custom URL"]).default("OpenAI").description( "API 类型" ), BaseAPI: Schema.string() - .default("https://api.openai.com/v1/chat/completions/") - .description("API 基础URL"), + .default("https://api.openai.com/") + .description("API 基础URL, 设置为“Custom URL”需要填写完整的 URL"), UID: Schema.string() .default("若非 Cloudflare 可不填") .description("Cloudflare UID"), @@ -140,6 +140,10 @@ function handleResponse(APIType: string, input: any): string { res = input.choices[0].message.content; break; } + case "Custom URL": { + res = input.choices[0].message.content; + break; + } case "Cloudflare": { res = input.result.response; break; diff --git a/src/utils/api-adapter.ts b/src/utils/api-adapter.ts index 50611dd..3054832 100644 --- a/src/utils/api-adapter.ts +++ b/src/utils/api-adapter.ts @@ -23,7 +23,7 @@ export async function run( }, { role: "assistant", - content: "Resolved OK", + content: "Resolve OK", }, { role: "user", @@ -52,6 +52,31 @@ export async function run( }; break; } + + case "Custom URL": { + url = `${BaseAPI}/`; + requestBody = { + model: model, + messages: [ + { + role: "system", + content: SysInput, + }, + { + role: "assistant", + content: "Resolve OK", + }, + { + role: "user", + content: InfoInput, + }, + ], + temperature: 0.7, + max_tokens: 4096, + }; + break; + } + default: { throw new Error(`不支持的 API 类型: ${APIType}`);