doomiaichat 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/azureai.js +1 -2
- package/dist/gptprovider.d.ts +1 -0
- package/dist/gptprovider.js +5 -1
- package/dist/openai.js +2 -7
- package/dist/stabilityai.d.ts +2 -0
- package/dist/stabilityai.js +1 -2
- package/dist/stabilityplusai.d.ts +7 -0
- package/dist/stabilityplusai.js +86 -0
- package/package.json +1 -1
- package/src/azureai.ts +1 -2
- package/src/gptprovider.ts +5 -1
- package/src/openai.ts +2 -8
- package/src/stabilityai.ts +3 -2
- package/src/stabilityplusai.ts +75 -0
package/dist/azureai.js
CHANGED
|
@@ -20,8 +20,7 @@ class AzureAI extends openai_1.default {
|
|
|
20
20
|
constructor(apiKey, azureOption, apiOption = {}) {
|
|
21
21
|
super(apiKey, apiOption);
|
|
22
22
|
this.azureSetting = azureOption;
|
|
23
|
-
if (!this.azureSetting.endpoint.toLowerCase().startsWith('https://')
|
|
24
|
-
!this.azureSetting.endpoint.toLowerCase().startsWith('https://')) {
|
|
23
|
+
if (!this.azureSetting.endpoint.toLowerCase().startsWith('https://')) {
|
|
25
24
|
this.azureSetting.endpoint = 'https://' + this.azureSetting.endpoint;
|
|
26
25
|
}
|
|
27
26
|
}
|
package/dist/gptprovider.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const GptProviderEnum: {
|
|
|
9
9
|
readonly BAIDU: "baidu";
|
|
10
10
|
readonly GOOGLE: "google";
|
|
11
11
|
readonly STABILITY: "stability";
|
|
12
|
+
readonly STABILITY2: "stability2";
|
|
12
13
|
};
|
|
13
14
|
export type GptProviderEnum = typeof GptProviderEnum[keyof typeof GptProviderEnum];
|
|
14
15
|
/**
|
package/dist/gptprovider.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.createGpt = exports.GptProviderEnum = void 0;
|
|
|
11
11
|
const openai_1 = __importDefault(require("./openai"));
|
|
12
12
|
const azureai_1 = __importDefault(require("./azureai"));
|
|
13
13
|
const stabilityai_1 = __importDefault(require("./stabilityai"));
|
|
14
|
+
const stabilityplusai_1 = __importDefault(require("./stabilityplusai"));
|
|
14
15
|
const baiduai_1 = __importDefault(require("./baiduai"));
|
|
15
16
|
/**
|
|
16
17
|
* OpenAI/NLP 的服务提供商 OpenAI,微软,百度文心(待接入),google(待接入)
|
|
@@ -20,7 +21,8 @@ exports.GptProviderEnum = {
|
|
|
20
21
|
MICROSOFT: 'microsoft',
|
|
21
22
|
BAIDU: 'baidu',
|
|
22
23
|
GOOGLE: 'google',
|
|
23
|
-
STABILITY: 'stability'
|
|
24
|
+
STABILITY: 'stability',
|
|
25
|
+
STABILITY2: 'stability2',
|
|
24
26
|
};
|
|
25
27
|
/**
|
|
26
28
|
* 根据类型创建不同的TTS引擎对象
|
|
@@ -41,6 +43,8 @@ function createGpt(provider, apikey, setting) {
|
|
|
41
43
|
return new baiduai_1.default(cred);
|
|
42
44
|
case exports.GptProviderEnum.STABILITY:
|
|
43
45
|
return new stabilityai_1.default(apikey + '', { endpoint, engine }, setting);
|
|
46
|
+
case exports.GptProviderEnum.STABILITY2:
|
|
47
|
+
return new stabilityplusai_1.default(apikey + '', { endpoint, engine }, setting);
|
|
44
48
|
default: return null;
|
|
45
49
|
}
|
|
46
50
|
}
|
package/dist/openai.js
CHANGED
|
@@ -471,12 +471,6 @@ class OpenAIGpt extends gptbase_1.default {
|
|
|
471
471
|
*/
|
|
472
472
|
pickUpQuestions(result, count, questiontype, score = 1) {
|
|
473
473
|
let answerString = result[0].message.content.trim().replace(/\t|\n|\v|\r|\f/g, '');
|
|
474
|
-
// const firstsybmol = answerString.indexOf("["); ////必须过滤出来数组
|
|
475
|
-
// const lastsybmol = answerString.lastIndexOf("]");
|
|
476
|
-
// console.log('answerString', answerString)
|
|
477
|
-
// if (firstsybmol < 0 || lastsybmol < 0 || lastsybmol <= firstsybmol) return [];
|
|
478
|
-
// answerString = answerString.substr(firstsybmol, lastsybmol - firstsybmol + 1);
|
|
479
|
-
// console.log('answerString', answerString)
|
|
480
474
|
let jsonObj = this.fixedJsonString(answerString);
|
|
481
475
|
if (!jsonObj.length)
|
|
482
476
|
return [];
|
|
@@ -516,7 +510,8 @@ class OpenAIGpt extends gptbase_1.default {
|
|
|
516
510
|
questionitem.answer = (questionitem.answer + '').replace(/,|[^ABCDEFG]/g, '').split('');
|
|
517
511
|
break;
|
|
518
512
|
case 'trueorfalse':
|
|
519
|
-
|
|
513
|
+
let rightItem = questionitem.choice.find((x) => { return x.iscorrect == 1; });
|
|
514
|
+
questionitem.answer = [(rightItem === null || rightItem === void 0 ? void 0 : rightItem.id) || 'Z']; //[(questionitem.answer + '').indexOf('正确') >= 0 ? 'A' : 'B']
|
|
520
515
|
break;
|
|
521
516
|
}
|
|
522
517
|
///单选题验证
|
package/dist/stabilityai.d.ts
CHANGED
package/dist/stabilityai.js
CHANGED
|
@@ -26,8 +26,7 @@ class StabilityAI extends gptbase_1.default {
|
|
|
26
26
|
this.apiKey = apiKey;
|
|
27
27
|
this.apiSetting = urlOption;
|
|
28
28
|
this.apiOption = apiOption;
|
|
29
|
-
if (!this.apiSetting.endpoint.toLowerCase().startsWith('
|
|
30
|
-
!this.apiSetting.endpoint.toLowerCase().startsWith('https://')) {
|
|
29
|
+
if (!this.apiSetting.endpoint.toLowerCase().startsWith('http')) {
|
|
31
30
|
this.apiSetting.endpoint = 'https://' + this.apiSetting.endpoint;
|
|
32
31
|
}
|
|
33
32
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import StabilityAI, { StabilityOption, StabilityResult } from "./stabilityai";
|
|
2
|
+
export default class StabilityPlusAI extends StabilityAI {
|
|
3
|
+
/**
|
|
4
|
+
* 请求Stable作画的接口
|
|
5
|
+
*/
|
|
6
|
+
chatRequest(chatText: string, paramOption: StabilityOption, axiosOption?: any): Promise<StabilityResult>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const declare_1 = require("./declare");
|
|
16
|
+
const stabilityai_1 = __importDefault(require("./stabilityai"));
|
|
17
|
+
class StabilityPlusAI extends stabilityai_1.default {
|
|
18
|
+
/**
|
|
19
|
+
* 请求Stable作画的接口
|
|
20
|
+
*/
|
|
21
|
+
chatRequest(chatText, paramOption, axiosOption = {}) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
if (!chatText)
|
|
24
|
+
return { successed: false, error: { errcode: 2, errmsg: '缺失聊天的内容' } };
|
|
25
|
+
axiosOption = Object.assign({}, axiosOption, {
|
|
26
|
+
headers: {
|
|
27
|
+
"Content-Type": "application/json",
|
|
28
|
+
"Accept": "application/json",
|
|
29
|
+
// "Authorization": `Bearer ${this.apiKey}`
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
let param = Object.assign(Object.assign({}, axiosOption), { method: "post", url: `${this.apiSetting.endpoint}/sdapi/v1/txt2img`, data: {
|
|
34
|
+
"enable_hr": false,
|
|
35
|
+
"denoising_strength": 0,
|
|
36
|
+
"firstphase_width": 0,
|
|
37
|
+
"firstphase_height": 0,
|
|
38
|
+
"hr_scale": 2,
|
|
39
|
+
"hr_upscaler": "string",
|
|
40
|
+
"hr_second_pass_steps": 0,
|
|
41
|
+
"hr_resize_x": 0,
|
|
42
|
+
"hr_resize_y": 0,
|
|
43
|
+
"prompt": chatText,
|
|
44
|
+
"styles": [this.apiSetting.engine || "bra_v5"],
|
|
45
|
+
"seed": -1,
|
|
46
|
+
"subseed": -1,
|
|
47
|
+
"subseed_strength": 0,
|
|
48
|
+
"seed_resize_from_h": -1,
|
|
49
|
+
"seed_resize_from_w": -1,
|
|
50
|
+
"sampler_name": paramOption.sampler || this.apiOption.sampler || "Euler",
|
|
51
|
+
"batch_size": 1,
|
|
52
|
+
"n_iter": paramOption.samples || this.apiOption.samples || 1,
|
|
53
|
+
"steps": 50,
|
|
54
|
+
"cfg_scale": paramOption.cfg_scale || this.apiOption.cfg_scale || 7,
|
|
55
|
+
"width": paramOption.width || this.apiOption.width || 512,
|
|
56
|
+
"height": paramOption.height || this.apiOption.height || 512,
|
|
57
|
+
"restore_faces": false,
|
|
58
|
+
"tiling": false,
|
|
59
|
+
"do_not_save_samples": false,
|
|
60
|
+
"do_not_save_grid": false,
|
|
61
|
+
"negative_prompt": paramOption.negative || '',
|
|
62
|
+
// "eta": 0,
|
|
63
|
+
// "s_churn": 0,
|
|
64
|
+
// "s_tmax": 0,
|
|
65
|
+
// "s_tmin": 0,
|
|
66
|
+
// "s_noise": 1,
|
|
67
|
+
// "script_args": [],
|
|
68
|
+
// "sampler_index": paramOption.sampler || this.apiOption.sampler || "Euler", //"Euler",
|
|
69
|
+
// "send_images": true,
|
|
70
|
+
// "save_images": false,
|
|
71
|
+
// "alwayson_scripts": {}
|
|
72
|
+
} });
|
|
73
|
+
const response = yield (0, declare_1.request)(param);
|
|
74
|
+
if (response.successed) {
|
|
75
|
+
return { successed: true, type: 'image', data: response.data.images, };
|
|
76
|
+
}
|
|
77
|
+
return Object.assign({ successed: false }, response.data);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.log('result is error ', error);
|
|
81
|
+
return { successed: false, error };
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.default = StabilityPlusAI;
|
package/package.json
CHANGED
package/src/azureai.ts
CHANGED
|
@@ -7,8 +7,7 @@ export default class AzureAI extends OpenAIGpt {
|
|
|
7
7
|
constructor(apiKey: string, azureOption: AzureOpenAIPatameters, apiOption: OpenAIApiParameters = {}) {
|
|
8
8
|
super(apiKey, apiOption);
|
|
9
9
|
this.azureSetting = azureOption;
|
|
10
|
-
if (!this.azureSetting.endpoint.toLowerCase().startsWith('https://')
|
|
11
|
-
!this.azureSetting.endpoint.toLowerCase().startsWith('https://')) {
|
|
10
|
+
if (!this.azureSetting.endpoint.toLowerCase().startsWith('https://')) {
|
|
12
11
|
this.azureSetting.endpoint = 'https://' + this.azureSetting.endpoint;
|
|
13
12
|
}
|
|
14
13
|
}
|
package/src/gptprovider.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import OpenAIGpt from './openai';
|
|
6
6
|
import AzureAI from './azureai'
|
|
7
7
|
import StabilityAI from './stabilityai'
|
|
8
|
+
import StabilityPlusAI from './stabilityplusai'
|
|
8
9
|
import BaiduWenXinAI, { ApiCredential } from './baiduai'
|
|
9
10
|
import GptBase from './gptbase';
|
|
10
11
|
/**
|
|
@@ -15,7 +16,8 @@ export const GptProviderEnum = {
|
|
|
15
16
|
MICROSOFT: 'microsoft',
|
|
16
17
|
BAIDU: 'baidu',
|
|
17
18
|
GOOGLE:'google',
|
|
18
|
-
STABILITY:'stability'
|
|
19
|
+
STABILITY:'stability',
|
|
20
|
+
STABILITY2: 'stability2',
|
|
19
21
|
} as const;
|
|
20
22
|
export type GptProviderEnum = typeof GptProviderEnum[keyof typeof GptProviderEnum];
|
|
21
23
|
/**
|
|
@@ -37,6 +39,8 @@ export function createGpt(provider: GptProviderEnum, apikey: string|ApiCredentia
|
|
|
37
39
|
return new BaiduWenXinAI(cred);
|
|
38
40
|
case GptProviderEnum.STABILITY:
|
|
39
41
|
return new StabilityAI(apikey + '', { endpoint, engine }, setting);
|
|
42
|
+
case GptProviderEnum.STABILITY2:
|
|
43
|
+
return new StabilityPlusAI(apikey + '', { endpoint, engine }, setting);
|
|
40
44
|
default: return null;
|
|
41
45
|
}
|
|
42
46
|
};
|
package/src/openai.ts
CHANGED
|
@@ -441,13 +441,6 @@ export default class OpenAIGpt extends GptBase {
|
|
|
441
441
|
*/
|
|
442
442
|
protected pickUpQuestions(result: Array<any>, count: number, questiontype: string, score: number = 1): Array<QuestionItem> {
|
|
443
443
|
let answerString = result[0].message.content.trim().replace(/\t|\n|\v|\r|\f/g, '');
|
|
444
|
-
// const firstsybmol = answerString.indexOf("["); ////必须过滤出来数组
|
|
445
|
-
// const lastsybmol = answerString.lastIndexOf("]");
|
|
446
|
-
|
|
447
|
-
// console.log('answerString', answerString)
|
|
448
|
-
// if (firstsybmol < 0 || lastsybmol < 0 || lastsybmol <= firstsybmol) return [];
|
|
449
|
-
// answerString = answerString.substr(firstsybmol, lastsybmol - firstsybmol + 1);
|
|
450
|
-
// console.log('answerString', answerString)
|
|
451
444
|
let jsonObj = this.fixedJsonString(answerString);
|
|
452
445
|
if (!jsonObj.length) return []
|
|
453
446
|
let returnItems: QuestionItem[] = [];
|
|
@@ -487,7 +480,8 @@ export default class OpenAIGpt extends GptBase {
|
|
|
487
480
|
questionitem.answer = (questionitem.answer + '').replace(/,|[^ABCDEFG]/g, '').split('');
|
|
488
481
|
break;
|
|
489
482
|
case 'trueorfalse':
|
|
490
|
-
|
|
483
|
+
let rightItem = questionitem.choice.find((x: any) => { return x.iscorrect == 1 });
|
|
484
|
+
questionitem.answer = [rightItem?.id || 'Z'] ; //[(questionitem.answer + '').indexOf('正确') >= 0 ? 'A' : 'B']
|
|
491
485
|
break;
|
|
492
486
|
}
|
|
493
487
|
///单选题验证
|
package/src/stabilityai.ts
CHANGED
|
@@ -16,8 +16,7 @@ export default class StabilityAI extends GptBase {
|
|
|
16
16
|
this.apiKey = apiKey;
|
|
17
17
|
this.apiSetting = urlOption;
|
|
18
18
|
this.apiOption = apiOption;
|
|
19
|
-
if (!this.apiSetting.endpoint.toLowerCase().startsWith('
|
|
20
|
-
!this.apiSetting.endpoint.toLowerCase().startsWith('https://')) {
|
|
19
|
+
if (!this.apiSetting.endpoint.toLowerCase().startsWith('http')) {
|
|
21
20
|
this.apiSetting.endpoint = 'https://' + this.apiSetting.endpoint;
|
|
22
21
|
}
|
|
23
22
|
}
|
|
@@ -74,6 +73,8 @@ export interface StabilityOption {
|
|
|
74
73
|
'width'?: number,
|
|
75
74
|
'samples'?: number,
|
|
76
75
|
'steps'?: number,
|
|
76
|
+
'sampler'?:string,
|
|
77
|
+
'negative'?:string
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
export interface StabilityResult extends ApiResult {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
import { request } from "./declare";
|
|
3
|
+
import StabilityAI, { StabilityOption, StabilityResult } from "./stabilityai"
|
|
4
|
+
export default class StabilityPlusAI extends StabilityAI {
|
|
5
|
+
/**
|
|
6
|
+
* 请求Stable作画的接口
|
|
7
|
+
*/
|
|
8
|
+
public override async chatRequest(chatText: string, paramOption: StabilityOption, axiosOption: any = {}): Promise<StabilityResult> {
|
|
9
|
+
if (!chatText) return { successed: false, error: { errcode: 2, errmsg: '缺失聊天的内容' } };
|
|
10
|
+
axiosOption = Object.assign({}, axiosOption, {
|
|
11
|
+
headers: {
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"Accept": "application/json",
|
|
14
|
+
// "Authorization": `Bearer ${this.apiKey}`
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
try {
|
|
18
|
+
let param = {
|
|
19
|
+
...axiosOption,
|
|
20
|
+
method: "post",
|
|
21
|
+
url: `${this.apiSetting.endpoint}/sdapi/v1/txt2img`,
|
|
22
|
+
data: {
|
|
23
|
+
"enable_hr": false,
|
|
24
|
+
"denoising_strength": 0,
|
|
25
|
+
"firstphase_width": 0,
|
|
26
|
+
"firstphase_height": 0,
|
|
27
|
+
"hr_scale": 2,
|
|
28
|
+
"hr_upscaler": "string",
|
|
29
|
+
"hr_second_pass_steps": 0,
|
|
30
|
+
"hr_resize_x": 0,
|
|
31
|
+
"hr_resize_y": 0,
|
|
32
|
+
"prompt": chatText,
|
|
33
|
+
"styles": [this.apiSetting.engine || "bra_v5"], //["bra_v5"], //模型
|
|
34
|
+
"seed": -1,
|
|
35
|
+
"subseed": -1,
|
|
36
|
+
"subseed_strength": 0,
|
|
37
|
+
"seed_resize_from_h": -1,
|
|
38
|
+
"seed_resize_from_w": -1,
|
|
39
|
+
"sampler_name": paramOption.sampler || this.apiOption.sampler || "Euler", //"Euler",
|
|
40
|
+
"batch_size": 1,
|
|
41
|
+
"n_iter": paramOption.samples || this.apiOption.samples || 1, //生成的数量
|
|
42
|
+
"steps": 50,
|
|
43
|
+
"cfg_scale": paramOption.cfg_scale || this.apiOption.cfg_scale || 7,
|
|
44
|
+
"width": paramOption.width || this.apiOption.width || 512,
|
|
45
|
+
"height": paramOption.height || this.apiOption.height || 512,
|
|
46
|
+
"restore_faces": false,
|
|
47
|
+
"tiling": false,
|
|
48
|
+
"do_not_save_samples": false,
|
|
49
|
+
"do_not_save_grid": false,
|
|
50
|
+
"negative_prompt": paramOption.negative || '',
|
|
51
|
+
// "eta": 0,
|
|
52
|
+
// "s_churn": 0,
|
|
53
|
+
// "s_tmax": 0,
|
|
54
|
+
// "s_tmin": 0,
|
|
55
|
+
// "s_noise": 1,
|
|
56
|
+
// "script_args": [],
|
|
57
|
+
// "sampler_index": paramOption.sampler || this.apiOption.sampler || "Euler", //"Euler",
|
|
58
|
+
// "send_images": true,
|
|
59
|
+
// "save_images": false,
|
|
60
|
+
// "alwayson_scripts": {}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
};
|
|
64
|
+
const response: any = await request(param)
|
|
65
|
+
if (response.successed) {
|
|
66
|
+
return { successed: true, type: 'image', data: response.data.images, };
|
|
67
|
+
}
|
|
68
|
+
return { successed: false, ...response.data };
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.log('result is error ', error)
|
|
71
|
+
return { successed: false, error };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
}
|