doomiaichat 3.6.0 → 4.0.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/baiduai.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EmotionResult, SimilarityResult, ChatReponse, SummaryReponse, ExaminationPaperResult, ApiResult, CacheProvider, CommentResult } from "./declare";
1
+ import { ApiResult, CacheProvider } from "./declare";
2
2
  import GptBase from "./gptbase";
3
3
  export default class BaiduWenXinAI extends GptBase {
4
4
  protected credential: ApiCredential;
@@ -14,23 +14,10 @@ export default class BaiduWenXinAI extends GptBase {
14
14
  * 获取调用Api的Token
15
15
  */
16
16
  getAccessToken(): Promise<AccessTokenResult>;
17
- /**
18
- * 获得文字的向量
19
- * @param text
20
- */
21
- getTextEmbedding(_text: string, _axiosOption: any): Promise<any>;
22
17
  /**
23
18
  * 请求GPT接口
24
19
  */
25
20
  chatRequest(chatText: string | Array<any>, _paramOption: any, axiosOption?: any): Promise<ApiResult>;
26
- chatRequestInStream(_chatText: string | any[], _paramOption: any, _attach?: any, _axiosOption?: any): void;
27
- commentQuestionAnswer(_question: string, _answer: string, _axiosOption: any): Promise<CommentResult>;
28
- getScentenceEmotional(_s1: string, _axiosOption: any): Promise<EmotionResult>;
29
- getScentenseSimilarity(_s1: string, _s2: string, _axiosOption: any): Promise<SimilarityResult>;
30
- getSimilarityContent(_content: string, _count: number, _axiosOption: any): Promise<ChatReponse>;
31
- getSummaryOfContent(_content: string | any[], _axiosOption: any): Promise<SummaryReponse>;
32
- generateQuestionsFromContent(_content: string, _count: number, _axiosOption: any): Promise<ChatReponse>;
33
- generateExaminationPaperFromContent(_content: string, _paperOption: any, _axiosOption: any): Promise<ExaminationPaperResult>;
34
21
  }
35
22
  export interface AccessTokenResult extends ApiResult {
36
23
  'access_token'?: string;
package/dist/baiduai.js CHANGED
@@ -53,15 +53,6 @@ class BaiduWenXinAI extends gptbase_1.default {
53
53
  return { successed: false, error: tokenData.data.msg };
54
54
  });
55
55
  }
56
- /**
57
- * 获得文字的向量
58
- * @param text
59
- */
60
- getTextEmbedding(_text, _axiosOption) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- return null;
63
- });
64
- }
65
56
  /**
66
57
  * 请求GPT接口
67
58
  */
@@ -97,29 +88,5 @@ class BaiduWenXinAI extends gptbase_1.default {
97
88
  }
98
89
  });
99
90
  }
100
- chatRequestInStream(_chatText, _paramOption, _attach, _axiosOption) {
101
- throw new Error("Method not implemented.");
102
- }
103
- commentQuestionAnswer(_question, _answer, _axiosOption) {
104
- throw new Error("Method not implemented.");
105
- }
106
- getScentenceEmotional(_s1, _axiosOption) {
107
- throw new Error("Method not implemented.");
108
- }
109
- getScentenseSimilarity(_s1, _s2, _axiosOption) {
110
- throw new Error("Method not implemented.");
111
- }
112
- getSimilarityContent(_content, _count, _axiosOption) {
113
- throw new Error("Method not implemented.");
114
- }
115
- getSummaryOfContent(_content, _axiosOption) {
116
- throw new Error("Method not implemented.");
117
- }
118
- generateQuestionsFromContent(_content, _count, _axiosOption) {
119
- throw new Error("Method not implemented.");
120
- }
121
- generateExaminationPaperFromContent(_content, _paperOption, _axiosOption) {
122
- throw new Error("Method not implemented.");
123
- }
124
91
  }
125
92
  exports.default = BaiduWenXinAI;
package/dist/declare.js CHANGED
@@ -28,7 +28,7 @@ function request(opts = {}) {
28
28
  return { successed: true, data: result.data };
29
29
  }
30
30
  catch (err) {
31
- return { successed: false, error: err };
31
+ return { successed: false, error: err, data: err };
32
32
  }
33
33
  });
34
34
  }
package/dist/gptbase.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from "events";
3
- import { ChatReponse, SummaryReponse, ExaminationPaperResult, EmotionResult, SimilarityResult, ApiResult, CommentResult } from './declare';
3
+ import { ApiResult } from './declare';
4
4
  export default abstract class GptBase extends EventEmitter {
5
5
  /**
6
6
  * 构造函数
@@ -10,7 +10,7 @@ export default abstract class GptBase extends EventEmitter {
10
10
  * 获得文字的向量
11
11
  * @param text
12
12
  */
13
- abstract getTextEmbedding(text: string, axiosOption: any): Promise<any>;
13
+ getTextEmbedding(_text: string, _axiosOption: any): any;
14
14
  /**
15
15
  * 自由聊天模式
16
16
  * @param chatText
@@ -24,52 +24,52 @@ export default abstract class GptBase extends EventEmitter {
24
24
  * @param _paramOption
25
25
  * @param axiosOption
26
26
  */
27
- abstract chatRequestInStream(chatText: string | Array<any>, _paramOption: any, attach?: any, axiosOption?: any): any;
27
+ chatRequestInStream(_chatText: string | Array<any>, _paramOption: any, _attach?: any, _axiosOption?: any): any;
28
28
  /**
29
29
  * 点评问题回答的评价
30
30
  * @param question 问题题干
31
31
  * @param answer 回答内容
32
32
  * @param axiosOption
33
33
  */
34
- abstract commentQuestionAnswer(question: string, answer: string, axiosOption: any): Promise<CommentResult>;
34
+ commentQuestionAnswer(_question: string, _answer: string, _axiosOption: any): any;
35
35
  /**
36
36
  * 获取句子的情感
37
37
  * @param s1
38
38
  * @param axiosOption
39
39
  */
40
- abstract getScentenceEmotional(s1: string, axiosOption: any): Promise<EmotionResult>;
40
+ getScentenceEmotional(_s1: string, _axiosOption: any): any;
41
41
  /**
42
42
  * 获取两段文本的相似度
43
43
  * @param s1
44
44
  * @param s2
45
45
  * @param axiosOption
46
46
  */
47
- abstract getScentenseSimilarity(s1: string, s2: string, axiosOption: any): Promise<SimilarityResult>;
47
+ getScentenseSimilarity(_s1: string, _s2: string, _axiosOption: any): any;
48
48
  /**
49
49
  * 获取一段文本的相似内容
50
50
  * @param content
51
51
  * @param count
52
52
  * @param axiosOption
53
53
  */
54
- abstract getSimilarityContent(content: string, count: number, axiosOption: any): Promise<ChatReponse>;
54
+ getSimilarityContent(_content: string, _count: number, _axiosOption: any): any;
55
55
  /**
56
56
  * 获取内容的摘要
57
57
  * @param content
58
58
  * @param axiosOption
59
59
  */
60
- abstract getSummaryOfContent(content: string | Array<any>, axiosOption: any): Promise<SummaryReponse>;
60
+ getSummaryOfContent(_content: string | Array<any>, _axiosOption: any): any;
61
61
  /**
62
62
  * 从内容中提取问题和答案及管件子
63
63
  * @param content
64
64
  * @param count
65
65
  * @param axiosOption
66
66
  */
67
- abstract generateQuestionsFromContent(content: string, count: number, everyContentLength: number, axiosOption: any): Promise<ChatReponse>;
67
+ generateQuestionsFromContent(_content: string, _count: number, _everyContentLength: number, _axiosOption: any): any;
68
68
  /**
69
69
  * 从内容中提取单选多选判断填空题
70
70
  * @param content
71
71
  * @param paperOption
72
72
  * @param axiosOption
73
73
  */
74
- abstract generateExaminationPaperFromContent(content: string, paperOption: any, everyContentLength: number, axiosOption: any): Promise<ExaminationPaperResult>;
74
+ generateExaminationPaperFromContent(_content: string, _paperOption: any, _everyContentLength: number, _axiosOption: any): any;
75
75
  }
package/dist/gptbase.js CHANGED
@@ -8,5 +8,64 @@ class GptBase extends events_1.EventEmitter {
8
8
  constructor() {
9
9
  super();
10
10
  }
11
+ /**
12
+ * 获得文字的向量
13
+ * @param text
14
+ */
15
+ getTextEmbedding(_text, _axiosOption) { return null; }
16
+ /**
17
+ * 流式的聊天模式
18
+ * @param chatText
19
+ * @param _paramOption
20
+ * @param axiosOption
21
+ */
22
+ chatRequestInStream(_chatText, _paramOption, _attach, _axiosOption) { return null; }
23
+ /**
24
+ * 点评问题回答的评价
25
+ * @param question 问题题干
26
+ * @param answer 回答内容
27
+ * @param axiosOption
28
+ */
29
+ commentQuestionAnswer(_question, _answer, _axiosOption) { return null; }
30
+ /**
31
+ * 获取句子的情感
32
+ * @param s1
33
+ * @param axiosOption
34
+ */
35
+ getScentenceEmotional(_s1, _axiosOption) { return null; }
36
+ /**
37
+ * 获取两段文本的相似度
38
+ * @param s1
39
+ * @param s2
40
+ * @param axiosOption
41
+ */
42
+ getScentenseSimilarity(_s1, _s2, _axiosOption) { return null; }
43
+ /**
44
+ * 获取一段文本的相似内容
45
+ * @param content
46
+ * @param count
47
+ * @param axiosOption
48
+ */
49
+ getSimilarityContent(_content, _count, _axiosOption) { return null; }
50
+ /**
51
+ * 获取内容的摘要
52
+ * @param content
53
+ * @param axiosOption
54
+ */
55
+ getSummaryOfContent(_content, _axiosOption) { return null; }
56
+ /**
57
+ * 从内容中提取问题和答案及管件子
58
+ * @param content
59
+ * @param count
60
+ * @param axiosOption
61
+ */
62
+ generateQuestionsFromContent(_content, _count, _everyContentLength, _axiosOption) { return null; }
63
+ /**
64
+ * 从内容中提取单选多选判断填空题
65
+ * @param content
66
+ * @param paperOption
67
+ * @param axiosOption
68
+ */
69
+ generateExaminationPaperFromContent(_content, _paperOption, _everyContentLength, _axiosOption) { return null; }
11
70
  }
12
71
  exports.default = GptBase;
@@ -8,6 +8,7 @@ export declare const GptProviderEnum: {
8
8
  readonly MICROSOFT: "microsoft";
9
9
  readonly BAIDU: "baidu";
10
10
  readonly GOOGLE: "google";
11
+ readonly STABILITY: "stability";
11
12
  };
12
13
  export type GptProviderEnum = typeof GptProviderEnum[keyof typeof GptProviderEnum];
13
14
  /**
@@ -10,6 +10,7 @@ exports.createGpt = exports.GptProviderEnum = void 0;
10
10
  */
11
11
  const openai_1 = __importDefault(require("./openai"));
12
12
  const azureai_1 = __importDefault(require("./azureai"));
13
+ const stabilityai_1 = __importDefault(require("./stabilityai"));
13
14
  const baiduai_1 = __importDefault(require("./baiduai"));
14
15
  /**
15
16
  * OpenAI/NLP 的服务提供商 OpenAI,微软,百度文心(待接入),google(待接入)
@@ -18,7 +19,8 @@ exports.GptProviderEnum = {
18
19
  OPENAI: 'openai',
19
20
  MICROSOFT: 'microsoft',
20
21
  BAIDU: 'baidu',
21
- GOOGLE: 'google'
22
+ GOOGLE: 'google',
23
+ STABILITY: 'stability'
22
24
  };
23
25
  /**
24
26
  * 根据类型创建不同的TTS引擎对象
@@ -37,6 +39,8 @@ function createGpt(provider, apikey, setting) {
37
39
  case exports.GptProviderEnum.BAIDU:
38
40
  let cred = typeof (apikey) === 'string' ? { apikey, securitykey: apikey } : apikey;
39
41
  return new baiduai_1.default(cred);
42
+ case exports.GptProviderEnum.STABILITY:
43
+ return new stabilityai_1.default(apikey + '', { endpoint, engine }, setting);
40
44
  default: return null;
41
45
  }
42
46
  }
@@ -0,0 +1,30 @@
1
+ import { ApiResult, AzureOpenAIPatameters } from "./declare";
2
+ import GptBase from "./gptbase";
3
+ export default class StabilityAI extends GptBase {
4
+ protected readonly apiKey: string;
5
+ protected readonly apiSetting: AzureOpenAIPatameters;
6
+ protected readonly apiOption: StabilityOption;
7
+ /**
8
+ *
9
+ * @param apiKey 调用OpenAI 的key
10
+ * @param azureOption 用作accesstoken的缓存
11
+ * @param apiOption 用作accesstoken的缓存
12
+ */
13
+ constructor(apiKey: string, urlOption: AzureOpenAIPatameters, apiOption?: StabilityOption);
14
+ /**
15
+ * 请求Stable作画的接口
16
+ */
17
+ chatRequest(chatText: string, paramOption: StabilityOption, axiosOption?: any): Promise<StabilityResult>;
18
+ }
19
+ export interface StabilityOption {
20
+ 'cfg_scale'?: number;
21
+ 'clip_guidance_preset'?: string;
22
+ 'height'?: number;
23
+ 'width'?: number;
24
+ 'samples'?: number;
25
+ 'steps'?: number;
26
+ }
27
+ export interface StabilityResult extends ApiResult {
28
+ 'data'?: any;
29
+ 'type'?: string;
30
+ }
@@ -0,0 +1,76 @@
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 gptbase_1 = __importDefault(require("./gptbase"));
17
+ class StabilityAI extends gptbase_1.default {
18
+ /**
19
+ *
20
+ * @param apiKey 调用OpenAI 的key
21
+ * @param azureOption 用作accesstoken的缓存
22
+ * @param apiOption 用作accesstoken的缓存
23
+ */
24
+ constructor(apiKey, urlOption, apiOption = {}) {
25
+ super();
26
+ this.apiKey = apiKey;
27
+ this.apiSetting = urlOption;
28
+ this.apiOption = apiOption;
29
+ if (!this.apiSetting.endpoint.toLowerCase().startsWith('https://') &&
30
+ !this.apiSetting.endpoint.toLowerCase().startsWith('https://')) {
31
+ this.apiSetting.endpoint = 'https://' + this.apiSetting.endpoint;
32
+ }
33
+ }
34
+ /**
35
+ * 请求Stable作画的接口
36
+ */
37
+ chatRequest(chatText, paramOption, axiosOption = {}) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (!chatText)
40
+ return { successed: false, error: { errcode: 2, errmsg: '缺失聊天的内容' } };
41
+ axiosOption = Object.assign({}, axiosOption, {
42
+ headers: {
43
+ "Content-Type": "application/json",
44
+ "Accept": "application/json",
45
+ "Authorization": `Bearer ${this.apiKey}`
46
+ }
47
+ });
48
+ try {
49
+ let param = Object.assign(Object.assign({}, axiosOption), { method: "post", url: `${this.apiSetting.endpoint}/v1/generation/${this.apiSetting.engine}/text-to-image`, data: {
50
+ text_prompts: [
51
+ {
52
+ text: chatText
53
+ }
54
+ ],
55
+ cfg_scale: paramOption.cfg_scale || this.apiOption.cfg_scale || 7,
56
+ clip_guidance_preset: paramOption.clip_guidance_preset || this.apiOption.clip_guidance_preset || "FAST_BLUE",
57
+ height: paramOption.height || this.apiOption.height || 512,
58
+ width: paramOption.width || this.apiOption.width || 512,
59
+ samples: paramOption.samples || this.apiOption.samples || 1,
60
+ steps: paramOption.steps || this.apiOption.steps || 30,
61
+ } });
62
+ const response = yield (0, declare_1.request)(param);
63
+ if (response.successed) {
64
+ let data = response.data;
65
+ return { successed: true, type: 'image', data: data.artifacts, };
66
+ }
67
+ return Object.assign({ successed: false }, response.data);
68
+ }
69
+ catch (error) {
70
+ console.log('result is error ', error);
71
+ return { successed: false, error };
72
+ }
73
+ });
74
+ }
75
+ }
76
+ exports.default = StabilityAI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "3.6.0",
3
+ "version": "4.0.0",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/baiduai.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EmotionResult, SimilarityResult, ChatReponse, SummaryReponse, ExaminationPaperResult, ApiResult, CacheProvider, request, CommentResult } from "./declare";
1
+ import { ApiResult, CacheProvider, request } from "./declare";
2
2
  import GptBase from "./gptbase"
3
3
  const TOKEN_CACHE_KEY = "key:_doomisoft:baiduwenxin:"
4
4
  export default class BaiduWenXinAI extends GptBase {
@@ -39,13 +39,7 @@ export default class BaiduWenXinAI extends GptBase {
39
39
  }
40
40
  return { successed: false, error: tokenData.data.msg }
41
41
  }
42
- /**
43
- * 获得文字的向量
44
- * @param text
45
- */
46
- async getTextEmbedding(_text: string, _axiosOption: any): Promise<any> {
47
- return null;
48
- }
42
+
49
43
  /**
50
44
  * 请求GPT接口
51
45
  */
@@ -82,32 +76,6 @@ export default class BaiduWenXinAI extends GptBase {
82
76
  }
83
77
 
84
78
  }
85
-
86
- chatRequestInStream(_chatText: string | any[], _paramOption: any,_attach?:any, _axiosOption?: any): void {
87
- throw new Error("Method not implemented.");
88
- }
89
- commentQuestionAnswer(_question: string, _answer: string, _axiosOption: any): Promise<CommentResult>{
90
- throw new Error("Method not implemented.");
91
- }
92
- getScentenceEmotional(_s1: string, _axiosOption: any): Promise<EmotionResult> {
93
- throw new Error("Method not implemented.");
94
- }
95
- getScentenseSimilarity(_s1: string, _s2: string, _axiosOption: any): Promise<SimilarityResult> {
96
- throw new Error("Method not implemented.");
97
- }
98
- getSimilarityContent(_content: string, _count: number, _axiosOption: any): Promise<ChatReponse> {
99
- throw new Error("Method not implemented.");
100
- }
101
- getSummaryOfContent(_content: string | any[], _axiosOption: any): Promise<SummaryReponse> {
102
- throw new Error("Method not implemented.");
103
- }
104
- generateQuestionsFromContent(_content: string, _count: number, _axiosOption: any): Promise<ChatReponse> {
105
- throw new Error("Method not implemented.");
106
- }
107
- generateExaminationPaperFromContent(_content: string, _paperOption: any, _axiosOption: any): Promise<ExaminationPaperResult> {
108
- throw new Error("Method not implemented.");
109
- }
110
-
111
79
  }
112
80
  export interface AccessTokenResult extends ApiResult {
113
81
  'access_token'?: string
package/src/declare.ts CHANGED
@@ -139,7 +139,7 @@ export async function request(opts: any = {}): Promise<RpcResult> {
139
139
  let result = await axios(opts);
140
140
  return { successed: true, data: result.data }
141
141
  } catch (err) {
142
- return { successed: false, error: err }
142
+ return { successed: false, error: err,data:err }
143
143
  }
144
144
  }
145
145
 
package/src/gptbase.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from "events"
2
- import { ChatReponse, SummaryReponse, ExaminationPaperResult, EmotionResult, SimilarityResult, ApiResult, CommentResult } from './declare'
2
+ import { ApiResult } from './declare'
3
3
 
4
4
  export default abstract class GptBase extends EventEmitter {
5
5
  /**
@@ -12,7 +12,7 @@ export default abstract class GptBase extends EventEmitter {
12
12
  * 获得文字的向量
13
13
  * @param text
14
14
  */
15
- abstract getTextEmbedding(text: string, axiosOption: any):Promise<any>;
15
+ getTextEmbedding(_text: string, _axiosOption: any):any {return null;}
16
16
  /**
17
17
  * 自由聊天模式
18
18
  * @param chatText
@@ -26,52 +26,52 @@ export default abstract class GptBase extends EventEmitter {
26
26
  * @param _paramOption
27
27
  * @param axiosOption
28
28
  */
29
- abstract chatRequestInStream(chatText: string | Array<any>, _paramOption: any,attach?:any, axiosOption?: any):any;
29
+ chatRequestInStream(_chatText: string | Array<any>, _paramOption: any, _attach?: any, _axiosOption?: any): any { return null; }
30
30
  /**
31
31
  * 点评问题回答的评价
32
32
  * @param question 问题题干
33
33
  * @param answer 回答内容
34
34
  * @param axiosOption
35
35
  */
36
- abstract commentQuestionAnswer(question: string, answer: string, axiosOption: any): Promise<CommentResult>;
36
+ commentQuestionAnswer(_question: string, _answer: string, _axiosOption: any): any { return null; }
37
37
  /**
38
38
  * 获取句子的情感
39
39
  * @param s1
40
40
  * @param axiosOption
41
41
  */
42
- abstract getScentenceEmotional(s1: string, axiosOption: any ): Promise<EmotionResult> ;
42
+ getScentenceEmotional(_s1: string, _axiosOption: any): any { return null; }
43
43
  /**
44
44
  * 获取两段文本的相似度
45
45
  * @param s1
46
46
  * @param s2
47
47
  * @param axiosOption
48
48
  */
49
- abstract getScentenseSimilarity(s1: string, s2: string, axiosOption: any): Promise<SimilarityResult>;
49
+ getScentenseSimilarity(_s1: string, _s2: string, _axiosOption: any): any { return null; }
50
50
  /**
51
51
  * 获取一段文本的相似内容
52
52
  * @param content
53
53
  * @param count
54
54
  * @param axiosOption
55
55
  */
56
- abstract getSimilarityContent(content: string, count: number, axiosOption: any): Promise<ChatReponse>;
56
+ getSimilarityContent(_content: string, _count: number, _axiosOption: any): any { return null; }
57
57
  /**
58
58
  * 获取内容的摘要
59
59
  * @param content
60
60
  * @param axiosOption
61
61
  */
62
- abstract getSummaryOfContent(content: string | Array<any>, axiosOption: any): Promise<SummaryReponse>;
62
+ getSummaryOfContent(_content: string | Array<any>, _axiosOption: any): any { return null; }
63
63
  /**
64
64
  * 从内容中提取问题和答案及管件子
65
65
  * @param content
66
66
  * @param count
67
67
  * @param axiosOption
68
68
  */
69
- abstract generateQuestionsFromContent(content: string, count: number, everyContentLength: number, axiosOption: any): Promise<ChatReponse>;
69
+ generateQuestionsFromContent(_content: string, _count: number, _everyContentLength: number, _axiosOption: any): any { return null; }
70
70
  /**
71
71
  * 从内容中提取单选多选判断填空题
72
72
  * @param content
73
73
  * @param paperOption
74
74
  * @param axiosOption
75
75
  */
76
- abstract generateExaminationPaperFromContent(content: string, paperOption: any, everyContentLength: number, axiosOption: any): Promise<ExaminationPaperResult>;
76
+ generateExaminationPaperFromContent(_content: string, _paperOption: any, _everyContentLength: number, _axiosOption: any): any { return null; }
77
77
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import OpenAIGpt from './openai';
6
6
  import AzureAI from './azureai'
7
+ import StabilityAI from './stabilityai'
7
8
  import BaiduWenXinAI, { ApiCredential } from './baiduai'
8
9
  import GptBase from './gptbase';
9
10
  /**
@@ -13,7 +14,8 @@ export const GptProviderEnum = {
13
14
  OPENAI: 'openai',
14
15
  MICROSOFT: 'microsoft',
15
16
  BAIDU: 'baidu',
16
- GOOGLE:'google'
17
+ GOOGLE:'google',
18
+ STABILITY:'stability'
17
19
  } as const;
18
20
  export type GptProviderEnum = typeof GptProviderEnum[keyof typeof GptProviderEnum];
19
21
  /**
@@ -33,6 +35,8 @@ export function createGpt(provider: GptProviderEnum, apikey: string|ApiCredentia
33
35
  case GptProviderEnum.BAIDU:
34
36
  let cred: ApiCredential = typeof (apikey) === 'string' ? { apikey, securitykey: apikey } : apikey
35
37
  return new BaiduWenXinAI(cred);
38
+ case GptProviderEnum.STABILITY:
39
+ return new StabilityAI(apikey + '', { endpoint, engine }, setting);
36
40
  default: return null;
37
41
  }
38
42
  };
package/src/openai.ts CHANGED
@@ -46,7 +46,7 @@ export default class OpenAIGpt extends GptBase {
46
46
  * 获得文字的向量
47
47
  * @param text
48
48
  */
49
- async getTextEmbedding(text: string, axiosOption: any): Promise<EmbeddingResult>{
49
+ override async getTextEmbedding(text: string, axiosOption: any): Promise<EmbeddingResult>{
50
50
  if (!text) return { successed: false, error: { errcode: 2, errmsg: 'content required' } };
51
51
  if (!this.aiApi) {
52
52
  this.aiApi = this.createOpenAI(this.apiKey);
@@ -97,7 +97,7 @@ export default class OpenAIGpt extends GptBase {
97
97
  * @param _paramOption
98
98
  * @param axiosOption
99
99
  */
100
- async chatRequestInStream(chatText: string | Array<any>, callChatOption: OpenAIApiParameters, attach?: any, axiosOption?: any):Promise<any>{
100
+ override async chatRequestInStream(chatText: string | Array<any>, callChatOption: OpenAIApiParameters, attach?: any, axiosOption?: any):Promise<any>{
101
101
  if (!chatText) this.emit('chaterror', { successed: false, error:'no text in chat'});
102
102
  if (!this.aiApi) {
103
103
  this.aiApi = this.createOpenAI(this.apiKey);
@@ -162,7 +162,7 @@ export default class OpenAIGpt extends GptBase {
162
162
  * @param answer
163
163
  * @param axiosOption
164
164
  */
165
- async commentQuestionAnswer(question: string, answer: string, axiosOption: any = { timeout: 30000 }): Promise<CommentResult>{
165
+ override async commentQuestionAnswer(question: string, answer: string, axiosOption: any = { timeout: 30000 }): Promise<CommentResult>{
166
166
  if (!question || !answer) return { successed: false, error: { errcode: 2, errmsg: '缺失参数' } }
167
167
  let message = [
168
168
  {role:'system',content:'你是一名专业的知识点评师。'},
@@ -192,7 +192,7 @@ export default class OpenAIGpt extends GptBase {
192
192
  * @param {*} s1
193
193
  * @param {*} axiosOption
194
194
  */
195
- async getScentenceEmotional(s1: string, axiosOption: any = { timeout: 30000 }): Promise<EmotionResult> {
195
+ override async getScentenceEmotional(s1: string, axiosOption: any = { timeout: 30000 }): Promise<EmotionResult> {
196
196
  if (!s1) return { successed: false, error: { errcode: 2, errmsg: '缺失参数' } }
197
197
  const emotion = ['愤怒', '威胁', '讽刺', '愧疚', '兴奋', '友好', '消极', '生气', '正常'];
198
198
  const messages = [
@@ -215,7 +215,7 @@ export default class OpenAIGpt extends GptBase {
215
215
  * @param {*} s1
216
216
  * @param {*} s2
217
217
  */
218
- async getScentenseSimilarity(s1: string, s2: string, axiosOption: any = { timeout: 30000 }): Promise<SimilarityResult> {
218
+ override async getScentenseSimilarity(s1: string, s2: string, axiosOption: any = { timeout: 30000 }): Promise<SimilarityResult> {
219
219
  if (!s1 || !s2) return { successed: false, error: { errcode: 2, errmsg: '缺失参数' } }
220
220
  const messages = [
221
221
  { role: 'system', content: '你是一名专业的语言分析大师' },
@@ -243,7 +243,7 @@ export default class OpenAIGpt extends GptBase {
243
243
  * @param {*} content
244
244
  * @param {需要出来的数量} count
245
245
  */
246
- async getSimilarityContent(content: string, count: number = 1, axiosOption: any = {}): Promise<ChatReponse> {
246
+ override async getSimilarityContent(content: string, count: number = 1, axiosOption: any = {}): Promise<ChatReponse> {
247
247
  let chnReg: boolean = /([\u4e00-\u9fa5]|[\ufe30-\uffa0])/.test(content) ///检查源话是否含有中文内容
248
248
  let engReg: boolean = /[a-zA-Z]/.test(content) ///检查源话是否含有英文内容
249
249
  ///如果源话是全中文,那么结果中不应该出来英文的相似说法,如果源话是全英文,则结果不能出现全中文的说法
@@ -259,7 +259,7 @@ export default class OpenAIGpt extends GptBase {
259
259
  * @param content
260
260
  * @param axiosOption
261
261
  */
262
- async getSummaryOfContent(content: string | Array<any>, axiosOption: any = {}): Promise<SummaryReponse> {
262
+ override async getSummaryOfContent(content: string | Array<any>, axiosOption: any = {}): Promise<SummaryReponse> {
263
263
  const arrContent = typeof (content) == 'string' ? this.splitLongText(content) : content;
264
264
  let summary: Array<OutlineSummaryItem> = [];
265
265
  while (arrContent.length > 0) {
@@ -287,7 +287,7 @@ export default class OpenAIGpt extends GptBase {
287
287
  * @param {*} axiosOption
288
288
  * @returns
289
289
  *///并在答案末尾处必须给出答案内容中的关键词
290
- async generateQuestionsFromContent(content: string, count: number = 1, everyContentLength: number = SECTION_LENGTH, axiosOption: any = {}): Promise<ChatReponse> {
290
+ override async generateQuestionsFromContent(content: string, count: number = 1, everyContentLength: number = SECTION_LENGTH, axiosOption: any = {}): Promise<ChatReponse> {
291
291
  let arrContent = this.splitLongText(content, everyContentLength || SECTION_LENGTH);
292
292
  ///没20句话分为一组,适应大文件内容多次请求组合结果
293
293
  ///每一句话需要产生的题目
@@ -369,7 +369,7 @@ export default class OpenAIGpt extends GptBase {
369
369
  * @param {*} axiosOption
370
370
  * @returns
371
371
  *///并在答案末尾处必须给出答案内容中的关键词
372
- async generateExaminationPaperFromContent(content: string, paperOption: any = {}, everyContentLength: number = SECTION_LENGTH, axiosOption: any = {}): Promise<ExaminationPaperResult> {
372
+ override async generateExaminationPaperFromContent(content: string, paperOption: any = {}, everyContentLength: number = SECTION_LENGTH, axiosOption: any = {}): Promise<ExaminationPaperResult> {
373
373
  let arrContent = this.splitLongText(content, everyContentLength || SECTION_LENGTH);
374
374
  let sectionCount: any = {
375
375
  singlechoice: (paperOption.singlechoice?.count || 0) / arrContent.length,
@@ -0,0 +1,82 @@
1
+ import { ApiResult, request, AzureOpenAIPatameters } from "./declare";
2
+ import GptBase from "./gptbase"
3
+ export default class StabilityAI extends GptBase {
4
+
5
+ protected readonly apiKey: string;
6
+ protected readonly apiSetting: AzureOpenAIPatameters
7
+ protected readonly apiOption:StabilityOption;
8
+ /**
9
+ *
10
+ * @param apiKey 调用OpenAI 的key
11
+ * @param azureOption 用作accesstoken的缓存
12
+ * @param apiOption 用作accesstoken的缓存
13
+ */
14
+ constructor(apiKey: string, urlOption: AzureOpenAIPatameters, apiOption: StabilityOption = {}) {
15
+ super();
16
+ this.apiKey = apiKey;
17
+ this.apiSetting = urlOption;
18
+ this.apiOption = apiOption;
19
+ if (!this.apiSetting.endpoint.toLowerCase().startsWith('https://') &&
20
+ !this.apiSetting.endpoint.toLowerCase().startsWith('https://')) {
21
+ this.apiSetting.endpoint = 'https://' + this.apiSetting.endpoint;
22
+ }
23
+ }
24
+ /**
25
+ * 请求Stable作画的接口
26
+ */
27
+ public async chatRequest(chatText: string, paramOption: StabilityOption, axiosOption: any = {}): Promise<StabilityResult> {
28
+ if (!chatText) return { successed: false, error: { errcode: 2, errmsg: '缺失聊天的内容' } };
29
+ axiosOption = Object.assign({}, axiosOption,{
30
+ headers:{
31
+ "Content-Type": "application/json",
32
+ "Accept": "application/json",
33
+ "Authorization": `Bearer ${this.apiKey}`
34
+ }
35
+ })
36
+ try {
37
+ let param = {
38
+ ...axiosOption,
39
+ method: "post",
40
+ url: `${this.apiSetting.endpoint}/v1/generation/${this.apiSetting.engine}/text-to-image`,
41
+ data: {
42
+ text_prompts: [
43
+ {
44
+ text: chatText
45
+ }
46
+ ],
47
+ cfg_scale: paramOption.cfg_scale || this.apiOption.cfg_scale || 7,
48
+ clip_guidance_preset: paramOption.clip_guidance_preset || this.apiOption.clip_guidance_preset || "FAST_BLUE",
49
+ height: paramOption.height || this.apiOption.height || 512,
50
+ width: paramOption.width || this.apiOption.width || 512,
51
+ samples: paramOption.samples || this.apiOption.samples || 1,
52
+ steps: paramOption.steps || this.apiOption.steps || 30,
53
+ },
54
+
55
+ };
56
+ const response:any = await request(param)
57
+ if (response.successed) {
58
+ let data = response.data;
59
+ return { successed: true, type: 'image', data: data.artifacts, };
60
+ }
61
+ return { successed: false, ...response.data };
62
+ } catch (error) {
63
+ console.log('result is error ', error)
64
+ return { successed: false, error };
65
+ }
66
+
67
+ }
68
+ }
69
+
70
+ export interface StabilityOption {
71
+ 'cfg_scale'?: number,
72
+ 'clip_guidance_preset'?: string,
73
+ 'height'?: number,
74
+ 'width'?: number,
75
+ 'samples'?: number,
76
+ 'steps'?: number,
77
+ }
78
+
79
+ export interface StabilityResult extends ApiResult {
80
+ 'data'?:any;
81
+ 'type'?:string;
82
+ }