generaltranslation 1.1.24 → 1.1.25
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 +43 -20
- package/client/getUserLanguage.js +1 -1
- package/index.js +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,35 +54,27 @@ const codes = gt.getLanguageCodes(['French', 'Spanish'])
|
|
|
54
54
|
console.log(codes) // ['fr', 'es']
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
##
|
|
57
|
+
## Get a user's language
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
### getUserLanguage()
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Get the latest list of models for which there is data. Returns an array of model names.
|
|
61
|
+
Returns a user's default browser language. Meant for use in a web browser.
|
|
64
62
|
|
|
65
63
|
```
|
|
66
|
-
const
|
|
67
|
-
console.log(
|
|
64
|
+
const userLanguage = getUserLanguage();
|
|
65
|
+
console.log(userLanguage) // 'en'
|
|
68
66
|
```
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
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.
|
|
68
|
+
If invoked on an instance of the GT class, this function will return the default language of that instance, similar to accessing the `defaultLanguage` property.
|
|
73
69
|
|
|
74
70
|
```
|
|
75
|
-
|
|
76
|
-
console.log(languages) // ['en', 'fr', 'de', 'es', 'it']
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### async isSupportedLanguage(model, code)
|
|
71
|
+
import GT from 'generaltranslation'
|
|
80
72
|
|
|
81
|
-
|
|
73
|
+
const gt = new GT({
|
|
74
|
+
defaultLanguage: 'en'
|
|
75
|
+
});
|
|
82
76
|
|
|
83
|
-
|
|
84
|
-
const supported = await gt.isSupportedLanguage('gpt-4', 'fr')
|
|
85
|
-
console.log(supported) // true
|
|
77
|
+
console.log(gt.getUserLanguage()) // same as gt.defaultLanguage
|
|
86
78
|
```
|
|
87
79
|
|
|
88
80
|
## Prompt Internationalization API
|
|
@@ -149,4 +141,35 @@ This also works:
|
|
|
149
141
|
|
|
150
142
|
```
|
|
151
143
|
const translatedPrompt = await gt.translatePrompt({ text: 'Tell me a story' }, 'es');
|
|
152
|
-
```
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Which languages do AI models understand?
|
|
147
|
+
|
|
148
|
+
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.
|
|
149
|
+
|
|
150
|
+
### async getModelList()
|
|
151
|
+
|
|
152
|
+
Get the latest list of models for which there is data. Returns an array of model names.
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
const models = await gt.getModelList();
|
|
156
|
+
console.log(models) // ['gpt-4', ... ]
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### async getModelLanguages(model)
|
|
160
|
+
|
|
161
|
+
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.
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
const languages = await gt.getModelLanguages('mixtral-8x7b')
|
|
165
|
+
console.log(languages) // ['en', 'fr', 'de', 'es', 'it']
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### async isSupportedLanguage(model, code)
|
|
169
|
+
|
|
170
|
+
Returns true if a model is known to be compatible with a given language, represented by an ISO-639 language code. Returns false otherwise.
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
const supported = await gt.isSupportedLanguage('gpt-4', 'fr')
|
|
174
|
+
console.log(supported) // true
|
|
175
|
+
```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// e.g. 'en-US', not necessarily 'en'
|
|
3
3
|
// generaltranslation handles this well, but other libraries may not
|
|
4
4
|
// (it's a skill issue I'm afraid)
|
|
5
|
-
export default function _getUserLanguage(defaultLanguage = '') {
|
|
5
|
+
export default function _getUserLanguage({defaultLanguage = ''} = {}) {
|
|
6
6
|
if (typeof window !== 'undefined' && window?.navigator) {
|
|
7
7
|
return navigator?.language || navigator?.userLanguage || defaultLanguage || '';
|
|
8
8
|
} else if (defaultLanguage) {
|
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ export default class GT {
|
|
|
17
17
|
defaultLanguage = 'en',
|
|
18
18
|
baseURL = 'https://translate.gtx.dev'
|
|
19
19
|
} = {}) {
|
|
20
|
-
this.apiKey = apiKey;
|
|
20
|
+
this.apiKey = apiKey || (typeof process !== 'undefined' ? process.env.GT_API_KEY : '');
|
|
21
21
|
this.defaultLanguage = defaultLanguage;
|
|
22
22
|
this.baseURL = baseURL;
|
|
23
23
|
}
|
|
@@ -36,7 +36,9 @@ export default class GT {
|
|
|
36
36
|
|
|
37
37
|
// Get a user's browser language
|
|
38
38
|
getUserLanguage = () => {
|
|
39
|
-
return _getUserLanguage(
|
|
39
|
+
return _getUserLanguage({
|
|
40
|
+
defaultLanguage: this.defaultLanguage
|
|
41
|
+
});
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
// Prompt I18N
|