@cobrowser/chatgpt 0.7.7 → 0.7.9
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.
|
@@ -14,7 +14,7 @@ class BaseService {
|
|
|
14
14
|
* @param maxNumberOfChoices How many chat completion choices to generate for each request.
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
|
-
constructor(apiKey = process.env.OPEN_AI_API_KEY, model = 'gpt-
|
|
17
|
+
constructor(apiKey = process.env.OPEN_AI_API_KEY, model = 'gpt-4o', apiUrl, maxNumberOfChoices = 1) {
|
|
18
18
|
Object.defineProperty(this, "request", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
configurable: true,
|
|
@@ -13,4 +13,5 @@ export declare class TranslationService extends BaseService {
|
|
|
13
13
|
translate(text: string, toLanguage?: string, fromLanguage?: string): Promise<ChatGptResponse | undefined>;
|
|
14
14
|
findTextLanguage(text: string): Promise<ChatGptResponse | undefined>;
|
|
15
15
|
getFindTextLanguagePromptMessage(text: string): string;
|
|
16
|
+
findTextLanguageBasedOnFrequency(text: string): Promise<ChatGptResponse | undefined>;
|
|
16
17
|
}
|
|
@@ -122,5 +122,43 @@ class TranslationService extends BaseService_1.default {
|
|
|
122
122
|
return `In which language is this text in '${text}'? The response should be {'languageCode': 'language_code_here', 'isError': 'true or false based on whether you did find the language code or not'}.
|
|
123
123
|
Other responses or explanations are not allowed.`;
|
|
124
124
|
}
|
|
125
|
+
findTextLanguageBasedOnFrequency(text) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
if (!text) {
|
|
128
|
+
logger_1.default.error('translation text should be provided');
|
|
129
|
+
return Promise.reject(new Error('text must be provided'));
|
|
130
|
+
}
|
|
131
|
+
text = '```' + text + '```';
|
|
132
|
+
// instruction on what to do with the text
|
|
133
|
+
const translateText = `Tell me the language ISO code of the enclosed between triple backticks ${text}
|
|
134
|
+
based on most words used. Give me the result in just one word, the ISO code of the language with most words.`,
|
|
135
|
+
// the body we need to send to the request
|
|
136
|
+
requestBody = {
|
|
137
|
+
model: this.chatGptModel,
|
|
138
|
+
response_format: { type: 'json_object' },
|
|
139
|
+
messages: [
|
|
140
|
+
{
|
|
141
|
+
role: ChatGptMessage_1.ChatGptRole.SYSTEM,
|
|
142
|
+
content: this.FIND_TEXT_LANGUAGE_SYSTEM_ROLE,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
role: ChatGptMessage_1.ChatGptRole.USER,
|
|
146
|
+
content: translateText,
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
};
|
|
150
|
+
try {
|
|
151
|
+
const response = yield this.request.post('', requestBody);
|
|
152
|
+
return {
|
|
153
|
+
firstChoice: this.getResponseFirstChoice(response),
|
|
154
|
+
usageTokens: this.getResponseUsageTokens(response),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
this.handleErrors(e);
|
|
159
|
+
return Promise.reject(e);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
125
163
|
}
|
|
126
164
|
exports.TranslationService = TranslationService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"bugs": {
|
|
40
40
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "8e46de817375da4000a023be665d1bee76724d70"
|
|
43
43
|
}
|