generaltranslation 1.1.10 → 1.1.11
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/README.md +2 -2
- package/models/models.js +2 -2
- package/package.json +1 -1
- package/prompts/prompts.js +29 -24
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ const codes = gt.getLanguageCodes(['French', 'Spanish'])
|
|
|
49
49
|
console.log(codes) // ['fr', 'es']
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
## Which languages do AI models
|
|
52
|
+
## Which languages do AI models understand?
|
|
53
53
|
|
|
54
54
|
We continually benchmark AI models and add new models as they are released. That means these functions have to be <code>async</code>. This information is provided as a public service. It's completely free and requires no API key.
|
|
55
55
|
|
|
@@ -68,7 +68,7 @@ main();
|
|
|
68
68
|
|
|
69
69
|
### async getModelLanguages(model)
|
|
70
70
|
|
|
71
|
-
Get all languages known to be compatible with a given AI model. Returns an array of languages codes, or
|
|
71
|
+
Get all languages known to be compatible with a given AI model. Returns an array of languages codes, or null if the model is unknown.
|
|
72
72
|
|
|
73
73
|
```
|
|
74
74
|
async function main() {
|
package/models/models.js
CHANGED
|
@@ -29,10 +29,10 @@ const _getModelInfo = async model => {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// Get all languages known to be compatible with a given LLM
|
|
32
|
-
// Returns an array of languages codes, or
|
|
32
|
+
// Returns an array of languages codes, or null if unknown
|
|
33
33
|
const _getModelLanguages = async model => {
|
|
34
34
|
const modelInfo = await _getModelInfo(model);
|
|
35
|
-
return modelInfo?.languages
|
|
35
|
+
return modelInfo?.languages;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// Returns true if a model is known to be compatible with a language
|
package/package.json
CHANGED
package/prompts/prompts.js
CHANGED
|
@@ -65,31 +65,36 @@ const _constructPrompt = ({translated, redacted = null}) => {
|
|
|
65
65
|
// Get a translated prompt via General Translation API
|
|
66
66
|
// Returns prompt string
|
|
67
67
|
const _getPrompt = async (prompt, language, defaultLanguage, apiKey) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
try {
|
|
69
|
+
if (!apiKey) {
|
|
70
|
+
throw new Error('Missing API Key!')
|
|
71
|
+
}
|
|
72
|
+
if (language === defaultLanguage) {
|
|
73
|
+
return _constructPrompt(prompt);
|
|
74
|
+
}
|
|
75
|
+
const { processed, redacted } = _processPrompt(prompt);
|
|
76
|
+
const response = await fetch('http://prompts.gtx.dev/internationalize', {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json',
|
|
80
|
+
'gtx-api-key': apiKey
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
prompt: processed,
|
|
84
|
+
language: language,
|
|
85
|
+
defaultLanguage: defaultLanguage
|
|
86
|
+
})
|
|
85
87
|
})
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
const result = await response.text();
|
|
90
|
+
throw new Error(`${result || response.status}`);
|
|
91
|
+
} else {
|
|
92
|
+
const result = await response.json();
|
|
93
|
+
return _constructPrompt({translated: result, redacted: redacted});
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error(error)
|
|
97
|
+
return _constructPrompt({ translated: prompt })
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
|