doomiaichat 1.4.5 → 2.1.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 +14 -0
- package/dist/azureai.js +73 -0
- package/dist/declare.d.ts +99 -0
- package/dist/declare.js +2 -0
- package/dist/index.d.ts +1 -162
- package/dist/index.js +24 -360
- package/dist/openai.d.ts +94 -0
- package/dist/openai.js +496 -0
- package/dist/openaiprovider.d.ts +22 -0
- package/dist/openaiprovider.js +39 -0
- package/package.json +6 -3
- package/src/azureai.ts +65 -0
- package/src/declare.ts +105 -0
- package/src/index.ts +1 -429
- package/src/openai.ts +477 -0
- package/src/openaiprovider.ts +32 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AzureOpenAIPatameters, ChatReponse, OpenAIApiParameters } from "./declare";
|
|
2
|
+
import OpenAIGpt from "./openai";
|
|
3
|
+
export default class AzureAI extends OpenAIGpt {
|
|
4
|
+
protected readonly azureSetting: AzureOpenAIPatameters;
|
|
5
|
+
constructor(apiKey: string, azureOption: AzureOpenAIPatameters, apiOption?: OpenAIApiParameters);
|
|
6
|
+
/**
|
|
7
|
+
* ZAure OpenAI 最新的URL地址
|
|
8
|
+
*/
|
|
9
|
+
get BaseUrl(): string;
|
|
10
|
+
/**
|
|
11
|
+
* 请求GPT接口
|
|
12
|
+
*/
|
|
13
|
+
chatRequest(chatText: string | Array<any>, paramOption: OpenAIApiParameters, axiosOption?: any): Promise<ChatReponse>;
|
|
14
|
+
}
|
package/dist/azureai.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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 axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const openai_1 = __importDefault(require("./openai"));
|
|
17
|
+
class AzureAI extends openai_1.default {
|
|
18
|
+
constructor(apiKey, azureOption, apiOption = {}) {
|
|
19
|
+
super(apiKey, apiOption);
|
|
20
|
+
this.azureSetting = azureOption;
|
|
21
|
+
if (!this.azureSetting.endpoint.toLowerCase().startsWith('https://') &&
|
|
22
|
+
!this.azureSetting.endpoint.toLowerCase().startsWith('https://')) {
|
|
23
|
+
this.azureSetting.endpoint = 'https://' + this.azureSetting.endpoint;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* ZAure OpenAI 最新的URL地址
|
|
28
|
+
*/
|
|
29
|
+
get BaseUrl() {
|
|
30
|
+
return `${this.azureSetting.endpoint}/openai/deployments/${this.azureSetting.engine}/chat/completions?api-version=${this.azureSetting.version || '2023-03-15-preview'}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 请求GPT接口
|
|
34
|
+
*/
|
|
35
|
+
chatRequest(chatText, paramOption, axiosOption = {}) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (!chatText)
|
|
38
|
+
return { successed: false, error: { errcode: 2, errmsg: '缺失聊天的内容' } };
|
|
39
|
+
if (!axiosOption.headers)
|
|
40
|
+
axiosOption.headers = { 'api-key': this.apiKey, 'Content-Type': 'application/json' };
|
|
41
|
+
else {
|
|
42
|
+
axiosOption.headers['api-key'] = this.apiKey;
|
|
43
|
+
axiosOption.headers['Content-Type'] = 'application/json';
|
|
44
|
+
}
|
|
45
|
+
let messages = typeof (chatText) == 'string' ?
|
|
46
|
+
[{ role: 'user', content: chatText }] : chatText;
|
|
47
|
+
//let axios = new Axios(axiosOption)
|
|
48
|
+
try {
|
|
49
|
+
// const response = await axios.post(this.BaseUrl, {
|
|
50
|
+
// messages,
|
|
51
|
+
// temperature: Number(paramOption?.temperature || this.temperature),
|
|
52
|
+
// max_tokens: Number(paramOption?.maxtoken || this.maxtoken),
|
|
53
|
+
// })
|
|
54
|
+
let param = Object.assign(Object.assign({}, axiosOption), { method: "post", data: {
|
|
55
|
+
messages,
|
|
56
|
+
temperature: Number((paramOption === null || paramOption === void 0 ? void 0 : paramOption.temperature) || this.temperature),
|
|
57
|
+
max_tokens: Number((paramOption === null || paramOption === void 0 ? void 0 : paramOption.maxtoken) || this.maxtoken),
|
|
58
|
+
}, url: this.BaseUrl });
|
|
59
|
+
console.log('axiosOption', param);
|
|
60
|
+
const response = yield (0, axios_1.default)(param);
|
|
61
|
+
if (response.data.choices) {
|
|
62
|
+
return { successed: true, message: response.data.choices };
|
|
63
|
+
}
|
|
64
|
+
return Object.assign({ successed: false }, response.data);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.log('result is error ', error);
|
|
68
|
+
return { successed: false, error };
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.default = AzureAI;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
interface ApiResult {
|
|
2
|
+
/**
|
|
3
|
+
* return the result of api called
|
|
4
|
+
* @type {boolean}
|
|
5
|
+
*/
|
|
6
|
+
'successed': boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The error info
|
|
9
|
+
* @type {any}
|
|
10
|
+
* @memberof ChatReponse
|
|
11
|
+
*/
|
|
12
|
+
'error'?: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Api封装后的返回结果
|
|
16
|
+
*/
|
|
17
|
+
export interface ChatReponse extends ApiResult {
|
|
18
|
+
/**
|
|
19
|
+
* The name of the user in a multi-user chat
|
|
20
|
+
* @type {Array<any>}
|
|
21
|
+
* @memberof ChatReponse
|
|
22
|
+
*/
|
|
23
|
+
'message'?: Array<any>;
|
|
24
|
+
}
|
|
25
|
+
export interface OutlineSummaryItem {
|
|
26
|
+
/**
|
|
27
|
+
* The name of the user in a multi-user chat
|
|
28
|
+
* @type {Array<any>}
|
|
29
|
+
* @memberof SummaryReponse
|
|
30
|
+
*/
|
|
31
|
+
'outline'?: string;
|
|
32
|
+
'summary'?: Array<string>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 摘要信息
|
|
36
|
+
*/
|
|
37
|
+
export interface SummaryReponse extends ApiResult {
|
|
38
|
+
/**
|
|
39
|
+
* The name of the user in a multi-user chat
|
|
40
|
+
* @type {Array<any>}
|
|
41
|
+
* @memberof SummaryReponse
|
|
42
|
+
*/
|
|
43
|
+
'article'?: Array<OutlineSummaryItem>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 调用OpenAI Api的参数约定
|
|
47
|
+
*/
|
|
48
|
+
export interface OpenAIApiParameters {
|
|
49
|
+
'model'?: string;
|
|
50
|
+
'maxtoken'?: number;
|
|
51
|
+
'temperature'?: number;
|
|
52
|
+
'replyCounts'?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Azure 上的OpenAI的链接参数
|
|
56
|
+
*/
|
|
57
|
+
export interface AzureOpenAIPatameters {
|
|
58
|
+
'endpoint': string;
|
|
59
|
+
'engine': string;
|
|
60
|
+
'version'?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 调用OpenAI Api的参数约定
|
|
64
|
+
*/
|
|
65
|
+
export interface FaqItem {
|
|
66
|
+
'question': string;
|
|
67
|
+
'answer'?: string;
|
|
68
|
+
'keywords'?: Array<string>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 调用OpenAI Api的参数约定
|
|
72
|
+
*/
|
|
73
|
+
export interface ExaminationPaperResult extends ApiResult {
|
|
74
|
+
'score': number;
|
|
75
|
+
'paper': any;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 调用OpenAI Api的参数约定
|
|
79
|
+
*/
|
|
80
|
+
export interface QuestionItem {
|
|
81
|
+
'question': string;
|
|
82
|
+
'fullanswer'?: string;
|
|
83
|
+
'answer'?: Array<string>;
|
|
84
|
+
'choice'?: any[];
|
|
85
|
+
'score'?: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 调用OpenAI Api的参数约定
|
|
89
|
+
*/
|
|
90
|
+
export interface SimilarityResult extends ApiResult {
|
|
91
|
+
'value'?: number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 调用OpenAI Api的参数约定
|
|
95
|
+
*/
|
|
96
|
+
export interface EmotionResult extends ApiResult {
|
|
97
|
+
'emotion'?: string;
|
|
98
|
+
}
|
|
99
|
+
export {};
|
package/dist/declare.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,162 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { EventEmitter } from "events";
|
|
3
|
-
import { AxiosRequestConfig } from "axios";
|
|
4
|
-
export declare class AIChat extends EventEmitter {
|
|
5
|
-
private readonly chatRobot;
|
|
6
|
-
private readonly chatModel;
|
|
7
|
-
private readonly maxtoken;
|
|
8
|
-
private readonly temperature;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param apiKey 调用OpenAI 的key
|
|
12
|
-
* @param apiOption
|
|
13
|
-
*/
|
|
14
|
-
constructor(apiKey: string, apiOption?: CallChatApiOption);
|
|
15
|
-
/**
|
|
16
|
-
* 向OpenAI发送一个聊天请求
|
|
17
|
-
* @param {*} chatText
|
|
18
|
-
*/
|
|
19
|
-
chatRequest(chatText: string | Array<any>, callChatOption: CallChatApiOption, axiosOption?: AxiosRequestConfig): Promise<ChatReponse>;
|
|
20
|
-
/**
|
|
21
|
-
* 判断一句话的表达情绪
|
|
22
|
-
* @param {*} s1
|
|
23
|
-
* @param {*} axiosOption
|
|
24
|
-
*/
|
|
25
|
-
getScentenceEmotional(s1: string, axiosOption?: any): Promise<EmotionResult>;
|
|
26
|
-
/**
|
|
27
|
-
* 获取两句话的相似度取值
|
|
28
|
-
* @param {*} s1
|
|
29
|
-
* @param {*} s2
|
|
30
|
-
*/
|
|
31
|
-
getScentenseSimilarity(s1: string, s2: string, axiosOption?: any): Promise<SimilarityResult>;
|
|
32
|
-
/**
|
|
33
|
-
* 获得一种内容的相似说法
|
|
34
|
-
* 比如:
|
|
35
|
-
* 你今年多大?
|
|
36
|
-
* 相似问法:您是哪一年出生的
|
|
37
|
-
* 您今年贵庚?
|
|
38
|
-
* @param {*} content
|
|
39
|
-
* @param {需要出来的数量} count
|
|
40
|
-
*/
|
|
41
|
-
getSimilarityContent(content: string, count?: number, axiosOption?: AxiosRequestConfig): Promise<ChatReponse>;
|
|
42
|
-
/**
|
|
43
|
-
* 提取内容的中心思想摘要
|
|
44
|
-
* @param content
|
|
45
|
-
* @param axiosOption
|
|
46
|
-
*/
|
|
47
|
-
getSummaryOfContent(content: string | Array<any>, axiosOption?: AxiosRequestConfig): Promise<SummaryReponse>;
|
|
48
|
-
/**
|
|
49
|
-
* 从指定的文本内容中生成相关的问答
|
|
50
|
-
* @param {*} content
|
|
51
|
-
* @param {*} count
|
|
52
|
-
* @param {*} axiosOption
|
|
53
|
-
* @returns
|
|
54
|
-
*/ generateQuestionsFromContent(content: string, count?: number, axiosOption?: AxiosRequestConfig): Promise<ChatReponse>;
|
|
55
|
-
/**
|
|
56
|
-
* 解析Faq返回的问题
|
|
57
|
-
* @param {*} messages
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
private pickUpFaqContent;
|
|
61
|
-
/**
|
|
62
|
-
* 从指定的文本内容中生成一张试卷
|
|
63
|
-
* @param {*} content
|
|
64
|
-
* @param {试卷的参数} paperOption
|
|
65
|
-
* totalscore: 试卷总分,默认100
|
|
66
|
-
* section: {type:[0,1,2,3]为单选、多选、判断、填空题型 count:生成多少道 score:本段分数}
|
|
67
|
-
* @param {*} axiosOption
|
|
68
|
-
* @returns
|
|
69
|
-
*/ generateExaminationPaperFromContent(content: string, paperOption?: any, axiosOption?: AxiosRequestConfig): Promise<ExaminationPaperResult>;
|
|
70
|
-
/**
|
|
71
|
-
* 从答复中得到题目
|
|
72
|
-
* @param {*} result
|
|
73
|
-
*
|
|
74
|
-
*/
|
|
75
|
-
private pickUpQuestions;
|
|
76
|
-
/**
|
|
77
|
-
* 将一段很长的文本,按1024长度来划分到多个中
|
|
78
|
-
* @param {*} content
|
|
79
|
-
*/
|
|
80
|
-
private splitLongText;
|
|
81
|
-
}
|
|
82
|
-
interface ApiResult {
|
|
83
|
-
/**
|
|
84
|
-
* return the result of api called
|
|
85
|
-
* @type {boolean}
|
|
86
|
-
*/
|
|
87
|
-
'successed': boolean;
|
|
88
|
-
/**
|
|
89
|
-
* The error info
|
|
90
|
-
* @type {any}
|
|
91
|
-
* @memberof ChatReponse
|
|
92
|
-
*/
|
|
93
|
-
'error'?: any;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Api封装后的返回结果
|
|
97
|
-
*/
|
|
98
|
-
export interface ChatReponse extends ApiResult {
|
|
99
|
-
/**
|
|
100
|
-
* The name of the user in a multi-user chat
|
|
101
|
-
* @type {Array<any>}
|
|
102
|
-
* @memberof ChatReponse
|
|
103
|
-
*/
|
|
104
|
-
'message'?: Array<any>;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* 摘要信息
|
|
108
|
-
*/
|
|
109
|
-
export interface SummaryReponse extends ApiResult {
|
|
110
|
-
/**
|
|
111
|
-
* The name of the user in a multi-user chat
|
|
112
|
-
* @type {Array<any>}
|
|
113
|
-
* @memberof SummaryReponse
|
|
114
|
-
*/
|
|
115
|
-
'summary'?: Array<string>;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* 调用OpenAI Api的参数约定
|
|
119
|
-
*/
|
|
120
|
-
export interface CallChatApiOption {
|
|
121
|
-
'model'?: string;
|
|
122
|
-
'maxtoken'?: number;
|
|
123
|
-
'temperature'?: number;
|
|
124
|
-
'replyCounts'?: number;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* 调用OpenAI Api的参数约定
|
|
128
|
-
*/
|
|
129
|
-
export interface FaqItem {
|
|
130
|
-
'question': string;
|
|
131
|
-
'answer'?: string;
|
|
132
|
-
'keywords'?: Array<string>;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* 调用OpenAI Api的参数约定
|
|
136
|
-
*/
|
|
137
|
-
export interface ExaminationPaperResult extends ApiResult {
|
|
138
|
-
'score': number;
|
|
139
|
-
'paper': any;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* 调用OpenAI Api的参数约定
|
|
143
|
-
*/
|
|
144
|
-
export interface QuestionItem {
|
|
145
|
-
'question': string;
|
|
146
|
-
'answer'?: Array<string>;
|
|
147
|
-
'choice'?: Array<string>;
|
|
148
|
-
'score'?: number;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* 调用OpenAI Api的参数约定
|
|
152
|
-
*/
|
|
153
|
-
export interface SimilarityResult extends ApiResult {
|
|
154
|
-
'value'?: number;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* 调用OpenAI Api的参数约定
|
|
158
|
-
*/
|
|
159
|
-
export interface EmotionResult extends ApiResult {
|
|
160
|
-
'emotion'?: string;
|
|
161
|
-
}
|
|
162
|
-
export {};
|
|
1
|
+
export * as AIFactory from "./openaiprovider";
|