doomiaichat 2.0.0 → 2.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.d.ts +14 -0
- package/dist/azureai.js +67 -0
- package/dist/baiduai.d.ts +34 -0
- package/dist/baiduai.js +110 -0
- package/dist/declare.d.ts +34 -2
- package/dist/declare.js +33 -0
- package/dist/gptbase.d.ts +56 -0
- package/dist/gptbase.js +12 -0
- package/dist/gptprovider.d.ts +20 -0
- package/dist/gptprovider.js +44 -0
- package/dist/index.d.ts +2 -179
- package/dist/index.js +25 -506
- package/dist/openai.d.ts +8 -10
- package/dist/openai.js +8 -40
- package/dist/openaiprovider.d.ts +20 -0
- package/dist/openaiprovider.js +43 -0
- package/package.json +2 -1
- package/src/azureai.ts +14 -10
- package/src/baiduai.ts +103 -0
- package/src/declare.ts +49 -1
- package/src/gptbase.ts +58 -0
- package/src/gptprovider.ts +38 -0
- package/src/index.ts +2 -1
- package/src/openai.ts +14 -51
- package/tsconfig.json +1 -1
- package/src/openaiprovider.ts +0 -32
|
@@ -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,67 @@
|
|
|
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 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
|
+
try {
|
|
48
|
+
let param = Object.assign(Object.assign({}, axiosOption), { method: "post", data: {
|
|
49
|
+
messages,
|
|
50
|
+
temperature: Number((paramOption === null || paramOption === void 0 ? void 0 : paramOption.temperature) || this.temperature),
|
|
51
|
+
max_tokens: Number((paramOption === null || paramOption === void 0 ? void 0 : paramOption.maxtoken) || this.maxtoken),
|
|
52
|
+
}, url: this.BaseUrl });
|
|
53
|
+
// console.log('axiosOption', param)
|
|
54
|
+
const response = yield (0, declare_1.request)(param);
|
|
55
|
+
if (response.data.choices) {
|
|
56
|
+
return { successed: true, message: response.data.choices };
|
|
57
|
+
}
|
|
58
|
+
return Object.assign({ successed: false }, response.data);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.log('result is error ', error);
|
|
62
|
+
return { successed: false, error };
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.default = AzureAI;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EmotionResult, SimilarityResult, ChatReponse, SummaryReponse, ExaminationPaperResult, ApiResult, CacheProvider } from "./declare";
|
|
2
|
+
import GptBase from "./gptbase";
|
|
3
|
+
export default class BaiduWenXinAI extends GptBase {
|
|
4
|
+
protected credential: ApiCredential;
|
|
5
|
+
private Cacher;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param credential 调用OpenAI 的key
|
|
9
|
+
* @param cacher 用作accesstoken的缓存
|
|
10
|
+
* @param apiOption 用作accesstoken的缓存
|
|
11
|
+
*/
|
|
12
|
+
constructor(credential: ApiCredential, cacher?: CacheProvider);
|
|
13
|
+
/**
|
|
14
|
+
* 获取调用Api的Token
|
|
15
|
+
*/
|
|
16
|
+
getAccessToken(): Promise<AccessTokenResult>;
|
|
17
|
+
/**
|
|
18
|
+
* 请求GPT接口
|
|
19
|
+
*/
|
|
20
|
+
chatRequest(chatText: string | Array<any>, _paramOption: any, axiosOption?: any): Promise<ApiResult>;
|
|
21
|
+
getScentenceEmotional(_s1: string, _axiosOption: any): Promise<EmotionResult>;
|
|
22
|
+
getScentenseSimilarity(_s1: string, _s2: string, _axiosOption: any): Promise<SimilarityResult>;
|
|
23
|
+
getSimilarityContent(_content: string, _count: number, _axiosOption: any): Promise<ChatReponse>;
|
|
24
|
+
getSummaryOfContent(_content: string | any[], _axiosOption: any): Promise<SummaryReponse>;
|
|
25
|
+
generateQuestionsFromContent(_content: string, _count: number, _axiosOption: any): Promise<ChatReponse>;
|
|
26
|
+
generateExaminationPaperFromContent(_content: string, _paperOption: any, _axiosOption: any): Promise<ExaminationPaperResult>;
|
|
27
|
+
}
|
|
28
|
+
export interface AccessTokenResult extends ApiResult {
|
|
29
|
+
'access_token'?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ApiCredential {
|
|
32
|
+
'apikey': string;
|
|
33
|
+
'securitykey': string;
|
|
34
|
+
}
|
package/dist/baiduai.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
const TOKEN_CACHE_KEY = "key:_doomisoft:baiduwenxin:";
|
|
18
|
+
class BaiduWenXinAI extends gptbase_1.default {
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param credential 调用OpenAI 的key
|
|
22
|
+
* @param cacher 用作accesstoken的缓存
|
|
23
|
+
* @param apiOption 用作accesstoken的缓存
|
|
24
|
+
*/
|
|
25
|
+
constructor(credential, cacher) {
|
|
26
|
+
super();
|
|
27
|
+
this.credential = credential;
|
|
28
|
+
this.Cacher = cacher;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 获取调用Api的Token
|
|
32
|
+
*/
|
|
33
|
+
getAccessToken() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
////如果当前应用是一个委托到第三方的
|
|
36
|
+
///公众号或小程序,则需要用关联的第三方平台来获取api调用的accesstoken
|
|
37
|
+
////如果是需要缓存token,则首先看缓存中是否有AccessToken
|
|
38
|
+
const accesstoken = this.Cacher ? (yield this.Cacher.get(TOKEN_CACHE_KEY + this.credential.apikey)) : null;
|
|
39
|
+
if (accesstoken)
|
|
40
|
+
return { successed: true, access_token: accesstoken };
|
|
41
|
+
const option = {
|
|
42
|
+
url: `https://wenxin.baidu.com/moduleApi/portal/api/oauth/token?grant_type=client_credentials&client_id=${this.credential.apikey}&client_secret=${this.credential.securitykey}`,
|
|
43
|
+
method: "post",
|
|
44
|
+
};
|
|
45
|
+
const tokenData = yield (0, declare_1.request)(option);
|
|
46
|
+
if (tokenData.successed == true && !tokenData.data.code) {
|
|
47
|
+
///把api accesstoken缓存起来
|
|
48
|
+
if (this.Cacher) {
|
|
49
|
+
this.Cacher.set(TOKEN_CACHE_KEY + this.credential.apikey, tokenData.data.data, 3600 * 20);
|
|
50
|
+
}
|
|
51
|
+
return { successed: true, access_token: tokenData.data.data };
|
|
52
|
+
}
|
|
53
|
+
return { successed: false, error: tokenData.data.msg };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 请求GPT接口
|
|
58
|
+
*/
|
|
59
|
+
chatRequest(chatText, _paramOption, axiosOption = {}) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
console.log('call baidu');
|
|
62
|
+
if (!chatText)
|
|
63
|
+
return { successed: false, error: { errcode: 2, errmsg: '缺失聊天的内容' } };
|
|
64
|
+
const accessToken = yield this.getAccessToken();
|
|
65
|
+
if (!accessToken.successed || !accessToken.access_token)
|
|
66
|
+
return { successed: false, error: 'accesstoken get failed' };
|
|
67
|
+
try {
|
|
68
|
+
let param = Object.assign(Object.assign({}, axiosOption), { method: "post", data: {
|
|
69
|
+
text: `问题:${chatText}\n回答:`,
|
|
70
|
+
seq_len: 512,
|
|
71
|
+
topp: 0.5,
|
|
72
|
+
penalty_score: 1.2,
|
|
73
|
+
min_dec_len: 12,
|
|
74
|
+
min_dec_penalty_text: "。?:![<S>]",
|
|
75
|
+
task_prompt: "qa",
|
|
76
|
+
mask_type: "paragraph"
|
|
77
|
+
}, url: `https://wenxin.baidu.com/moduleApi/portal/api/rest/1.0/ernie/3.0.25/zeus?access_token=${accessToken.access_token}` });
|
|
78
|
+
console.log('param', param);
|
|
79
|
+
const response = yield (0, declare_1.request)(param);
|
|
80
|
+
if (response.successed && !response.data.code) {
|
|
81
|
+
return Object.assign({ successed: true }, response.data);
|
|
82
|
+
}
|
|
83
|
+
return Object.assign({ successed: false }, response.data);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.log('result is error ', error);
|
|
87
|
+
return { successed: false, error };
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getScentenceEmotional(_s1, _axiosOption) {
|
|
92
|
+
throw new Error("Method not implemented.");
|
|
93
|
+
}
|
|
94
|
+
getScentenseSimilarity(_s1, _s2, _axiosOption) {
|
|
95
|
+
throw new Error("Method not implemented.");
|
|
96
|
+
}
|
|
97
|
+
getSimilarityContent(_content, _count, _axiosOption) {
|
|
98
|
+
throw new Error("Method not implemented.");
|
|
99
|
+
}
|
|
100
|
+
getSummaryOfContent(_content, _axiosOption) {
|
|
101
|
+
throw new Error("Method not implemented.");
|
|
102
|
+
}
|
|
103
|
+
generateQuestionsFromContent(_content, _count, _axiosOption) {
|
|
104
|
+
throw new Error("Method not implemented.");
|
|
105
|
+
}
|
|
106
|
+
generateExaminationPaperFromContent(_content, _paperOption, _axiosOption) {
|
|
107
|
+
throw new Error("Method not implemented.");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.default = BaiduWenXinAI;
|
package/dist/declare.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface ApiResult {
|
|
1
|
+
export interface ApiResult {
|
|
2
2
|
/**
|
|
3
3
|
* return the result of api called
|
|
4
4
|
* @type {boolean}
|
|
@@ -96,4 +96,36 @@ export interface SimilarityResult extends ApiResult {
|
|
|
96
96
|
export interface EmotionResult extends ApiResult {
|
|
97
97
|
'emotion'?: string;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
/**
|
|
100
|
+
* 远程请求的返回
|
|
101
|
+
*/
|
|
102
|
+
export interface RpcResult extends ApiResult {
|
|
103
|
+
'data'?: any;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Axios远程请求封装
|
|
107
|
+
* @param opts
|
|
108
|
+
* @returns
|
|
109
|
+
*/
|
|
110
|
+
export declare function request(opts?: any): Promise<RpcResult>;
|
|
111
|
+
/**
|
|
112
|
+
* 数据缓存提供者接口
|
|
113
|
+
*/
|
|
114
|
+
export interface CacheProvider {
|
|
115
|
+
/**
|
|
116
|
+
* 缓存数据
|
|
117
|
+
* @param key 数据的键名称
|
|
118
|
+
* @param value 数据的键值
|
|
119
|
+
*/
|
|
120
|
+
set(key: string, value: string | object, exp?: number): void;
|
|
121
|
+
/**
|
|
122
|
+
* 从缓存中读取数据
|
|
123
|
+
* @param key 数据的键名称
|
|
124
|
+
*/
|
|
125
|
+
get(key: string): Promise<string | null>;
|
|
126
|
+
/**
|
|
127
|
+
* 删除缓存信息
|
|
128
|
+
* @param key 数据的键名称
|
|
129
|
+
*/
|
|
130
|
+
delete(key: string): void;
|
|
131
|
+
}
|
package/dist/declare.js
CHANGED
|
@@ -1,2 +1,35 @@
|
|
|
1
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
|
+
};
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.request = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
/**
|
|
18
|
+
* Axios远程请求封装
|
|
19
|
+
* @param opts
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
function request(opts = {}) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
if (!opts.data)
|
|
25
|
+
opts.data = opts.body;
|
|
26
|
+
try {
|
|
27
|
+
let result = yield (0, axios_1.default)(opts);
|
|
28
|
+
return { successed: true, data: result.data };
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return { successed: false, error: err };
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.request = request;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { ChatReponse, SummaryReponse, ExaminationPaperResult, EmotionResult, SimilarityResult, ApiResult } from './declare';
|
|
4
|
+
export default abstract class GptBase extends EventEmitter {
|
|
5
|
+
/**
|
|
6
|
+
* 构造函数
|
|
7
|
+
*/
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* 自由聊天模式
|
|
11
|
+
* @param chatText
|
|
12
|
+
* @param _paramOption
|
|
13
|
+
* @param axiosOption
|
|
14
|
+
*/
|
|
15
|
+
abstract chatRequest(chatText: string | Array<any>, _paramOption: any, axiosOption: any): Promise<ApiResult>;
|
|
16
|
+
/**
|
|
17
|
+
* 获取句子的情感
|
|
18
|
+
* @param s1
|
|
19
|
+
* @param axiosOption
|
|
20
|
+
*/
|
|
21
|
+
abstract getScentenceEmotional(s1: string, axiosOption: any): Promise<EmotionResult>;
|
|
22
|
+
/**
|
|
23
|
+
* 获取两段文本的相似度
|
|
24
|
+
* @param s1
|
|
25
|
+
* @param s2
|
|
26
|
+
* @param axiosOption
|
|
27
|
+
*/
|
|
28
|
+
abstract getScentenseSimilarity(s1: string, s2: string, axiosOption: any): Promise<SimilarityResult>;
|
|
29
|
+
/**
|
|
30
|
+
* 获取一段文本的相似内容
|
|
31
|
+
* @param content
|
|
32
|
+
* @param count
|
|
33
|
+
* @param axiosOption
|
|
34
|
+
*/
|
|
35
|
+
abstract getSimilarityContent(content: string, count: number, axiosOption: any): Promise<ChatReponse>;
|
|
36
|
+
/**
|
|
37
|
+
* 获取内容的摘要
|
|
38
|
+
* @param content
|
|
39
|
+
* @param axiosOption
|
|
40
|
+
*/
|
|
41
|
+
abstract getSummaryOfContent(content: string | Array<any>, axiosOption: any): Promise<SummaryReponse>;
|
|
42
|
+
/**
|
|
43
|
+
* 从内容中提取问题和答案及管件子
|
|
44
|
+
* @param content
|
|
45
|
+
* @param count
|
|
46
|
+
* @param axiosOption
|
|
47
|
+
*/
|
|
48
|
+
abstract generateQuestionsFromContent(content: string, count: number, axiosOption: any): Promise<ChatReponse>;
|
|
49
|
+
/**
|
|
50
|
+
* 从内容中提取单选多选判断填空题
|
|
51
|
+
* @param content
|
|
52
|
+
* @param paperOption
|
|
53
|
+
* @param axiosOption
|
|
54
|
+
*/
|
|
55
|
+
abstract generateExaminationPaperFromContent(content: string, paperOption: any, axiosOption: any): Promise<ExaminationPaperResult>;
|
|
56
|
+
}
|
package/dist/gptbase.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApiCredential } from './baiduai';
|
|
2
|
+
import GptBase from './gptbase';
|
|
3
|
+
/**
|
|
4
|
+
* OpenAI/NLP 的服务提供商 OpenAI,微软,百度文心(待接入),google(待接入)
|
|
5
|
+
*/
|
|
6
|
+
export declare const GptProviderEnum: {
|
|
7
|
+
readonly OPENAI: "openai";
|
|
8
|
+
readonly MICROSOFT: "microsoft";
|
|
9
|
+
readonly BAIDU: "baidu";
|
|
10
|
+
readonly GOOGLE: "google";
|
|
11
|
+
};
|
|
12
|
+
export type GptProviderEnum = typeof GptProviderEnum[keyof typeof GptProviderEnum];
|
|
13
|
+
/**
|
|
14
|
+
* 根据类型创建不同的TTS引擎对象
|
|
15
|
+
* @param {*} provider
|
|
16
|
+
* @param {*} apikey
|
|
17
|
+
* @param {*} setting
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function createGpt(provider: GptProviderEnum, apikey: string | ApiCredential, setting: any): GptBase | null;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createGpt = exports.GptProviderEnum = void 0;
|
|
7
|
+
//ts check
|
|
8
|
+
/**
|
|
9
|
+
* 语音转文字服务商工厂
|
|
10
|
+
*/
|
|
11
|
+
const openai_1 = __importDefault(require("./openai"));
|
|
12
|
+
const azureai_1 = __importDefault(require("./azureai"));
|
|
13
|
+
const baiduai_1 = __importDefault(require("./baiduai"));
|
|
14
|
+
/**
|
|
15
|
+
* OpenAI/NLP 的服务提供商 OpenAI,微软,百度文心(待接入),google(待接入)
|
|
16
|
+
*/
|
|
17
|
+
exports.GptProviderEnum = {
|
|
18
|
+
OPENAI: 'openai',
|
|
19
|
+
MICROSOFT: 'microsoft',
|
|
20
|
+
BAIDU: 'baidu',
|
|
21
|
+
GOOGLE: 'google'
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 根据类型创建不同的TTS引擎对象
|
|
25
|
+
* @param {*} provider
|
|
26
|
+
* @param {*} apikey
|
|
27
|
+
* @param {*} setting
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
function createGpt(provider, apikey, setting) {
|
|
31
|
+
let { model, maxtoken, temperature, endpoint, engine, version } = setting || {};
|
|
32
|
+
switch (provider) {
|
|
33
|
+
case exports.GptProviderEnum.OPENAI:
|
|
34
|
+
return new openai_1.default(apikey + '', { model, maxtoken, temperature });
|
|
35
|
+
case exports.GptProviderEnum.MICROSOFT:
|
|
36
|
+
return new azureai_1.default(apikey + '', { endpoint, engine, version }, { model, maxtoken, temperature });
|
|
37
|
+
case exports.GptProviderEnum.BAIDU:
|
|
38
|
+
let cred = typeof (apikey) === 'string' ? { apikey, securitykey: apikey } : apikey;
|
|
39
|
+
return new baiduai_1.default(cred);
|
|
40
|
+
default: return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.createGpt = createGpt;
|
|
44
|
+
;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,179 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
* 从指定的文本内容中生成相关的问答
|
|
57
|
-
* @param {*} content
|
|
58
|
-
* @param {*} count
|
|
59
|
-
* @param {*} axiosOption
|
|
60
|
-
* @returns
|
|
61
|
-
*/ generateQuestionsFromContent_Orgin(content: string, count?: number, promotion?: string | null, sliceslength?: number, axiosOption?: AxiosRequestConfig): Promise<ChatReponse>;
|
|
62
|
-
/**
|
|
63
|
-
* 解析Faq返回的问题
|
|
64
|
-
* @param {*} messages
|
|
65
|
-
* @returns
|
|
66
|
-
*/
|
|
67
|
-
private pickUpFaqContent;
|
|
68
|
-
/**
|
|
69
|
-
* 从指定的文本内容中生成一张试卷
|
|
70
|
-
* @param {*} content
|
|
71
|
-
* @param {试卷的参数} paperOption
|
|
72
|
-
* totalscore: 试卷总分,默认100
|
|
73
|
-
* section: {type:[0,1,2,3]为单选、多选、判断、填空题型 count:生成多少道 score:本段分数}
|
|
74
|
-
* @param {*} axiosOption
|
|
75
|
-
* @returns
|
|
76
|
-
*/ generateExaminationPaperFromContent(content: string, paperOption?: any, axiosOption?: AxiosRequestConfig): Promise<ExaminationPaperResult>;
|
|
77
|
-
/**
|
|
78
|
-
* 从答复中得到题目
|
|
79
|
-
* @param {*} result
|
|
80
|
-
*
|
|
81
|
-
*/
|
|
82
|
-
private pickUpQuestions;
|
|
83
|
-
/**
|
|
84
|
-
* 将一段很长的文本,按1024长度来划分到多个中
|
|
85
|
-
* @param {*} content
|
|
86
|
-
*/
|
|
87
|
-
private splitLongText;
|
|
88
|
-
}
|
|
89
|
-
interface ApiResult {
|
|
90
|
-
/**
|
|
91
|
-
* return the result of api called
|
|
92
|
-
* @type {boolean}
|
|
93
|
-
*/
|
|
94
|
-
'successed': boolean;
|
|
95
|
-
/**
|
|
96
|
-
* The error info
|
|
97
|
-
* @type {any}
|
|
98
|
-
* @memberof ChatReponse
|
|
99
|
-
*/
|
|
100
|
-
'error'?: any;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Api封装后的返回结果
|
|
104
|
-
*/
|
|
105
|
-
export interface ChatReponse extends ApiResult {
|
|
106
|
-
/**
|
|
107
|
-
* The name of the user in a multi-user chat
|
|
108
|
-
* @type {Array<any>}
|
|
109
|
-
* @memberof ChatReponse
|
|
110
|
-
*/
|
|
111
|
-
'message'?: Array<any>;
|
|
112
|
-
}
|
|
113
|
-
interface OutlineSummaryItem {
|
|
114
|
-
/**
|
|
115
|
-
* The name of the user in a multi-user chat
|
|
116
|
-
* @type {Array<any>}
|
|
117
|
-
* @memberof SummaryReponse
|
|
118
|
-
*/
|
|
119
|
-
'outline'?: string;
|
|
120
|
-
'summary'?: Array<string>;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* 摘要信息
|
|
124
|
-
*/
|
|
125
|
-
export interface SummaryReponse extends ApiResult {
|
|
126
|
-
/**
|
|
127
|
-
* The name of the user in a multi-user chat
|
|
128
|
-
* @type {Array<any>}
|
|
129
|
-
* @memberof SummaryReponse
|
|
130
|
-
*/
|
|
131
|
-
'article'?: Array<OutlineSummaryItem>;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* 调用OpenAI Api的参数约定
|
|
135
|
-
*/
|
|
136
|
-
export interface CallChatApiOption {
|
|
137
|
-
'model'?: string;
|
|
138
|
-
'maxtoken'?: number;
|
|
139
|
-
'temperature'?: number;
|
|
140
|
-
'replyCounts'?: number;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* 调用OpenAI Api的参数约定
|
|
144
|
-
*/
|
|
145
|
-
export interface FaqItem {
|
|
146
|
-
'question': string;
|
|
147
|
-
'answer'?: string;
|
|
148
|
-
'keywords'?: Array<string>;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* 调用OpenAI Api的参数约定
|
|
152
|
-
*/
|
|
153
|
-
export interface ExaminationPaperResult extends ApiResult {
|
|
154
|
-
'score': number;
|
|
155
|
-
'paper': any;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* 调用OpenAI Api的参数约定
|
|
159
|
-
*/
|
|
160
|
-
export interface QuestionItem {
|
|
161
|
-
'question': string;
|
|
162
|
-
'fullanswer'?: string;
|
|
163
|
-
'answer'?: Array<string>;
|
|
164
|
-
'choice'?: any[];
|
|
165
|
-
'score'?: number;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* 调用OpenAI Api的参数约定
|
|
169
|
-
*/
|
|
170
|
-
export interface SimilarityResult extends ApiResult {
|
|
171
|
-
'value'?: number;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* 调用OpenAI Api的参数约定
|
|
175
|
-
*/
|
|
176
|
-
export interface EmotionResult extends ApiResult {
|
|
177
|
-
'emotion'?: string;
|
|
178
|
-
}
|
|
179
|
-
export {};
|
|
1
|
+
export * as GptFactory from "./gptprovider";
|
|
2
|
+
export * as GptBase from "./gptbase";
|