doomiaichat 6.0.6 → 6.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 +1 -1
- package/dist/azureai.js +25 -16
- package/dist/declare.d.ts +2 -1
- package/dist/openai.d.ts +1 -1
- package/dist/openai.js +1 -3
- package/package.json +1 -1
- package/src/azureai.ts +27 -22
- package/src/declare.ts +2 -1
- package/src/openai.ts +2 -4
package/dist/azureai.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export default class AzureAI extends OpenAIBase<OpenAIClient> {
|
|
|
16
16
|
* 获得文字的向量
|
|
17
17
|
* @param text
|
|
18
18
|
*/
|
|
19
|
-
getTextEmbedding(text: string,
|
|
19
|
+
getTextEmbedding(text: string | string[], callOption?: any): Promise<EmbeddingResult>;
|
|
20
20
|
/**
|
|
21
21
|
* 非流式聊天请求
|
|
22
22
|
* @param _chatText
|
package/dist/azureai.js
CHANGED
|
@@ -23,7 +23,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
* 微软AZure OpenAI
|
|
24
24
|
*/
|
|
25
25
|
const openaibase_1 = __importDefault(require("./openaibase"));
|
|
26
|
-
const declare_1 = require("./declare");
|
|
27
26
|
const openai_1 = require("@azure/openai");
|
|
28
27
|
class AzureAI extends openaibase_1.default {
|
|
29
28
|
constructor(apiKey, azureOption, apiOption = {}) {
|
|
@@ -46,26 +45,36 @@ class AzureAI extends openaibase_1.default {
|
|
|
46
45
|
* 获得文字的向量
|
|
47
46
|
* @param text
|
|
48
47
|
*/
|
|
49
|
-
getTextEmbedding(text,
|
|
48
|
+
getTextEmbedding(text, callOption = {}) {
|
|
50
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
50
|
if (!text)
|
|
52
51
|
return { successed: false, error: { errcode: 2, errmsg: 'content required' } };
|
|
53
|
-
if (!
|
|
54
|
-
|
|
55
|
-
else {
|
|
56
|
-
axiosOption.headers['api-key'] = this.apiKey;
|
|
57
|
-
axiosOption.headers['Content-Type'] = 'application/json';
|
|
58
|
-
}
|
|
52
|
+
if (!this.aiApi)
|
|
53
|
+
this.aiApi = this.createOpenAI(this.apiKey);
|
|
59
54
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}, url: this.EmbeddingUrl });
|
|
63
|
-
const response = yield (0, declare_1.request)(param);
|
|
64
|
-
if (response.successed && response.data) {
|
|
65
|
-
return { successed: true, embedding: response.data.data[0].embedding };
|
|
66
|
-
}
|
|
67
|
-
return Object.assign({ successed: false }, response.data);
|
|
55
|
+
const result = yield this.aiApi.getEmbeddings(this.embeddingmodel || 'openai-embedding-ada-002', typeof text === 'string' ? [text] : text, callOption);
|
|
56
|
+
return { successed: true, embedding: result.data };
|
|
68
57
|
}
|
|
58
|
+
// if (!axiosOption.headers)
|
|
59
|
+
// axiosOption.headers = { 'api-key': this.apiKey, 'Content-Type': 'application/json' };
|
|
60
|
+
// else {
|
|
61
|
+
// axiosOption.headers['api-key'] = this.apiKey;
|
|
62
|
+
// axiosOption.headers['Content-Type'] = 'application/json';
|
|
63
|
+
// }
|
|
64
|
+
// try {
|
|
65
|
+
// let param = {
|
|
66
|
+
// ...axiosOption,
|
|
67
|
+
// method: "post",
|
|
68
|
+
// data: {
|
|
69
|
+
// input: text
|
|
70
|
+
// },
|
|
71
|
+
// url: this.EmbeddingUrl
|
|
72
|
+
// };
|
|
73
|
+
// const response = await request(param)
|
|
74
|
+
// if (response.successed && response.data) {
|
|
75
|
+
// return { successed: true, embedding: response.data.data[0].embedding };
|
|
76
|
+
// }
|
|
77
|
+
// return { successed: false, ...response.data };
|
|
69
78
|
catch (error) {
|
|
70
79
|
return { successed: false, error };
|
|
71
80
|
}
|
package/dist/declare.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EmbeddingItem } from '@azure/openai';
|
|
1
2
|
export interface ApiResult {
|
|
2
3
|
/**
|
|
3
4
|
* return the result of api called
|
|
@@ -58,7 +59,7 @@ export interface AzureOpenAIPatameters {
|
|
|
58
59
|
* 调用OpenAI Api的向量约定
|
|
59
60
|
*/
|
|
60
61
|
export interface EmbeddingResult extends ApiResult {
|
|
61
|
-
'embedding'?:
|
|
62
|
+
'embedding'?: EmbeddingItem[];
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
64
65
|
* 远程请求的返回
|
package/dist/openai.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export default class OpenAIGpt extends OpenAIBase<OpenAI> {
|
|
|
13
13
|
* 获得文字的向量
|
|
14
14
|
* @param text
|
|
15
15
|
*/
|
|
16
|
-
getTextEmbedding(text: string, axiosOption: any): Promise<EmbeddingResult>;
|
|
16
|
+
getTextEmbedding(text: string | string[], axiosOption: any): Promise<EmbeddingResult>;
|
|
17
17
|
/**
|
|
18
18
|
* 向OpenAI发送一个聊天请求
|
|
19
19
|
* @param {*} chatText
|
package/dist/openai.js
CHANGED
|
@@ -45,15 +45,13 @@ class OpenAIGpt extends openaibase_1.default {
|
|
|
45
45
|
this.aiApi = this.createOpenAI(this.apiKey);
|
|
46
46
|
}
|
|
47
47
|
try {
|
|
48
|
-
//const response: any = await this.aiApi.createEmbedding({
|
|
49
48
|
const response = yield this.aiApi.embeddings.create({
|
|
50
49
|
model: this.embeddingmodel,
|
|
51
50
|
input: text,
|
|
52
51
|
}, axiosOption);
|
|
53
|
-
return { successed: true, embedding: response.data.data[0].embedding };
|
|
52
|
+
return { successed: true, embedding: response.data.data }; //[0].embedding };
|
|
54
53
|
}
|
|
55
54
|
catch (error) {
|
|
56
|
-
// console.log('result is error ', error)
|
|
57
55
|
return { successed: false, error };
|
|
58
56
|
}
|
|
59
57
|
});
|
package/package.json
CHANGED
package/src/azureai.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 微软AZure OpenAI
|
|
3
3
|
*/
|
|
4
4
|
import OpenAIBase from "./openaibase"
|
|
5
|
-
import { AzureOpenAIPatameters, ChatReponse, EmbeddingResult, OpenAIApiParameters
|
|
5
|
+
import { AzureOpenAIPatameters, ChatReponse, EmbeddingResult, OpenAIApiParameters} from "./declare";
|
|
6
6
|
import { OpenAIClient, AzureKeyCredential } from "@azure/openai";
|
|
7
7
|
export default class AzureAI extends OpenAIBase<OpenAIClient> {
|
|
8
8
|
|
|
@@ -29,30 +29,35 @@ export default class AzureAI extends OpenAIBase<OpenAIClient> {
|
|
|
29
29
|
* 获得文字的向量
|
|
30
30
|
* @param text
|
|
31
31
|
*/
|
|
32
|
-
override async getTextEmbedding(text: string,
|
|
32
|
+
override async getTextEmbedding(text: string|string[], callOption: any = {}): Promise<EmbeddingResult> {
|
|
33
33
|
if (!text) return { successed: false, error: { errcode: 2, errmsg: 'content required' } };
|
|
34
|
-
if (!
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
axiosOption.headers['Content-Type'] = 'application/json';
|
|
34
|
+
if (!this.aiApi) this.aiApi = this.createOpenAI(this.apiKey);
|
|
35
|
+
try{
|
|
36
|
+
const result = await this.aiApi.getEmbeddings(this.embeddingmodel || 'openai-embedding-ada-002', typeof text === 'string' ? [text] : text, callOption)
|
|
37
|
+
return { successed: true, embedding:result.data };
|
|
39
38
|
}
|
|
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
|
+
// }
|
|
40
45
|
|
|
41
|
-
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
// try {
|
|
47
|
+
// let param = {
|
|
48
|
+
// ...axiosOption,
|
|
49
|
+
// method: "post",
|
|
50
|
+
// data: {
|
|
51
|
+
// input: text
|
|
52
|
+
// },
|
|
53
|
+
// url: this.EmbeddingUrl
|
|
54
|
+
// };
|
|
55
|
+
// const response = await request(param)
|
|
56
|
+
// if (response.successed && response.data) {
|
|
57
|
+
// return { successed: true, embedding: response.data.data[0].embedding };
|
|
58
|
+
// }
|
|
59
|
+
// return { successed: false, ...response.data };
|
|
60
|
+
catch (error) {
|
|
56
61
|
return { successed: false, error };
|
|
57
62
|
}
|
|
58
63
|
}
|
package/src/declare.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
import { EmbeddingItem } from '@azure/openai';
|
|
2
3
|
import axios from 'axios';
|
|
3
4
|
export interface ApiResult {
|
|
4
5
|
/**
|
|
@@ -63,7 +64,7 @@ export interface AzureOpenAIPatameters {
|
|
|
63
64
|
* 调用OpenAI Api的向量约定
|
|
64
65
|
*/
|
|
65
66
|
export interface EmbeddingResult extends ApiResult {
|
|
66
|
-
'embedding'?:
|
|
67
|
+
'embedding'?: EmbeddingItem[],
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* 远程请求的返回
|
package/src/openai.ts
CHANGED
|
@@ -18,20 +18,18 @@ export default class OpenAIGpt extends OpenAIBase<OpenAI> {
|
|
|
18
18
|
* 获得文字的向量
|
|
19
19
|
* @param text
|
|
20
20
|
*/
|
|
21
|
-
override async getTextEmbedding(text: string, axiosOption: any): Promise<EmbeddingResult> {
|
|
21
|
+
override async getTextEmbedding(text: string|string[], axiosOption: any): Promise<EmbeddingResult> {
|
|
22
22
|
if (!text) return { successed: false, error: { errcode: 2, errmsg: 'content required' } };
|
|
23
23
|
if (!this.aiApi) {
|
|
24
24
|
this.aiApi = this.createOpenAI(this.apiKey);
|
|
25
25
|
}
|
|
26
26
|
try {
|
|
27
|
-
//const response: any = await this.aiApi.createEmbedding({
|
|
28
27
|
const response: any = await this.aiApi.embeddings.create({
|
|
29
28
|
model: this.embeddingmodel,
|
|
30
29
|
input: text,
|
|
31
30
|
}, axiosOption);
|
|
32
|
-
return { successed: true, embedding: response.data.data[0].embedding };
|
|
31
|
+
return { successed: true, embedding: response.data.data};//[0].embedding };
|
|
33
32
|
} catch (error) {
|
|
34
|
-
// console.log('result is error ', error)
|
|
35
33
|
return { successed: false, error };
|
|
36
34
|
}
|
|
37
35
|
}
|