generaltranslation 1.0.22 → 1.1.0

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
@@ -8,23 +8,32 @@ Note: this package is in active development.
8
8
 
9
9
  ## Getting Started
10
10
 
11
+ In your terminal:
12
+
11
13
  ```
12
14
  npm i generaltranslation
13
15
  ```
14
16
 
15
- ## Toolkit Functions
17
+ In your code:
18
+
19
+ ```
20
+ import GT from 'generaltranslation'
21
+ // or const GT = require('generaltranslation')
22
+
23
+ const gt = new GT()
24
+ ```
25
+
26
+ ## Language Codes
16
27
 
17
28
  ### getLanguageName(codes)
18
29
 
19
30
  Returns a language name from a two or three-letter ISO-639 language code, or an array of codes.
20
31
 
21
32
  ```
22
- import { getLanguageName } from 'generaltranslation'
23
-
24
- const language = getLanguageName('en');
33
+ const language = gt.getLanguageName('en');
25
34
  console.log(language) // 'English'
26
35
 
27
- const languages = getLanguageName(['fr', 'es'])
36
+ const languages = gt.getLanguageName(['fr', 'es'])
28
37
  console.log(languages) // ['French', 'Spanish']
29
38
  ```
30
39
 
@@ -33,27 +42,24 @@ console.log(languages) // ['French', 'Spanish']
33
42
  Returns an ISO-639 code from a language name or an array of language names.
34
43
 
35
44
  ```
36
- import { getLanguageCode } from 'generaltranslation'
37
-
38
- const code = getLanguageCode('English');
45
+ const code = gt.getLanguageCode('English');
39
46
  console.log(language) // 'en'
40
47
 
41
- const codes = getLanguageCodes(['French', 'Spanish'])
48
+ const codes = gt.getLanguageCodes(['French', 'Spanish'])
42
49
  console.log(codes) // ['fr', 'es']
43
50
  ```
44
51
 
45
- ## Async Toolkit Functions
52
+ ## Which AI models are compatible with which languages?
46
53
 
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.
54
+ 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.
48
55
 
49
56
  ### async getModelList()
50
57
 
51
58
  Get the latest list of models for which there is data. Returns an array of model names.
52
- ```
53
- import { getModelList } from 'generaltranslation'
54
59
 
60
+ ```
55
61
  async function main() {
56
- const models = await getModelList();
62
+ const models = await gt.getModelList();
57
63
  console.log(models) // ['gpt-4', ... ]
58
64
  }
59
65
 
@@ -62,13 +68,11 @@ main();
62
68
 
63
69
  ### async getModelLanguages(model)
64
70
 
65
- Get all languages known to be compatible with a given LLM. Returns an array of languages codes, [] if the model is unknown.
71
+ Get all languages known to be compatible with a given AI model. Returns an array of languages codes, or [] if the model is unknown.
66
72
 
67
73
  ```
68
- import { getModelLanguages } from 'generaltranslation'
69
-
70
74
  async function main() {
71
- const languages = await getModelLanguages('mixtral-8x7b')
75
+ const languages = await gt.getModelLanguages('mixtral-8x7b')
72
76
  console.log(languages) // ['en', 'fr', 'de', 'es', 'it']
73
77
  }
74
78
 
@@ -80,10 +84,8 @@ main();
80
84
  Returns true if a model is known to be compatible with a given language, represented by an ISO-639 language code. Returns false otherwise.
81
85
 
82
86
  ```
83
- import { isSupportedLanguage } from 'generaltranslation'
84
-
85
87
  async function main() {
86
- const supported = await isSupportedLanguage('gpt-4', 'fr')
88
+ const supported = await gt.isSupportedLanguage('gpt-4', 'fr')
87
89
  console.log(supported) // true
88
90
  }
89
91
 
package/index.js CHANGED
@@ -7,9 +7,26 @@ const { getLanguageName, getLanguageCode } = require('./codes/codes.js');
7
7
 
8
8
  const { getModelList, getModelLanguages, isLanguageSupported } = require('./models/models.js');
9
9
 
10
+ class GT {
11
+
12
+ constructor({
13
+ apiKey = '',
14
+ defaultLanguage = 'en'
15
+ } = {}) {
16
+ this.apiKey = apiKey;
17
+ this.defaultLanguage = defaultLanguage;
18
+ }
19
+
20
+ // Language code functions
21
+ getLanguageName = getLanguageName; // e.g. 'en' => 'English'
22
+ getLanguageCode = getLanguageCode; // e.g. 'English' => 'en'
23
+
24
+ getModelList = getModelList; // returns array of supported model names
25
+ getModelLanguages = getModelLanguages; // e.g. 'mistral-7b' => ['en']
26
+ isLanguageSupported = isLanguageSupported; // e.g. ('mistral-7b', 'en') => true
27
+
28
+ }
29
+
10
30
  // ----- EXPORTS ----- //
11
31
 
12
- module.exports = {
13
- getLanguageName, getLanguageCode,
14
- getModelList, getModelLanguages, isLanguageSupported
15
- }
32
+ module.exports = GT;
package/models/models.js CHANGED
@@ -1,10 +1,10 @@
1
1
  // ----- MODEL INFORMATION ----- //
2
2
 
3
- // Get all models and all languages
3
+ // Get all models
4
4
  // Returns an array of model names
5
5
  const getModelList = async () => {
6
6
  try {
7
- const result = await fetch(`https://gtx.dev/models`);
7
+ const result = await fetch(`https://data.gtx.dev/models`);
8
8
  const models = await result.json();
9
9
  return models;
10
10
  } catch (error) {
@@ -19,7 +19,7 @@ const _getModelInfo = async model => {
19
19
  if (!model) return null;
20
20
  model = model?.toLowerCase();
21
21
  try {
22
- const result = await fetch(`https://gtx.dev/model/${model}`);
22
+ const result = await fetch(`https://data.gtx.dev/model/${model}`);
23
23
  const modelInfo = await result.json();
24
24
  return modelInfo;
25
25
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "1.0.22",
3
+ "version": "1.1.0",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "index.js",
6
6
  "scripts": {