doomiaichat 4.9.0 → 5.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/azureai.d.ts +1 -21
- package/dist/azureai.js +0 -95
- package/dist/declare.d.ts +0 -64
- package/dist/gptbase.d.ts +0 -47
- package/dist/gptbase.js +0 -47
- package/dist/openai.d.ts +1 -75
- package/dist/openai.js +15 -588
- package/package.json +1 -1
- package/src/azureai.ts +1 -95
- package/src/declare.ts +0 -69
- package/src/gptbase.ts +1 -48
- package/src/openai.ts +533 -561
package/dist/azureai.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpenAIApi } from "azure-openai";
|
|
2
|
-
import { AzureOpenAIPatameters,
|
|
2
|
+
import { AzureOpenAIPatameters, EmbeddingResult, OpenAIApiParameters } from "./declare";
|
|
3
3
|
import OpenAIGpt from "./openai";
|
|
4
4
|
export default class AzureAI extends OpenAIGpt {
|
|
5
5
|
protected readonly azureSetting: AzureOpenAIPatameters;
|
|
@@ -17,24 +17,4 @@ export default class AzureAI extends OpenAIGpt {
|
|
|
17
17
|
* @param text
|
|
18
18
|
*/
|
|
19
19
|
getTextEmbedding(text: string, axiosOption?: any): Promise<EmbeddingResult>;
|
|
20
|
-
/**
|
|
21
|
-
* 请求GPT接口
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* 流式的聊天模式
|
|
25
|
-
* @param chatText
|
|
26
|
-
* @param _paramOption
|
|
27
|
-
* @param axiosOption
|
|
28
|
-
*/
|
|
29
|
-
/**
|
|
30
|
-
* 获得一种内容的相似说法
|
|
31
|
-
* 微软的AI参数中已经没有了n的参数
|
|
32
|
-
* 比如:
|
|
33
|
-
* 你今年多大?
|
|
34
|
-
* 相似问法:您是哪一年出生的
|
|
35
|
-
* 您今年贵庚?
|
|
36
|
-
* @param {*} content
|
|
37
|
-
* @param {需要出来的数量} count
|
|
38
|
-
*/
|
|
39
|
-
getSimilarityContent(content: string, count?: number, axiosOption?: any): Promise<ChatReponse>;
|
|
40
20
|
}
|
package/dist/azureai.js
CHANGED
|
@@ -73,100 +73,5 @@ class AzureAI extends openai_1.default {
|
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
/**
|
|
77
|
-
* 请求GPT接口
|
|
78
|
-
*/
|
|
79
|
-
// public override async chatRequest(chatText: string | Array<any>, paramOption: OpenAIApiParameters, axiosOption: any = {}): Promise<ChatReponse> {
|
|
80
|
-
// if (!chatText) return { successed: false, error: { errcode: 2, errmsg: '缺失聊天的内容' } };
|
|
81
|
-
// // if (!axiosOption.headers)
|
|
82
|
-
// // axiosOption.headers = { 'api-key': this.apiKey, 'Content-Type': 'application/json' };
|
|
83
|
-
// // else {
|
|
84
|
-
// // axiosOption.headers['api-key'] = this.apiKey;
|
|
85
|
-
// // axiosOption.headers['Content-Type'] = 'application/json';
|
|
86
|
-
// // }
|
|
87
|
-
// if (!this.azureApi) {
|
|
88
|
-
// this.azureApi = this.createAzureAI(this.apiKey);
|
|
89
|
-
// }
|
|
90
|
-
// let messages: Array<ChatCompletionRequestMessage> = typeof (chatText) == 'string' ?
|
|
91
|
-
// [{ role: 'user', content: chatText }] : chatText;
|
|
92
|
-
// try {
|
|
93
|
-
// // let param = {
|
|
94
|
-
// // ...axiosOption,
|
|
95
|
-
// // method: "post",
|
|
96
|
-
// // data: {
|
|
97
|
-
// // messages,
|
|
98
|
-
// // temperature: Number(paramOption?.temperature || this.temperature),
|
|
99
|
-
// // max_tokens: Number(paramOption?.maxtoken || this.maxtoken),
|
|
100
|
-
// // },
|
|
101
|
-
// // url: this.BaseUrl
|
|
102
|
-
// // };
|
|
103
|
-
// // // console.log('axiosOption', param)
|
|
104
|
-
// // const response = await request(param)
|
|
105
|
-
// const response: any = await this.azureApi.createChatCompletion({
|
|
106
|
-
// model: this.azureSetting.engine,
|
|
107
|
-
// messages: messages,
|
|
108
|
-
// temperature: Number(paramOption?.temperature || this.temperature),
|
|
109
|
-
// max_tokens: Number(paramOption?.maxtoken || this.maxtoken),
|
|
110
|
-
// n: Number(paramOption?.replyCounts || 1) || 1
|
|
111
|
-
// }, axiosOption);
|
|
112
|
-
// console.log('response.data', JSON.stringify(response.data))
|
|
113
|
-
// if (response.data.choices) {
|
|
114
|
-
// return { successed: true, message: response.data.choices, usage: response.data.usage };
|
|
115
|
-
// }
|
|
116
|
-
// return { successed: false, ...response.data };
|
|
117
|
-
// } catch (error) {
|
|
118
|
-
// console.log('result is error ', error)
|
|
119
|
-
// return { successed: false, error };
|
|
120
|
-
// }
|
|
121
|
-
// }
|
|
122
|
-
/**
|
|
123
|
-
* 流式的聊天模式
|
|
124
|
-
* @param chatText
|
|
125
|
-
* @param _paramOption
|
|
126
|
-
* @param axiosOption
|
|
127
|
-
*/
|
|
128
|
-
/**
|
|
129
|
-
* 获得一种内容的相似说法
|
|
130
|
-
* 微软的AI参数中已经没有了n的参数
|
|
131
|
-
* 比如:
|
|
132
|
-
* 你今年多大?
|
|
133
|
-
* 相似问法:您是哪一年出生的
|
|
134
|
-
* 您今年贵庚?
|
|
135
|
-
* @param {*} content
|
|
136
|
-
* @param {需要出来的数量} count
|
|
137
|
-
*/
|
|
138
|
-
getSimilarityContent(content, count = 1, axiosOption = {}) {
|
|
139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
let chnReg = /([\u4e00-\u9fa5]|[\ufe30-\uffa0])/.test(content); ///检查源话是否含有中文内容
|
|
141
|
-
let engReg = /[a-zA-Z]/.test(content); ///检查源话是否含有英文内容
|
|
142
|
-
///如果源话是全中文,那么结果中不应该出来英文的相似说法,如果源话是全英文,则结果不能出现全中文的说法
|
|
143
|
-
let prefix = (!chnReg && engReg) ? `请用英文提供${count}句` : ((chnReg && !engReg) ? `请用中文提供${count}句` : `请提供${count}句`);
|
|
144
|
-
const text = `${prefix}与"${content}"意思相同的内容`;
|
|
145
|
-
const messages = [
|
|
146
|
-
{ role: 'system', content: '忘记我们的聊天,你现在是一名专业的语言大师' },
|
|
147
|
-
{ role: 'user', content: text },
|
|
148
|
-
{ role: 'user', content: '最终结果按照["意思相同语句","意思相同语句"]的JSON数组的格式输出。' } //如:"今天天气真好"的相同2句内容,输出结果为:["今天晴空万里无云","今天的天气适合出游"]。' },
|
|
149
|
-
];
|
|
150
|
-
let result = yield this.chatRequest(messages, {}, axiosOption);
|
|
151
|
-
if (!result.successed || !result.message)
|
|
152
|
-
return result;
|
|
153
|
-
let value = result.message[0].message.content.trim();
|
|
154
|
-
let replyJson = this.fixedJsonString(value);
|
|
155
|
-
///能够提取到内容
|
|
156
|
-
if (replyJson.length)
|
|
157
|
-
return { successed: true, message: replyJson };
|
|
158
|
-
///回答的内容非JSON格式,自己来提取算了
|
|
159
|
-
console.log('自己组装', value);
|
|
160
|
-
let sentences = value.split(/",|\n/g); ///用换行或",来割分文本内容
|
|
161
|
-
sentences = sentences.map((str) => {
|
|
162
|
-
return str.replace(/(\[|"|\]|\{|\})/g, '');
|
|
163
|
-
});
|
|
164
|
-
// let matched = value.match(/\d+分/g), score = 0;
|
|
165
|
-
// if (matched && matched.length) {
|
|
166
|
-
// score = Number(matched[0].replace('分', ''));
|
|
167
|
-
// }
|
|
168
|
-
return { successed: true, message: sentences };
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
76
|
}
|
|
172
77
|
exports.default = AzureAI;
|
package/dist/declare.d.ts
CHANGED
|
@@ -23,26 +23,6 @@ export interface ChatReponse extends ApiResult {
|
|
|
23
23
|
'message'?: Array<any>;
|
|
24
24
|
'usage'?: any;
|
|
25
25
|
}
|
|
26
|
-
export interface OutlineSummaryItem {
|
|
27
|
-
/**
|
|
28
|
-
* The name of the user in a multi-user chat
|
|
29
|
-
* @type {Array<any>}
|
|
30
|
-
* @memberof SummaryReponse
|
|
31
|
-
*/
|
|
32
|
-
'outline'?: string;
|
|
33
|
-
'summary'?: Array<string>;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 摘要信息
|
|
37
|
-
*/
|
|
38
|
-
export interface SummaryReponse extends ApiResult {
|
|
39
|
-
/**
|
|
40
|
-
* The name of the user in a multi-user chat
|
|
41
|
-
* @type {Array<any>}
|
|
42
|
-
* @memberof SummaryReponse
|
|
43
|
-
*/
|
|
44
|
-
'article'?: Array<OutlineSummaryItem>;
|
|
45
|
-
}
|
|
46
26
|
/**
|
|
47
27
|
* 调用OpenAI Api的参数约定
|
|
48
28
|
*/
|
|
@@ -62,56 +42,12 @@ export interface AzureOpenAIPatameters {
|
|
|
62
42
|
'embedding'?: string;
|
|
63
43
|
'version'?: string;
|
|
64
44
|
}
|
|
65
|
-
/**
|
|
66
|
-
* 调用OpenAI Api的参数约定
|
|
67
|
-
*/
|
|
68
|
-
export interface FaqItem {
|
|
69
|
-
'question': string;
|
|
70
|
-
'answer'?: string;
|
|
71
|
-
'keywords'?: Array<string>;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 调用OpenAI Api的参数约定
|
|
75
|
-
*/
|
|
76
|
-
export interface ExaminationPaperResult extends ApiResult {
|
|
77
|
-
'score': number;
|
|
78
|
-
'paper': any;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 调用OpenAI Api的参数约定
|
|
82
|
-
*/
|
|
83
|
-
export interface QuestionItem {
|
|
84
|
-
'question': string;
|
|
85
|
-
'fullanswer'?: string;
|
|
86
|
-
'answer'?: Array<string>;
|
|
87
|
-
'choice'?: any[];
|
|
88
|
-
'score'?: number;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 调用OpenAI Api的参数约定
|
|
92
|
-
*/
|
|
93
|
-
export interface SimilarityResult extends ApiResult {
|
|
94
|
-
'value'?: number;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 调用OpenAI Api的参数约定
|
|
98
|
-
*/
|
|
99
|
-
export interface CommentResult extends ApiResult {
|
|
100
|
-
'score'?: number;
|
|
101
|
-
'comment'?: string;
|
|
102
|
-
}
|
|
103
45
|
/**
|
|
104
46
|
* 调用OpenAI Api的向量约定
|
|
105
47
|
*/
|
|
106
48
|
export interface EmbeddingResult extends ApiResult {
|
|
107
49
|
'embedding'?: number[];
|
|
108
50
|
}
|
|
109
|
-
/**
|
|
110
|
-
* 调用OpenAI Api的参数约定
|
|
111
|
-
*/
|
|
112
|
-
export interface EmotionResult extends ApiResult {
|
|
113
|
-
'emotion'?: string;
|
|
114
|
-
}
|
|
115
51
|
/**
|
|
116
52
|
* 远程请求的返回
|
|
117
53
|
*/
|
package/dist/gptbase.d.ts
CHANGED
|
@@ -25,51 +25,4 @@ export default abstract class GptBase extends EventEmitter {
|
|
|
25
25
|
* @param axiosOption
|
|
26
26
|
*/
|
|
27
27
|
chatRequestInStream(_chatText: string | Array<any>, _paramOption: any, _attach?: any, _axiosOption?: any): any;
|
|
28
|
-
/**
|
|
29
|
-
* 点评问题回答的评价
|
|
30
|
-
* @param question 问题题干
|
|
31
|
-
* @param answer 回答内容
|
|
32
|
-
* @param axiosOption
|
|
33
|
-
*/
|
|
34
|
-
commentQuestionAnswer(_question: string, _answer: string, _axiosOption: any): any;
|
|
35
|
-
/**
|
|
36
|
-
* 获取句子的情感
|
|
37
|
-
* @param s1
|
|
38
|
-
* @param axiosOption
|
|
39
|
-
*/
|
|
40
|
-
getScentenceEmotional(_s1: string, _axiosOption: any): any;
|
|
41
|
-
/**
|
|
42
|
-
* 获取两段文本的相似度
|
|
43
|
-
* @param s1
|
|
44
|
-
* @param s2
|
|
45
|
-
* @param axiosOption
|
|
46
|
-
*/
|
|
47
|
-
getScentenseSimilarity(_s1: string, _s2: string, _axiosOption: any): any;
|
|
48
|
-
/**
|
|
49
|
-
* 获取一段文本的相似内容
|
|
50
|
-
* @param content
|
|
51
|
-
* @param count
|
|
52
|
-
* @param axiosOption
|
|
53
|
-
*/
|
|
54
|
-
getSimilarityContent(_content: string, _count: number, _axiosOption: any): any;
|
|
55
|
-
/**
|
|
56
|
-
* 获取内容的摘要
|
|
57
|
-
* @param content
|
|
58
|
-
* @param axiosOption
|
|
59
|
-
*/
|
|
60
|
-
getSummaryOfContent(_content: string | Array<any>, _axiosOption: any): any;
|
|
61
|
-
/**
|
|
62
|
-
* 从内容中提取问题和答案及管件子
|
|
63
|
-
* @param content
|
|
64
|
-
* @param count
|
|
65
|
-
* @param axiosOption
|
|
66
|
-
*/
|
|
67
|
-
generateQuestionsFromContent(_content: string, _count: number, _everyContentLength: number, _axiosOption: any): any;
|
|
68
|
-
/**
|
|
69
|
-
* 从内容中提取单选多选判断填空题
|
|
70
|
-
* @param content
|
|
71
|
-
* @param paperOption
|
|
72
|
-
* @param axiosOption
|
|
73
|
-
*/
|
|
74
|
-
generateExaminationPaperFromContent(_content: string, _paperOption: any, _everyContentLength: number, _axiosOption: any): any;
|
|
75
28
|
}
|
package/dist/gptbase.js
CHANGED
|
@@ -20,52 +20,5 @@ class GptBase extends events_1.EventEmitter {
|
|
|
20
20
|
* @param axiosOption
|
|
21
21
|
*/
|
|
22
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; }
|
|
70
23
|
}
|
|
71
24
|
exports.default = GptBase;
|
package/dist/openai.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAIApi } from "azure-openai";
|
|
2
2
|
import GptBase from "./gptbase";
|
|
3
|
-
import { OpenAIApiParameters, ChatReponse,
|
|
3
|
+
import { OpenAIApiParameters, ChatReponse, EmbeddingResult } from './declare';
|
|
4
4
|
export default class OpenAIGpt extends GptBase {
|
|
5
5
|
protected readonly apiKey: string;
|
|
6
6
|
protected aiApi: OpenAIApi | undefined;
|
|
@@ -35,78 +35,4 @@ export default class OpenAIGpt extends GptBase {
|
|
|
35
35
|
* @param axiosOption
|
|
36
36
|
*/
|
|
37
37
|
chatRequestInStream(chatText: string | Array<any>, callChatOption: OpenAIApiParameters, attach?: any, axiosOption?: any): Promise<any>;
|
|
38
|
-
/**
|
|
39
|
-
* 点评问题回答的评价
|
|
40
|
-
* @param question
|
|
41
|
-
* @param answer
|
|
42
|
-
* @param axiosOption
|
|
43
|
-
*/
|
|
44
|
-
commentQuestionAnswer(question: string, answer: string, axiosOption?: any): Promise<CommentResult>;
|
|
45
|
-
/**
|
|
46
|
-
* 判断一句话的表达情绪
|
|
47
|
-
* @param {*} s1
|
|
48
|
-
* @param {*} axiosOption
|
|
49
|
-
*/
|
|
50
|
-
getScentenceEmotional(s1: string, axiosOption?: any): Promise<EmotionResult>;
|
|
51
|
-
/**
|
|
52
|
-
* 获取两句话的相似度取值
|
|
53
|
-
* @param {*} s1
|
|
54
|
-
* @param {*} s2
|
|
55
|
-
*/
|
|
56
|
-
getScentenseSimilarity(s1: string, s2: string, axiosOption?: any): Promise<SimilarityResult>;
|
|
57
|
-
/**
|
|
58
|
-
* 获得一种内容的相似说法
|
|
59
|
-
* 比如:
|
|
60
|
-
* 你今年多大?
|
|
61
|
-
* 相似问法:您是哪一年出生的
|
|
62
|
-
* 您今年贵庚?
|
|
63
|
-
* @param {*} content
|
|
64
|
-
* @param {需要出来的数量} count
|
|
65
|
-
*/
|
|
66
|
-
getSimilarityContent(content: string, count?: number, axiosOption?: any): Promise<ChatReponse>;
|
|
67
|
-
/**
|
|
68
|
-
* 提取内容的中心思想摘要
|
|
69
|
-
* @param content
|
|
70
|
-
* @param axiosOption
|
|
71
|
-
*/
|
|
72
|
-
getSummaryOfContent(content: string | Array<any>, axiosOption?: any): Promise<SummaryReponse>;
|
|
73
|
-
/**
|
|
74
|
-
* 从指定的文本内容中生成相关的问答
|
|
75
|
-
* @param {*} content
|
|
76
|
-
* @param {*} count
|
|
77
|
-
* @param {*} axiosOption
|
|
78
|
-
* @returns
|
|
79
|
-
*/ generateQuestionsFromContent(content: string, count?: number, everyContentLength?: number, axiosOption?: any): Promise<ChatReponse>;
|
|
80
|
-
/**
|
|
81
|
-
* 解析Faq返回的问题
|
|
82
|
-
* @param {*} messages
|
|
83
|
-
* @returns
|
|
84
|
-
*/
|
|
85
|
-
protected pickUpFaqContent(messages: Array<any>): Promise<Array<FaqItem>>;
|
|
86
|
-
/**
|
|
87
|
-
* 从指定的文本内容中生成一张试卷
|
|
88
|
-
* @param {*} content
|
|
89
|
-
* @param {试卷的参数} paperOption
|
|
90
|
-
* totalscore: 试卷总分,默认100
|
|
91
|
-
* section: {type:[0,1,2,3]为单选、多选、判断、填空题型 count:生成多少道 score:本段分数}
|
|
92
|
-
* @param {*} axiosOption
|
|
93
|
-
* @returns
|
|
94
|
-
*/ generateExaminationPaperFromContent(content: string, paperOption?: any, everyContentLength?: number, axiosOption?: any): Promise<ExaminationPaperResult>;
|
|
95
|
-
/**
|
|
96
|
-
* 从答复中得到题目
|
|
97
|
-
* @param {*} result
|
|
98
|
-
*
|
|
99
|
-
*/
|
|
100
|
-
protected pickUpQuestions(result: Array<any>, count: number, questiontype: string, score?: number): Promise<Array<QuestionItem>>;
|
|
101
|
-
/**
|
|
102
|
-
* 验证JSON字符串是否是真正可转换为JSON的合法格式
|
|
103
|
-
* 这里只能做一个最简单的处理,就是用两端的符号
|
|
104
|
-
* @param jsonstr
|
|
105
|
-
*/
|
|
106
|
-
protected fixedJsonString(jsonstr: string): any[];
|
|
107
|
-
/**
|
|
108
|
-
* 将一段很长的文本,按1024长度来划分到多个中
|
|
109
|
-
* @param {*} content
|
|
110
|
-
*/
|
|
111
|
-
protected splitLongText(content: string, len?: number): string[];
|
|
112
38
|
}
|