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 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 speak?
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 [] if the model is unknown.
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 [] if unknown
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- if (!apiKey) {
69
- throw new Error('Missing API Key!')
70
- }
71
- if (language === defaultLanguage) {
72
- return _constructPrompt(prompt);
73
- }
74
- const { processed, redacted } = _processPrompt(prompt);
75
- const response = await fetch('http://prompts.gtx.dev/internationalize', {
76
- method: 'POST',
77
- headers: {
78
- 'Content-Type': 'application/json',
79
- 'gtx-api-key': apiKey
80
- },
81
- body: JSON.stringify({
82
- prompt: processed,
83
- language: language,
84
- defaultLanguage: defaultLanguage
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
- if (!response.ok) {
88
- const result = await response.text();
89
- throw new Error(`${result || response.status}`);
90
- } else {
91
- const result = await response.json();
92
- return _constructPrompt({translated: result, redacted: redacted});
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