auto-translate-json-library 1.3.6 → 1.3.8
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 +32 -1
- package/build/package.json +12 -12
- package/build/src/bin/cli.js +9 -0
- package/build/src/config.d.ts +8 -0
- package/build/src/index.js +9 -0
- package/build/src/lib.js +1 -1
- package/build/src/openai.d.ts +8 -1
- package/build/src/openai.js +26 -9
- package/package.json +12 -12
package/README.MD
CHANGED
|
@@ -4,9 +4,15 @@ This project is used in, (and refactored from) excellent vs code extension
|
|
|
4
4
|
Auto Translate JSON
|
|
5
5
|
<https://marketplace.visualstudio.com/items?itemName=JeffJorczak.auto-translate-json>
|
|
6
6
|
|
|
7
|
-
It opens
|
|
7
|
+
It opens possibility to use Auto Translation JSON
|
|
8
8
|
not just in vs code but as a library and command line interface
|
|
9
9
|
|
|
10
|
+
You can use Azure,AWS,Google,DeepL,Open AI or
|
|
11
|
+
local OPEN AI compatible REST API
|
|
12
|
+
for example [jan](https://jan.ai/) local server
|
|
13
|
+
http://localhost:1337/v1
|
|
14
|
+
and model mistral-ins-7b-q4
|
|
15
|
+
|
|
10
16
|
## Use as library
|
|
11
17
|
|
|
12
18
|
```shell
|
|
@@ -107,6 +113,31 @@ ATJ_DEEPL_FREE_SECRET_KEY=
|
|
|
107
113
|
|
|
108
114
|
OpenAI parameters
|
|
109
115
|
ATJ_OPEN_AI_SECRET_KEY=
|
|
116
|
+
ATJ_OPEN_AI_BASE_URL=
|
|
117
|
+
default value "https://api.openai.com/v1",
|
|
118
|
+
ATJ_OPEN_AI_MODEL
|
|
119
|
+
default value gpt-3.5-turbo
|
|
120
|
+
ATJ_OPEN_AI_MAX_TOKENS
|
|
121
|
+
default value 256
|
|
122
|
+
ATJ_OPEN_AI_TEMPERATURE
|
|
123
|
+
default value 0
|
|
124
|
+
ATJ_OPEN_AI_TOP_P
|
|
125
|
+
default value 1.0
|
|
126
|
+
ATJ_OPEN_AI_N
|
|
127
|
+
default value 1
|
|
128
|
+
ATJ_OPEN_AI_FREQUENCY_PENALTY
|
|
129
|
+
default value 0
|
|
130
|
+
ATJ_OPEN_AI_PRESENCE_PENALTY
|
|
131
|
+
default value 0
|
|
132
|
+
|
|
133
|
+
If you want to run it locally without using Open AI but compatible API
|
|
134
|
+
you need to modify base URL and model for example
|
|
135
|
+
if you use jan https://jan.ai/ you can modify base url model and maximum number of tokens (you do not pay for tokens anymore), secret key is not important
|
|
136
|
+
ATJ_OPEN_AI_SECRET_KEY=whatever
|
|
137
|
+
ATJ_OPEN_AI_BASE_URL=http://localhost:1337/v1
|
|
138
|
+
ATJ_OPEN_AI_MODEL=mistral-ins-7b-q4
|
|
139
|
+
ATJ_OPEN_AI_MAX_TOKENS=4096
|
|
140
|
+
|
|
110
141
|
|
|
111
142
|
start delimiter
|
|
112
143
|
ATJ_START_DELIMITER={{
|
package/build/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL or OpenAI",
|
|
3
|
+
"version": "1.3.8",
|
|
4
|
+
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
|
|
5
5
|
"main": "./build/src/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"auto-translate-json-library": "./build/src/bin/cli.js",
|
|
@@ -49,21 +49,21 @@
|
|
|
49
49
|
],
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@biomejs/biome": "1.3
|
|
52
|
+
"@biomejs/biome": "1.5.3",
|
|
53
53
|
"@topce/typescript": "5.3.1",
|
|
54
|
-
"@types/minimist": "1.2.
|
|
55
|
-
"@types/node": "20.
|
|
56
|
-
"@types/yargs": "17.0.
|
|
57
|
-
"ts-node": "10.9.
|
|
54
|
+
"@types/minimist": "1.2.5",
|
|
55
|
+
"@types/node": "20.11.24",
|
|
56
|
+
"@types/yargs": "17.0.32",
|
|
57
|
+
"ts-node": "10.9.2"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@aws-sdk/client-translate": "3.
|
|
61
|
-
"@google-cloud/translate": "8.0
|
|
62
|
-
"axios": "1.6.
|
|
63
|
-
"dotenv": "16.
|
|
60
|
+
"@aws-sdk/client-translate": "3.525.0",
|
|
61
|
+
"@google-cloud/translate": "8.1.0",
|
|
62
|
+
"axios": "1.6.7",
|
|
63
|
+
"dotenv": "16.4.5",
|
|
64
64
|
"form-data": "4.0.0",
|
|
65
65
|
"minimist": "1.2.8",
|
|
66
|
-
"openai": "4.
|
|
66
|
+
"openai": "4.28.4",
|
|
67
67
|
"picocolors": "1.0.0",
|
|
68
68
|
"uuid": "9.0.1",
|
|
69
69
|
"yargs": "17.7.2"
|
package/build/src/bin/cli.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
6
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const minimist_1 = __importDefault(require("minimist"));
|
|
@@ -115,6 +116,14 @@ switch (engine) {
|
|
|
115
116
|
config.translationKeyInfo = {
|
|
116
117
|
kind: "openai",
|
|
117
118
|
apiKey: openaiApiKey,
|
|
119
|
+
baseUrl: (_a = process.env.ATJ_OPEN_AI_BASE_URL) !== null && _a !== void 0 ? _a : "https://api.openai.com/v1",
|
|
120
|
+
model: (_b = process.env.ATJ_OPEN_AI_MODEL) !== null && _b !== void 0 ? _b : "gpt-3.5-turbo",
|
|
121
|
+
maxTokens: Number((_c = process.env.ATJ_OPEN_AI_MAX_TOKENS) !== null && _c !== void 0 ? _c : "256"),
|
|
122
|
+
temperature: Number((_d = process.env.ATJ_OPEN_AI_TEMPERATURE) !== null && _d !== void 0 ? _d : "0"),
|
|
123
|
+
topP: Number((_e = process.env.ATJ_OPEN_AI_TOP_P) !== null && _e !== void 0 ? _e : "1.0"),
|
|
124
|
+
n: Number((_f = process.env.ATJ_OPEN_AI_N) !== null && _f !== void 0 ? _f : "1"),
|
|
125
|
+
frequencyPenalty: Number((_g = process.env.ATJ_OPEN_AI_FREQUENCY_PENALTY) !== null && _g !== void 0 ? _g : "0"),
|
|
126
|
+
presencePenalty: Number((_h = process.env.ATJ_OPEN_AI_PRESENCE_PENALTY) !== null && _h !== void 0 ? _h : "0"),
|
|
118
127
|
};
|
|
119
128
|
break;
|
|
120
129
|
}
|
package/build/src/config.d.ts
CHANGED
|
@@ -34,5 +34,13 @@ type DeepLFreeTranslationKey = {
|
|
|
34
34
|
type OpenAITranslationKey = {
|
|
35
35
|
kind: "openai";
|
|
36
36
|
apiKey: string;
|
|
37
|
+
baseUrl: string;
|
|
38
|
+
model: string;
|
|
39
|
+
maxTokens: number;
|
|
40
|
+
temperature: number;
|
|
41
|
+
topP: number;
|
|
42
|
+
n: number;
|
|
43
|
+
frequencyPenalty: number;
|
|
44
|
+
presencePenalty: number;
|
|
37
45
|
};
|
|
38
46
|
export {};
|
package/build/src/index.js
CHANGED
|
@@ -58,6 +58,7 @@ function setDefaultConfiguration() {
|
|
|
58
58
|
config.ignorePrefix = "";
|
|
59
59
|
}
|
|
60
60
|
function setConfigurationFromEnvironment() {
|
|
61
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
61
62
|
require("dotenv").config();
|
|
62
63
|
if (process.env.ATJ_GOOGLE_API_KEY) {
|
|
63
64
|
config.translationKeyInfo = {
|
|
@@ -98,6 +99,14 @@ function setConfigurationFromEnvironment() {
|
|
|
98
99
|
config.translationKeyInfo = {
|
|
99
100
|
kind: "openai",
|
|
100
101
|
apiKey: process.env.ATJ_OPEN_AI_SECRET_KEY,
|
|
102
|
+
baseUrl: (_a = process.env.ATJ_OPEN_AI_BASE_URL) !== null && _a !== void 0 ? _a : "https://api.openai.com/v1",
|
|
103
|
+
model: (_b = process.env.ATJ_OPEN_AI_MODEL) !== null && _b !== void 0 ? _b : "gpt-3.5-turbo",
|
|
104
|
+
maxTokens: Number((_c = process.env.ATJ_OPEN_AI_MAX_TOKENS) !== null && _c !== void 0 ? _c : "256"),
|
|
105
|
+
temperature: Number((_d = process.env.ATJ_OPEN_AI_TEMPERATURE) !== null && _d !== void 0 ? _d : "0"),
|
|
106
|
+
topP: Number((_e = process.env.ATJ_OPEN_AI_TOP_P) !== null && _e !== void 0 ? _e : "1.0"),
|
|
107
|
+
n: Number((_f = process.env.ATJ_OPEN_AI_N) !== null && _f !== void 0 ? _f : "1"),
|
|
108
|
+
frequencyPenalty: Number((_g = process.env.ATJ_OPEN_AI_FREQUENCY_PENALTY) !== null && _g !== void 0 ? _g : "0"),
|
|
109
|
+
presencePenalty: Number((_h = process.env.ATJ_OPEN_AI_PRESENCE_PENALTY) !== null && _h !== void 0 ? _h : "0"),
|
|
101
110
|
};
|
|
102
111
|
}
|
|
103
112
|
if (process.env.ATJ_START_DELIMITER) {
|
package/build/src/lib.js
CHANGED
|
@@ -48,7 +48,7 @@ function translate(sourceFile, config) {
|
|
|
48
48
|
translateEngine = new deepl_1.DeepLTranslate(config.translationKeyInfo.secretKey, "pro");
|
|
49
49
|
}
|
|
50
50
|
else if (config.translationKeyInfo.kind === "openai") {
|
|
51
|
-
translateEngine = new openai_1.OpenAITranslate(config.translationKeyInfo.apiKey);
|
|
51
|
+
translateEngine = new openai_1.OpenAITranslate(config.translationKeyInfo.apiKey, config.translationKeyInfo.baseUrl, config.translationKeyInfo.model, config.translationKeyInfo.maxTokens, config.translationKeyInfo.temperature, config.translationKeyInfo.topP, config.translationKeyInfo.n, config.translationKeyInfo.presencePenalty, config.translationKeyInfo.frequencyPenalty);
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
console.warn("You must provide a Google, AWS, Azure, deepL, openai parameters first in the extension settings.");
|
package/build/src/openai.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { ITranslate } from "./translate.interface";
|
|
2
2
|
export declare class OpenAITranslate implements ITranslate {
|
|
3
|
+
private model;
|
|
4
|
+
private maxTokens;
|
|
5
|
+
private temperature;
|
|
6
|
+
private topP;
|
|
7
|
+
private n;
|
|
8
|
+
private frequencyPenalty;
|
|
9
|
+
private presencePenalty;
|
|
3
10
|
private openai;
|
|
4
|
-
constructor(apiKey: string);
|
|
11
|
+
constructor(apiKey: string, baseUrl: string, model: string, maxTokens: number, temperature: number, topP: number, n: number, frequencyPenalty: number, presencePenalty: number);
|
|
5
12
|
isValidLocale(targetLocale: string): boolean;
|
|
6
13
|
translateText(text: string, sourceLocale: string, targetLocale: string): Promise<string>;
|
|
7
14
|
}
|
package/build/src/openai.js
CHANGED
|
@@ -123,9 +123,17 @@ const supportedLanguages = {
|
|
|
123
123
|
zu: "Zulu",
|
|
124
124
|
};
|
|
125
125
|
class OpenAITranslate {
|
|
126
|
-
constructor(apiKey) {
|
|
126
|
+
constructor(apiKey, baseUrl, model, maxTokens, temperature, topP, n, frequencyPenalty, presencePenalty) {
|
|
127
|
+
this.model = model;
|
|
128
|
+
this.maxTokens = maxTokens;
|
|
129
|
+
this.temperature = temperature;
|
|
130
|
+
this.topP = topP;
|
|
131
|
+
this.n = n;
|
|
132
|
+
this.frequencyPenalty = frequencyPenalty;
|
|
133
|
+
this.presencePenalty = presencePenalty;
|
|
127
134
|
const configuration = {
|
|
128
135
|
apiKey: apiKey,
|
|
136
|
+
baseURL: baseUrl,
|
|
129
137
|
};
|
|
130
138
|
this.openai = new openai_1.OpenAI(configuration);
|
|
131
139
|
}
|
|
@@ -142,19 +150,28 @@ class OpenAITranslate {
|
|
|
142
150
|
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
143
151
|
const systemPrompt = `You will be provided with a sentence in English, and your task is to translate it into ${supportedLanguages[targetLocale]}`;
|
|
144
152
|
const userPrompt = text;
|
|
145
|
-
|
|
146
|
-
model:
|
|
153
|
+
let response = yield this.openai.chat.completions.create({
|
|
154
|
+
model: this.model,
|
|
147
155
|
messages: [
|
|
148
156
|
{ role: "system", content: systemPrompt },
|
|
149
157
|
{ role: "user", content: userPrompt },
|
|
150
158
|
],
|
|
151
|
-
temperature:
|
|
152
|
-
max_tokens:
|
|
153
|
-
top_p:
|
|
154
|
-
n:
|
|
155
|
-
frequency_penalty:
|
|
156
|
-
presence_penalty:
|
|
159
|
+
temperature: this.temperature,
|
|
160
|
+
max_tokens: this.maxTokens,
|
|
161
|
+
top_p: this.topP,
|
|
162
|
+
n: this.n,
|
|
163
|
+
frequency_penalty: this.frequencyPenalty,
|
|
164
|
+
presence_penalty: this.presencePenalty,
|
|
157
165
|
});
|
|
166
|
+
try {
|
|
167
|
+
console.log(response.choices[0].message.content);
|
|
168
|
+
}
|
|
169
|
+
catch (_a) {
|
|
170
|
+
// disable type script compiler for next line
|
|
171
|
+
// @ts-ignore
|
|
172
|
+
response = JSON.parse(response);
|
|
173
|
+
console.log(response.choices[0].message.content);
|
|
174
|
+
}
|
|
158
175
|
if (response.choices[0].message.content !== null) {
|
|
159
176
|
result = util_1.Util.replaceArgumentsWithNumbers(args, response.choices[0].message.content);
|
|
160
177
|
result = result.replace(/^\n+|\n+$/g, "");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL or OpenAI",
|
|
3
|
+
"version": "1.3.8",
|
|
4
|
+
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
|
|
5
5
|
"main": "./build/src/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"auto-translate-json-library": "./build/src/bin/cli.js",
|
|
@@ -49,21 +49,21 @@
|
|
|
49
49
|
],
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@biomejs/biome": "1.3
|
|
52
|
+
"@biomejs/biome": "1.5.3",
|
|
53
53
|
"@topce/typescript": "5.3.1",
|
|
54
|
-
"@types/minimist": "1.2.
|
|
55
|
-
"@types/node": "20.
|
|
56
|
-
"@types/yargs": "17.0.
|
|
57
|
-
"ts-node": "10.9.
|
|
54
|
+
"@types/minimist": "1.2.5",
|
|
55
|
+
"@types/node": "20.11.24",
|
|
56
|
+
"@types/yargs": "17.0.32",
|
|
57
|
+
"ts-node": "10.9.2"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@aws-sdk/client-translate": "3.
|
|
61
|
-
"@google-cloud/translate": "8.0
|
|
62
|
-
"axios": "1.6.
|
|
63
|
-
"dotenv": "16.
|
|
60
|
+
"@aws-sdk/client-translate": "3.525.0",
|
|
61
|
+
"@google-cloud/translate": "8.1.0",
|
|
62
|
+
"axios": "1.6.7",
|
|
63
|
+
"dotenv": "16.4.5",
|
|
64
64
|
"form-data": "4.0.0",
|
|
65
65
|
"minimist": "1.2.8",
|
|
66
|
-
"openai": "4.
|
|
66
|
+
"openai": "4.28.4",
|
|
67
67
|
"picocolors": "1.0.0",
|
|
68
68
|
"uuid": "9.0.1",
|
|
69
69
|
"yargs": "17.7.2"
|