generaltranslation 1.1.14 → 1.1.15
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/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
const { _getLanguageName, _getLanguageCode } = require('./codes/codes.js');
|
|
7
7
|
const { _getModelList, _getModelLanguages, _isLanguageSupported } = require('./models/models.js');
|
|
8
|
-
const {
|
|
8
|
+
const { _translate } = require('./translate/translate.js');
|
|
9
9
|
|
|
10
10
|
// ----- CORE CLASS ----- //
|
|
11
11
|
|
|
@@ -30,9 +30,15 @@ class GT {
|
|
|
30
30
|
|
|
31
31
|
// Prompt internationalization
|
|
32
32
|
getPrompt = async (prompt, code) => {
|
|
33
|
-
return await
|
|
33
|
+
return await _translate(prompt, code, this.defaultLanguage, this.apiKey);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// Translation (same as prompt internationalization)
|
|
37
|
+
translate = async (prompt, code) => {
|
|
38
|
+
return await _translate(prompt, code, this.defaultLanguage, this.apiKey);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
// ----- EXPORTS ----- //
|
package/package.json
CHANGED
|
@@ -62,9 +62,9 @@ const _constructPrompt = ({translated, redacted = null}) => {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
// Get a
|
|
66
|
-
// Returns
|
|
67
|
-
const
|
|
65
|
+
// Get a translation via General Translation API
|
|
66
|
+
// Returns string
|
|
67
|
+
const _translate = async (prompt, code, defaultLanguage, apiKey) => {
|
|
68
68
|
try {
|
|
69
69
|
if (!apiKey) {
|
|
70
70
|
throw new Error('Missing API Key!')
|
|
@@ -73,7 +73,7 @@ const _getPrompt = async (prompt, code, defaultLanguage, apiKey) => {
|
|
|
73
73
|
return _constructPrompt(prompt);
|
|
74
74
|
}
|
|
75
75
|
const { processed, redacted } = _processPrompt(prompt);
|
|
76
|
-
const response = await fetch('http://
|
|
76
|
+
const response = await fetch('http://prompts.gtx.dev/internationalize', {
|
|
77
77
|
method: 'POST',
|
|
78
78
|
headers: {
|
|
79
79
|
'Content-Type': 'application/json',
|
|
@@ -99,5 +99,5 @@ const _getPrompt = async (prompt, code, defaultLanguage, apiKey) => {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
module.exports = {
|
|
102
|
-
|
|
102
|
+
_translate
|
|
103
103
|
}
|