doomiaichat 2.1.0 → 2.3.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.js +3 -9
- package/dist/baiduai.d.ts +35 -0
- package/dist/baiduai.js +113 -0
- package/dist/declare.d.ts +41 -2
- package/dist/declare.js +33 -0
- package/dist/gptbase.d.ts +63 -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 -1
- package/dist/index.js +3 -2
- package/dist/openai.d.ts +16 -4
- package/dist/openai.js +115 -59
- package/dist/openaiprovider.d.ts +3 -5
- package/dist/openaiprovider.js +7 -3
- package/package.json +1 -1
- package/src/azureai.ts +3 -11
- package/src/baiduai.ts +106 -0
- package/src/declare.ts +56 -1
- package/src/gptbase.ts +65 -0
- package/src/gptprovider.ts +38 -0
- package/src/index.ts +2 -1
- package/src/openai.ts +121 -74
- package/src/openaiprovider.ts +0 -32
package/dist/azureai.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
15
|
+
const declare_1 = require("./declare");
|
|
16
16
|
const openai_1 = __importDefault(require("./openai"));
|
|
17
17
|
class AzureAI extends openai_1.default {
|
|
18
18
|
constructor(apiKey, azureOption, apiOption = {}) {
|
|
@@ -44,20 +44,14 @@ class AzureAI extends openai_1.default {
|
|
|
44
44
|
}
|
|
45
45
|
let messages = typeof (chatText) == 'string' ?
|
|
46
46
|
[{ role: 'user', content: chatText }] : chatText;
|
|
47
|
-
//let axios = new Axios(axiosOption)
|
|
48
47
|
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
48
|
let param = Object.assign(Object.assign({}, axiosOption), { method: "post", data: {
|
|
55
49
|
messages,
|
|
56
50
|
temperature: Number((paramOption === null || paramOption === void 0 ? void 0 : paramOption.temperature) || this.temperature),
|
|
57
51
|
max_tokens: Number((paramOption === null || paramOption === void 0 ? void 0 : paramOption.maxtoken) || this.maxtoken),
|
|
58
52
|
}, url: this.BaseUrl });
|
|
59
|
-
console.log('axiosOption', param)
|
|
60
|
-
const response = yield (0,
|
|
53
|
+
// console.log('axiosOption', param)
|
|
54
|
+
const response = yield (0, declare_1.request)(param);
|
|
61
55
|
if (response.data.choices) {
|
|
62
56
|
return { successed: true, message: response.data.choices };
|
|
63
57
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EmotionResult, SimilarityResult, ChatReponse, SummaryReponse, ExaminationPaperResult, ApiResult, CacheProvider, CommentResult } 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
|
+
commentQuestionAnswer(_question: string, _answer: string, _axiosOption: any): Promise<CommentResult>;
|
|
22
|
+
getScentenceEmotional(_s1: string, _axiosOption: any): Promise<EmotionResult>;
|
|
23
|
+
getScentenseSimilarity(_s1: string, _s2: string, _axiosOption: any): Promise<SimilarityResult>;
|
|
24
|
+
getSimilarityContent(_content: string, _count: number, _axiosOption: any): Promise<ChatReponse>;
|
|
25
|
+
getSummaryOfContent(_content: string | any[], _axiosOption: any): Promise<SummaryReponse>;
|
|
26
|
+
generateQuestionsFromContent(_content: string, _count: number, _axiosOption: any): Promise<ChatReponse>;
|
|
27
|
+
generateExaminationPaperFromContent(_content: string, _paperOption: any, _axiosOption: any): Promise<ExaminationPaperResult>;
|
|
28
|
+
}
|
|
29
|
+
export interface AccessTokenResult extends ApiResult {
|
|
30
|
+
'access_token'?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ApiCredential {
|
|
33
|
+
'apikey': string;
|
|
34
|
+
'securitykey': string;
|
|
35
|
+
}
|
package/dist/baiduai.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
commentQuestionAnswer(_question, _answer, _axiosOption) {
|
|
92
|
+
throw new Error("Method not implemented.");
|
|
93
|
+
}
|
|
94
|
+
getScentenceEmotional(_s1, _axiosOption) {
|
|
95
|
+
throw new Error("Method not implemented.");
|
|
96
|
+
}
|
|
97
|
+
getScentenseSimilarity(_s1, _s2, _axiosOption) {
|
|
98
|
+
throw new Error("Method not implemented.");
|
|
99
|
+
}
|
|
100
|
+
getSimilarityContent(_content, _count, _axiosOption) {
|
|
101
|
+
throw new Error("Method not implemented.");
|
|
102
|
+
}
|
|
103
|
+
getSummaryOfContent(_content, _axiosOption) {
|
|
104
|
+
throw new Error("Method not implemented.");
|
|
105
|
+
}
|
|
106
|
+
generateQuestionsFromContent(_content, _count, _axiosOption) {
|
|
107
|
+
throw new Error("Method not implemented.");
|
|
108
|
+
}
|
|
109
|
+
generateExaminationPaperFromContent(_content, _paperOption, _axiosOption) {
|
|
110
|
+
throw new Error("Method not implemented.");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
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}
|
|
@@ -90,10 +90,49 @@ export interface QuestionItem {
|
|
|
90
90
|
export interface SimilarityResult extends ApiResult {
|
|
91
91
|
'value'?: number;
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* 调用OpenAI Api的参数约定
|
|
95
|
+
*/
|
|
96
|
+
export interface CommentResult extends ApiResult {
|
|
97
|
+
'score'?: number;
|
|
98
|
+
'comment'?: string;
|
|
99
|
+
}
|
|
93
100
|
/**
|
|
94
101
|
* 调用OpenAI Api的参数约定
|
|
95
102
|
*/
|
|
96
103
|
export interface EmotionResult extends ApiResult {
|
|
97
104
|
'emotion'?: string;
|
|
98
105
|
}
|
|
99
|
-
|
|
106
|
+
/**
|
|
107
|
+
* 远程请求的返回
|
|
108
|
+
*/
|
|
109
|
+
export interface RpcResult extends ApiResult {
|
|
110
|
+
'data'?: any;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Axios远程请求封装
|
|
114
|
+
* @param opts
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
export declare function request(opts?: any): Promise<RpcResult>;
|
|
118
|
+
/**
|
|
119
|
+
* 数据缓存提供者接口
|
|
120
|
+
*/
|
|
121
|
+
export interface CacheProvider {
|
|
122
|
+
/**
|
|
123
|
+
* 缓存数据
|
|
124
|
+
* @param key 数据的键名称
|
|
125
|
+
* @param value 数据的键值
|
|
126
|
+
*/
|
|
127
|
+
set(key: string, value: string | object, exp?: number): void;
|
|
128
|
+
/**
|
|
129
|
+
* 从缓存中读取数据
|
|
130
|
+
* @param key 数据的键名称
|
|
131
|
+
*/
|
|
132
|
+
get(key: string): Promise<string | null>;
|
|
133
|
+
/**
|
|
134
|
+
* 删除缓存信息
|
|
135
|
+
* @param key 数据的键名称
|
|
136
|
+
*/
|
|
137
|
+
delete(key: string): void;
|
|
138
|
+
}
|
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,63 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { ChatReponse, SummaryReponse, ExaminationPaperResult, EmotionResult, SimilarityResult, ApiResult, CommentResult } 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 question 问题题干
|
|
19
|
+
* @param answer 回答内容
|
|
20
|
+
* @param axiosOption
|
|
21
|
+
*/
|
|
22
|
+
abstract commentQuestionAnswer(question: string, answer: string, axiosOption: any): Promise<CommentResult>;
|
|
23
|
+
/**
|
|
24
|
+
* 获取句子的情感
|
|
25
|
+
* @param s1
|
|
26
|
+
* @param axiosOption
|
|
27
|
+
*/
|
|
28
|
+
abstract getScentenceEmotional(s1: string, axiosOption: any): Promise<EmotionResult>;
|
|
29
|
+
/**
|
|
30
|
+
* 获取两段文本的相似度
|
|
31
|
+
* @param s1
|
|
32
|
+
* @param s2
|
|
33
|
+
* @param axiosOption
|
|
34
|
+
*/
|
|
35
|
+
abstract getScentenseSimilarity(s1: string, s2: string, axiosOption: any): Promise<SimilarityResult>;
|
|
36
|
+
/**
|
|
37
|
+
* 获取一段文本的相似内容
|
|
38
|
+
* @param content
|
|
39
|
+
* @param count
|
|
40
|
+
* @param axiosOption
|
|
41
|
+
*/
|
|
42
|
+
abstract getSimilarityContent(content: string, count: number, axiosOption: any): Promise<ChatReponse>;
|
|
43
|
+
/**
|
|
44
|
+
* 获取内容的摘要
|
|
45
|
+
* @param content
|
|
46
|
+
* @param axiosOption
|
|
47
|
+
*/
|
|
48
|
+
abstract getSummaryOfContent(content: string | Array<any>, axiosOption: any): Promise<SummaryReponse>;
|
|
49
|
+
/**
|
|
50
|
+
* 从内容中提取问题和答案及管件子
|
|
51
|
+
* @param content
|
|
52
|
+
* @param count
|
|
53
|
+
* @param axiosOption
|
|
54
|
+
*/
|
|
55
|
+
abstract generateQuestionsFromContent(content: string, count: number, axiosOption: any): Promise<ChatReponse>;
|
|
56
|
+
/**
|
|
57
|
+
* 从内容中提取单选多选判断填空题
|
|
58
|
+
* @param content
|
|
59
|
+
* @param paperOption
|
|
60
|
+
* @param axiosOption
|
|
61
|
+
*/
|
|
62
|
+
abstract generateExaminationPaperFromContent(content: string, paperOption: any, axiosOption: any): Promise<ExaminationPaperResult>;
|
|
63
|
+
}
|
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 +1,2 @@
|
|
|
1
|
-
export * as
|
|
1
|
+
export * as GptFactory from "./gptprovider";
|
|
2
|
+
export * as GptBase from "./gptbase";
|
package/dist/index.js
CHANGED
|
@@ -23,5 +23,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
26
|
+
exports.GptBase = exports.GptFactory = void 0;
|
|
27
|
+
exports.GptFactory = __importStar(require("./gptprovider"));
|
|
28
|
+
exports.GptBase = __importStar(require("./gptbase"));
|
package/dist/openai.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { OpenAIApi, ChatCompletionRequestMessage } from "openai";
|
|
3
|
-
import
|
|
4
|
-
import { OpenAIApiParameters, ChatReponse, SummaryReponse, FaqItem, ExaminationPaperResult, EmotionResult, SimilarityResult, QuestionItem } from './declare';
|
|
5
|
-
export default class OpenAIGpt extends
|
|
2
|
+
import GptBase from "./gptbase";
|
|
3
|
+
import { OpenAIApiParameters, ChatReponse, SummaryReponse, FaqItem, ExaminationPaperResult, EmotionResult, SimilarityResult, QuestionItem, CommentResult } from './declare';
|
|
4
|
+
export default class OpenAIGpt extends GptBase {
|
|
6
5
|
protected readonly apiKey: string;
|
|
7
6
|
private aiApi;
|
|
8
7
|
protected readonly chatModel: string;
|
|
@@ -23,6 +22,13 @@ export default class OpenAIGpt extends EventEmitter {
|
|
|
23
22
|
* @param {*} chatText
|
|
24
23
|
*/
|
|
25
24
|
chatRequest(chatText: string | Array<any>, callChatOption: OpenAIApiParameters, axiosOption?: any): Promise<ChatReponse>;
|
|
25
|
+
/**
|
|
26
|
+
* 点评问题回答的评价
|
|
27
|
+
* @param question
|
|
28
|
+
* @param answer
|
|
29
|
+
* @param axiosOption
|
|
30
|
+
*/
|
|
31
|
+
commentQuestionAnswer(question: string, answer: string, axiosOption?: any): Promise<CommentResult>;
|
|
26
32
|
/**
|
|
27
33
|
* 判断一句话的表达情绪
|
|
28
34
|
* @param {*} s1
|
|
@@ -86,6 +92,12 @@ export default class OpenAIGpt extends EventEmitter {
|
|
|
86
92
|
*
|
|
87
93
|
*/
|
|
88
94
|
protected pickUpQuestions(result: Array<any>, count: number, questiontype: string, score?: number): Array<QuestionItem>;
|
|
95
|
+
/**
|
|
96
|
+
* 验证JSON字符串是否是真正可转换为JSON的合法格式
|
|
97
|
+
* 这里只能做一个最简单的处理,就是用两端的符号
|
|
98
|
+
* @param jsonstr
|
|
99
|
+
*/
|
|
100
|
+
protected fixedJsonString(jsonstr: string): any[];
|
|
89
101
|
/**
|
|
90
102
|
* 将一段很长的文本,按1024长度来划分到多个中
|
|
91
103
|
* @param {*} content
|