generaltranslation 1.0.20 → 1.0.21
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 +19 -1
- package/index.js +1 -1
- package/models/models.js +19 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<a href='https://www.generaltranslation.com' target="_blank">generaltranslation.com</a>
|
|
4
4
|
|
|
5
|
-
A language toolkit for AI developers
|
|
5
|
+
A language toolkit for AI developers.
|
|
6
|
+
|
|
7
|
+
Note: this package is in active development.
|
|
6
8
|
|
|
7
9
|
## Getting Started
|
|
8
10
|
|
|
@@ -42,6 +44,22 @@ console.log(codes) // ['fr', 'es']
|
|
|
42
44
|
|
|
43
45
|
## Async Toolkit Functions
|
|
44
46
|
|
|
47
|
+
As language models are continuously benchmarked, we update our data in real time. Calling these async functions is completely free and requires no API key.
|
|
48
|
+
|
|
49
|
+
### async getModelList()
|
|
50
|
+
|
|
51
|
+
Get the latest list of models for which there is data. Returns an array of model names.
|
|
52
|
+
```
|
|
53
|
+
import { getModelList } from 'generaltranslation'
|
|
54
|
+
|
|
55
|
+
async function main() {
|
|
56
|
+
const models = await getModelList();
|
|
57
|
+
console.log(models) // ['gpt-4', ... ]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main();
|
|
61
|
+
```
|
|
62
|
+
|
|
45
63
|
### async getModelLanguages(model)
|
|
46
64
|
|
|
47
65
|
Get all languages known to be compatible with a given LLM. Returns an array of languages codes, [] if the model is unknown.
|
package/index.js
CHANGED
package/models/models.js
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
// ----- MODEL INFORMATION ----- //
|
|
2
2
|
|
|
3
|
+
// Get all models and all languages
|
|
4
|
+
// Returns an array of model names
|
|
5
|
+
const getModelList = async () => {
|
|
6
|
+
try {
|
|
7
|
+
const result = await fetch(`https://gtx.dev/models`);
|
|
8
|
+
const models = await result.json();
|
|
9
|
+
return models;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(error);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
3
16
|
// Get all info about a given model
|
|
4
17
|
// Returns an object or null if invalid
|
|
5
|
-
const
|
|
18
|
+
const _getModelInfo = async model => {
|
|
6
19
|
if (!model) return null;
|
|
7
20
|
model = model?.toLowerCase();
|
|
8
21
|
try {
|
|
9
22
|
const result = await fetch(`https://gtx.dev/model/${model}`);
|
|
10
23
|
const modelInfo = await result.json();
|
|
11
24
|
return modelInfo;
|
|
12
|
-
} catch {
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(error)
|
|
13
27
|
return null;
|
|
14
28
|
}
|
|
15
29
|
}
|
|
@@ -17,19 +31,20 @@ const getModelInfo = async model => {
|
|
|
17
31
|
// Get all languages known to be compatible with a given LLM
|
|
18
32
|
// Returns an array of languages codes, or [] if unknown
|
|
19
33
|
const getModelLanguages = async model => {
|
|
20
|
-
const modelInfo = await
|
|
34
|
+
const modelInfo = await _getModelInfo(model);
|
|
21
35
|
return modelInfo?.languages || [];
|
|
22
36
|
}
|
|
23
37
|
|
|
24
38
|
// Returns true if a model is known to be compatible with a language
|
|
25
39
|
// Returns false otherwise
|
|
26
40
|
const isLanguageSupported = async (model, code) => {
|
|
41
|
+
if (!code) return false;
|
|
27
42
|
const modelLanguages = await getModelLanguages(model);
|
|
28
43
|
return modelLanguages?.includes(code) ? true : false;
|
|
29
44
|
}
|
|
30
45
|
|
|
31
46
|
module.exports = {
|
|
32
|
-
|
|
47
|
+
getModelList,
|
|
33
48
|
getModelLanguages,
|
|
34
49
|
isLanguageSupported
|
|
35
50
|
}
|