@cobrowser/chatgpt 0.5.5 → 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.
@@ -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,34 @@ 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}', 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
+ };
87
+ }
88
+ catch (e) {
89
+ this.handleErrors(e);
90
+ return Promise.reject(e);
91
+ }
92
+ });
93
+ }
65
94
  }
66
95
  exports.TranslationService = TranslationService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobrowser/chatgpt",
3
- "version": "0.5.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": "919a4a49029fcd6c8d4c100bd55ed436dee5835c"
41
+ "gitHead": "bb937a81d830e69871f1741ef3c4620204978f32"
42
42
  }