doomiaichat 2.6.0 → 2.7.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 +0 -1
- package/dist/openai.d.ts +2 -2
- package/dist/openai.js +18 -2
- package/package.json +1 -1
- package/src/azureai.ts +0 -1
- package/src/openai.ts +17 -3
package/dist/azureai.js
CHANGED
|
@@ -50,7 +50,6 @@ class AzureAI extends openai_1.default {
|
|
|
50
50
|
let param = Object.assign(Object.assign({}, axiosOption), { method: "post", data: {
|
|
51
51
|
input: text
|
|
52
52
|
}, url: this.EmbeddingUrl });
|
|
53
|
-
console.log('param', param);
|
|
54
53
|
const response = yield (0, declare_1.request)(param);
|
|
55
54
|
if (response.data) {
|
|
56
55
|
return { successed: true, embedding: response.data.data[0].embedding };
|
package/dist/openai.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAIApi, ChatCompletionRequestMessage } from "openai";
|
|
2
2
|
import GptBase from "./gptbase";
|
|
3
|
-
import { OpenAIApiParameters, ChatReponse, SummaryReponse, FaqItem, ExaminationPaperResult, EmotionResult, SimilarityResult, QuestionItem, CommentResult } from './declare';
|
|
3
|
+
import { OpenAIApiParameters, ChatReponse, SummaryReponse, FaqItem, ExaminationPaperResult, EmotionResult, SimilarityResult, QuestionItem, CommentResult, EmbeddingResult } from './declare';
|
|
4
4
|
export default class OpenAIGpt extends GptBase {
|
|
5
5
|
protected readonly apiKey: string;
|
|
6
6
|
private aiApi;
|
|
@@ -21,7 +21,7 @@ export default class OpenAIGpt extends GptBase {
|
|
|
21
21
|
* 获得文字的向量
|
|
22
22
|
* @param text
|
|
23
23
|
*/
|
|
24
|
-
getTextEmbedding(
|
|
24
|
+
getTextEmbedding(text: string, axiosOption: any): Promise<EmbeddingResult>;
|
|
25
25
|
/**
|
|
26
26
|
* 向OpenAI发送一个聊天请求
|
|
27
27
|
* @param {*} chatText
|
package/dist/openai.js
CHANGED
|
@@ -48,9 +48,25 @@ class OpenAIGpt extends gptbase_1.default {
|
|
|
48
48
|
* 获得文字的向量
|
|
49
49
|
* @param text
|
|
50
50
|
*/
|
|
51
|
-
getTextEmbedding(
|
|
51
|
+
getTextEmbedding(text, axiosOption) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
|
|
53
|
+
if (!text)
|
|
54
|
+
return { successed: false, error: { errcode: 2, errmsg: 'content required' } };
|
|
55
|
+
if (!this.aiApi) {
|
|
56
|
+
this.aiApi = this.createOpenAI(this.apiKey);
|
|
57
|
+
}
|
|
58
|
+
// console.log('message', message)
|
|
59
|
+
try {
|
|
60
|
+
const response = yield this.aiApi.createEmbedding({
|
|
61
|
+
model: 'text-embedding-ada-002',
|
|
62
|
+
input: text,
|
|
63
|
+
}, axiosOption);
|
|
64
|
+
return { successed: true, embedding: response.data.data[0].embedding };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.log('result is error ', error);
|
|
68
|
+
return { successed: false, error };
|
|
69
|
+
}
|
|
54
70
|
});
|
|
55
71
|
}
|
|
56
72
|
/**
|
package/package.json
CHANGED
package/src/azureai.ts
CHANGED
package/src/openai.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Configuration, OpenAIApi, ChatCompletionRequestMessage } from "openai"
|
|
2
2
|
// import { EventEmitter } from "events";
|
|
3
3
|
import GptBase from "./gptbase"
|
|
4
|
-
import { OpenAIApiParameters, ChatReponse, OutlineSummaryItem, SummaryReponse, FaqItem, ExaminationPaperResult, EmotionResult, SimilarityResult, QuestionItem, CommentResult } from './declare'
|
|
4
|
+
import { OpenAIApiParameters, ChatReponse, OutlineSummaryItem, SummaryReponse, FaqItem, ExaminationPaperResult, EmotionResult, SimilarityResult, QuestionItem, CommentResult, EmbeddingResult } from './declare'
|
|
5
5
|
const SECTION_LENGTH = 1600; ///每2400个字符分成一组
|
|
6
6
|
const MESSAGE_LENGTH = 1; ///每次送8句话给openai 进行解析,送多了,会报错
|
|
7
7
|
//请将答案放在最后,标记为答案:()
|
|
@@ -43,8 +43,22 @@ export default class OpenAIGpt extends GptBase {
|
|
|
43
43
|
* 获得文字的向量
|
|
44
44
|
* @param text
|
|
45
45
|
*/
|
|
46
|
-
async getTextEmbedding(
|
|
47
|
-
return
|
|
46
|
+
async getTextEmbedding(text: string, axiosOption: any): Promise<EmbeddingResult>{
|
|
47
|
+
if (!text) return { successed: false, error: { errcode: 2, errmsg: 'content required' } };
|
|
48
|
+
if (!this.aiApi) {
|
|
49
|
+
this.aiApi = this.createOpenAI(this.apiKey);
|
|
50
|
+
}
|
|
51
|
+
// console.log('message', message)
|
|
52
|
+
try {
|
|
53
|
+
const response:any = await this.aiApi.createEmbedding({
|
|
54
|
+
model:'text-embedding-ada-002',
|
|
55
|
+
input: text,
|
|
56
|
+
}, axiosOption);
|
|
57
|
+
return { successed: true, embedding: response.data.data[0].embedding };
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.log('result is error ', error)
|
|
60
|
+
return { successed: false, error };
|
|
61
|
+
}
|
|
48
62
|
}
|
|
49
63
|
/**
|
|
50
64
|
* 向OpenAI发送一个聊天请求
|