generaltranslation 1.1.21 → 1.1.22

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/index.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  const { _getLanguageName, _getLanguageCode } = require('./codes/codes.js');
7
7
  const { _getModelList, _getModelInfo, _getAllModelInfo, _getModelLanguages, _isLanguageSupported, _getModelsByDeveloper, _getModelsByLanguage, } = require('./models/models.js');
8
- const { _translate } = require('./translate/translate.js');
8
+ const { _translatePrompt } = require('./prompts/translate.js');
9
9
 
10
10
  // ----- CORE CLASS ----- //
11
11
 
@@ -13,10 +13,12 @@ class GT {
13
13
 
14
14
  constructor({
15
15
  apiKey = '',
16
- defaultLanguage = 'en'
16
+ defaultLanguage = 'en',
17
+ baseURL = 'https://translate.gtx.dev'
17
18
  } = {}) {
18
19
  this.apiKey = apiKey;
19
20
  this.defaultLanguage = defaultLanguage;
21
+ this.baseURL = baseURL;
20
22
  }
21
23
 
22
24
  // Language code functions
@@ -32,13 +34,11 @@ class GT {
32
34
  getModelsByLanguage = _getModelsByLanguage; // returns array of model names
33
35
  getModelsByDeveloper = _getModelsByDeveloper; // returns array of model names
34
36
 
35
- // Prompt internationalization
37
+ // Prompt I18N
36
38
  getPrompt = async (prompt, language) => {
37
- return await _translate(prompt, language, this.defaultLanguage, this.apiKey);
38
- }
39
- // Translation (same as prompt internationalization)
40
- translate = async (content, language) => {
41
- return await _translate(content, language, this.defaultLanguage, this.apiKey);
39
+ return await _translatePrompt({
40
+ content: prompt, language: language, context: this
41
+ });
42
42
  }
43
43
 
44
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "1.1.21",
3
+ "version": "1.1.22",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,7 +5,7 @@ const _shouldTranslate = item => typeof item?.translate === 'boolean' ? item.tra
5
5
 
6
6
  // Pre-processes content to send to the API
7
7
  // Separates out text that shouldn't be translated.
8
- const _processContent = (content) => {
8
+ const _processContent = ({ content }) => {
9
9
  const processed = [];
10
10
  const untranslated = [];
11
11
  if (Array.isArray(content)) {
@@ -64,16 +64,24 @@ const _constructContent = ({ content, untranslated = null}) => {
64
64
 
65
65
  // Get a translation via General Translation API
66
66
  // Returns string
67
- const _translate = async (content, language, defaultLanguage, apiKey) => {
67
+ const _translatePrompt = async ({
68
+ content, language, context
69
+ }) => {
70
+
71
+ const apiKey = context?.apiKey;
68
72
  if (!apiKey) {
69
73
  throw new Error('Missing API Key!')
70
- }
74
+ };
75
+
76
+ const defaultLanguage = context?.defaultLanguage;
71
77
  if (language === defaultLanguage) {
72
78
  return _constructContent({ content: content });
73
- }
74
- const { processed, untranslated } = _processContent(content);
79
+ };
80
+
81
+ const { processed, untranslated } = _processContent({ content });
82
+
75
83
  try {
76
- const response = await fetch('http://translate.gtx.dev', {
84
+ const response = await fetch(`${context?.baseURL}/prompt`, {
77
85
  method: 'POST',
78
86
  headers: {
79
87
  'Content-Type': 'application/json',
@@ -96,8 +104,9 @@ const _translate = async (content, language, defaultLanguage, apiKey) => {
96
104
  console.error(error)
97
105
  return _constructContent({ content: content })
98
106
  }
107
+
99
108
  }
100
109
 
101
110
  module.exports = {
102
- _translate
111
+ _translatePrompt
103
112
  }