generaltranslation 1.0.12 → 1.0.14

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.
Files changed (2) hide show
  1. package/models/models.js +28 -12
  2. package/package.json +1 -1
package/models/models.js CHANGED
@@ -1,30 +1,46 @@
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
+ const results = await Promise.all([
10
+ fetch('https://data.gtx.dev/models.json'),
11
+ fetch('https://data.gtx.dev/alias_to_model.json')
12
+ ])
13
+ const values = await Promise.all([
14
+ results[0].json(),
15
+ results[1].json()
16
+ ])
17
+ Models = values[0];
18
+ AliasToModel = values[1];
19
+ }
20
+ return [Models, AliasToModel];
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
+ const [Models, AliasToModel] = await fetchModelData();
6
29
  model = model?.toLowerCase();
7
- try {
8
- const result = await fetch(`https://gtx.dev/model/${model}`);
9
- const modelInfo = await result.json();
10
- return modelInfo;
11
- } catch {
12
- return null;
13
- }
30
+ const modelName = AliasToModel ? AliasToModel[model] : model;
31
+ return Models ? Models[modelName] : null;
14
32
  }
15
33
 
16
34
  // Get all languages known to be compatible with a given LLM
17
35
  // Returns an array of languages codes, [] if unknown
18
36
  const getModelLanguages = async model => {
19
- const modelInfo = await getModelInfo(model);
20
- return modelInfo?.languages || [];
37
+ return (await getModelInfo(model))?.languages || [];
21
38
  }
22
39
 
23
40
  // Returns true if a model is known to be compatible with a language
24
41
  // Returns false otherwise
25
- const isLanguageSupported = async (model, code) => {
26
- const modelLanguages = await getModelLanguages(model);
27
- return modelLanguages?.includes(code);
42
+ const isLanguageSupported = async(model, code) => {
43
+ return (await getModelLanguages(model))?.includes(code);
28
44
  }
29
45
 
30
46
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "index.js",
6
6
  "scripts": {