generaltranslation 1.0.11 → 1.0.13

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
@@ -57,7 +57,7 @@ async function main() {
57
57
  main();
58
58
  ```
59
59
 
60
- ### isSupportedLanguage(model, language)
60
+ ### async isSupportedLanguage(model, language)
61
61
 
62
62
  Returns true if a model is known to be compatible with a given language, represented by an ISO-639 language code. Returns false otherwise.
63
63
 
package/models/models.js CHANGED
@@ -1,12 +1,34 @@
1
+ // ----- IMPORTS ----- //
2
+
3
+ let Models = null;
4
+ let AliasToModel = null;
5
+
6
+ // Fetches models and aliases from the server and caches them
7
+ const fetchModelData = async () => {
8
+ if (!Models || !AliasToModel) {
9
+ console.log('fetching model data...')
10
+ const results = await Promise.all([
11
+ fetch('https://data.gtx.dev/models.json'),
12
+ fetch('https://data.gtx.dev/alias_to_model.json')
13
+ ])
14
+ const values = await Promise.all([
15
+ results[0].json(),
16
+ results[1].json()
17
+ ])
18
+ Models = values[0];
19
+ AliasToModel = values[1];
20
+ }
21
+ }
22
+
1
23
  // ----- MODEL INFORMATION ----- //
2
24
 
3
25
  // Get all info about a given model
4
26
  // Returns an object or null if invalid
5
27
  const getModelInfo = async model => {
28
+ await fetchModelData();
6
29
  model = model?.toLowerCase();
7
- const result = await fetch(`https://gtx.dev/model/${model}`);
8
- const modelInfo = await result.json();
9
- return modelInfo;
30
+ const modelName = AliasToModel[model] || model;
31
+ return Models[modelName]
10
32
  }
11
33
 
12
34
  // Get all languages known to be compatible with a given LLM
@@ -17,7 +39,7 @@ const getModelLanguages = async model => {
17
39
 
18
40
  // Returns true if a model is known to be compatible with a language
19
41
  // Returns false otherwise
20
- const isLanguageSupported = async (model, code) => {
42
+ const isLanguageSupported = async(model, code) => {
21
43
  return (await getModelLanguages(model))?.includes(code);
22
44
  }
23
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "index.js",
6
6
  "scripts": {