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