generaltranslation 1.0.17 → 1.0.19
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/models/models.js +14 -36
- package/package.json +1 -1
package/models/models.js
CHANGED
|
@@ -1,53 +1,31 @@
|
|
|
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
|
-
try {
|
|
9
|
-
console.log('Fetching model data...');
|
|
10
|
-
if (!Models || !AliasToModel) {
|
|
11
|
-
const results = await Promise.all([
|
|
12
|
-
fetch('https://data.gtx.dev/models.json'),
|
|
13
|
-
fetch('https://data.gtx.dev/alias_to_model.json')
|
|
14
|
-
])
|
|
15
|
-
const values = await Promise.all([
|
|
16
|
-
results[0].json(),
|
|
17
|
-
results[1].json()
|
|
18
|
-
])
|
|
19
|
-
Models = values[0];
|
|
20
|
-
AliasToModel = values[1];
|
|
21
|
-
}
|
|
22
|
-
return [Models, AliasToModel];
|
|
23
|
-
} catch (error) {
|
|
24
|
-
console.error(error);
|
|
25
|
-
return [Models, AliasToModel];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
1
|
// ----- MODEL INFORMATION ----- //
|
|
30
2
|
|
|
31
3
|
// Get all info about a given model
|
|
32
4
|
// Returns an object or null if invalid
|
|
33
5
|
const getModelInfo = async model => {
|
|
34
|
-
|
|
35
|
-
console.log(Models, AliasToModel)
|
|
6
|
+
if (!model) return null;
|
|
36
7
|
model = model?.toLowerCase();
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
try {
|
|
9
|
+
const result = await fetch(`https://gtx.dev/model/${model}`);
|
|
10
|
+
const modelInfo = await result.json();
|
|
11
|
+
return modelInfo;
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
39
15
|
}
|
|
40
16
|
|
|
41
17
|
// Get all languages known to be compatible with a given LLM
|
|
42
|
-
// Returns an array of languages codes, [] if unknown
|
|
18
|
+
// Returns an array of languages codes, or [] if unknown
|
|
43
19
|
const getModelLanguages = async model => {
|
|
44
|
-
|
|
20
|
+
const modelInfo = await getModelInfo(model);
|
|
21
|
+
return modelInfo?.languages || [];
|
|
45
22
|
}
|
|
46
23
|
|
|
47
24
|
// Returns true if a model is known to be compatible with a language
|
|
48
25
|
// Returns false otherwise
|
|
49
|
-
const isLanguageSupported = async(model, code) => {
|
|
50
|
-
|
|
26
|
+
const isLanguageSupported = async (model, code) => {
|
|
27
|
+
const modelLanguages = await getModelLanguages(model);
|
|
28
|
+
return modelLanguages?.includes(code) ? true : false;
|
|
51
29
|
}
|
|
52
30
|
|
|
53
31
|
module.exports = {
|