Skip to content

Commit

Permalink
Feat. Add custom url support
Browse files Browse the repository at this point in the history
  • Loading branch information
HydroGest committed Jul 23, 2024
1 parent a56c829 commit 8977665
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 26 additions & 1 deletion src/utils/api-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function run(
},
{
role: "assistant",
content: "Resolved OK",
content: "Resolve OK",
},
{
role: "user",
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit 8977665

Please sign in to comment.