V 2.2.6 增加了MJ的api
This commit is contained in:
+26
-3
@@ -4,6 +4,8 @@ import { DEFINE_STRING } from "../../define/define_string";
|
||||
import { define } from "../../define/define";
|
||||
let fspromises = require("fs").promises;
|
||||
import { gptDefine } from "../../define/gptDefine";
|
||||
import { apiUrl } from "../../define/api/apiUrlDefine";
|
||||
import { successMessage } from "../generalTools";
|
||||
|
||||
export class GPT {
|
||||
constructor(global) {
|
||||
@@ -255,6 +257,18 @@ export class GPT {
|
||||
gpt_key = this.global.config.gpt_key,
|
||||
gpt_model = this.global.config.gpt_model) {
|
||||
try {
|
||||
// 还有自定义的
|
||||
let all_options = (await this.GetGPTBusinessOption("all", (value) => value.gpt_url)).data;
|
||||
// 判断gpt_business 是不是一个http开头的
|
||||
if (!gpt_url.includes("http")) {
|
||||
// 获取对应Id的gpt_url
|
||||
let index = all_options.findIndex(item => item.value == gpt_url && item.gpt_url);
|
||||
if (index < 0) {
|
||||
throw new Error("获取GPT的服务商配置失败");
|
||||
}
|
||||
gpt_url = all_options[index].gpt_url;
|
||||
}
|
||||
|
||||
|
||||
let data = {
|
||||
"model": gpt_model,
|
||||
@@ -268,7 +282,8 @@ export class GPT {
|
||||
url: gpt_url,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${gpt_key}`,
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
"Accept": "application/json"
|
||||
},
|
||||
data: JSON.stringify(data)
|
||||
};
|
||||
@@ -317,8 +332,16 @@ export class GPT {
|
||||
* 获取GPT的服务商配置,默认的和自定义的
|
||||
* @returns
|
||||
*/
|
||||
async GetGPTBusinessOption(value) {
|
||||
return await gptDefine.getGptDataByTypeAndProperty(value, "gpt_options", []);
|
||||
async GetGPTBusinessOption(value, callback = null) {
|
||||
let res = await gptDefine.getGptDataByTypeAndProperty(value, "gpt_options", []);
|
||||
if (res.code == 0) {
|
||||
return res;
|
||||
} else {
|
||||
if (callback) {
|
||||
callback(res.data)
|
||||
}
|
||||
return successMessage(res.data)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user