@cobrowser/chatgpt 0.5.5 → 0.5.7
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.
|
@@ -9,4 +9,5 @@ export declare class TranslationService extends BaseService {
|
|
|
9
9
|
* @param fromLanguage if we want to specify the language of the text, we can use this ( optional)
|
|
10
10
|
*/
|
|
11
11
|
translate(text: string, toLanguage?: string, fromLanguage?: string): Promise<any | undefined>;
|
|
12
|
+
findTextLanguage(text: string): Promise<any | undefined>;
|
|
12
13
|
}
|
|
@@ -62,5 +62,36 @@ class TranslationService extends BaseService_1.default {
|
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
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}', The response should be
|
|
73
|
+
{languageCode: "Code_here", isError: 'true or false based on if you did fine the language code or not'}
|
|
74
|
+
other responses or explanation are not allowed `,
|
|
75
|
+
// the body we need to send to the request
|
|
76
|
+
requestBody = {
|
|
77
|
+
model: this.chatGptModel,
|
|
78
|
+
messages: [{
|
|
79
|
+
role: ChatGptMessage_1.ChatGptRole.USER,
|
|
80
|
+
content: translateText,
|
|
81
|
+
}],
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const response = yield this.request.post('', requestBody);
|
|
85
|
+
return {
|
|
86
|
+
firstChoice: this.getResponseFirstChoice(response),
|
|
87
|
+
usageTokens: this.getResponseUsageTokens(response),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
this.handleErrors(e);
|
|
92
|
+
return Promise.reject(e);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
65
96
|
}
|
|
66
97
|
exports.TranslationService = TranslationService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
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": "02bdaba1e870f2c432eca0c822256357ea028973"
|
|
42
42
|
}
|