@cobrowser/chatgpt 0.5.4 → 0.5.6
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.
|
@@ -8,5 +8,6 @@ export declare class TranslationService extends BaseService {
|
|
|
8
8
|
* @param toLanguage the desired language to translate to ( English is the default )
|
|
9
9
|
* @param fromLanguage if we want to specify the language of the text, we can use this ( optional)
|
|
10
10
|
*/
|
|
11
|
-
translate(text: string, toLanguage?: string, fromLanguage?: string): Promise<
|
|
11
|
+
translate(text: string, toLanguage?: string, fromLanguage?: string): Promise<any | undefined>;
|
|
12
|
+
findTextLanguage(text: string): Promise<any | undefined>;
|
|
12
13
|
}
|
|
@@ -51,7 +51,39 @@ class TranslationService extends BaseService_1.default {
|
|
|
51
51
|
};
|
|
52
52
|
try {
|
|
53
53
|
const response = yield this.request.post('', requestBody);
|
|
54
|
-
return
|
|
54
|
+
return {
|
|
55
|
+
firstChoice: this.getResponseFirstChoice(response),
|
|
56
|
+
usageTokens: this.getResponseUsageTokens(response),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
this.handleErrors(e);
|
|
61
|
+
return Promise.reject(e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
findTextLanguage(text) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
if (!text) {
|
|
68
|
+
logger_1.default.error('translation text should be provided');
|
|
69
|
+
return Promise.reject(new Error('text must be provided'));
|
|
70
|
+
}
|
|
71
|
+
// instruction on what to do with the text
|
|
72
|
+
const translateText = `In which language is this text in '${text}', return language code in json`,
|
|
73
|
+
// the body we need to send to the request
|
|
74
|
+
requestBody = {
|
|
75
|
+
model: this.chatGptModel,
|
|
76
|
+
messages: [{
|
|
77
|
+
role: ChatGptMessage_1.ChatGptRole.USER,
|
|
78
|
+
content: translateText,
|
|
79
|
+
}],
|
|
80
|
+
};
|
|
81
|
+
try {
|
|
82
|
+
const response = yield this.request.post('', requestBody);
|
|
83
|
+
return {
|
|
84
|
+
firstChoice: this.getResponseFirstChoice(response),
|
|
85
|
+
usageTokens: this.getResponseUsageTokens(response),
|
|
86
|
+
};
|
|
55
87
|
}
|
|
56
88
|
catch (e) {
|
|
57
89
|
this.handleErrors(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"bugs": {
|
|
39
39
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "bb937a81d830e69871f1741ef3c4620204978f32"
|
|
42
42
|
}
|