auto-translate-json-library 1.4.0 → 1.4.1
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 +15 -4
- package/build/package.json +1 -1
- package/build/src/bin/cli.js +2 -2
- package/build/src/index.js +2 -2
- package/build/src/openai.js +2 -19
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -9,9 +9,9 @@ not just in vs code but as a library and command line interface
|
|
|
9
9
|
|
|
10
10
|
You can use Azure,AWS,Google,DeepL,Open AI or
|
|
11
11
|
local OPEN AI compatible REST API
|
|
12
|
-
for example [
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
for example [ollama](https://ollama.com/)
|
|
13
|
+
because it is compatible with Open AI https://ollama.com/blog/openai-compatibility :
|
|
14
|
+
|
|
15
15
|
|
|
16
16
|
## Use as library
|
|
17
17
|
|
|
@@ -48,7 +48,16 @@ do not forget to set translation engine parameters in environment variables or .
|
|
|
48
48
|
node node_modules\auto-translate-json-library\index.js --pivotTranslation=./translations/en.json
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
## Contribute
|
|
52
|
+
|
|
53
|
+
Clone repo you can use the following commands
|
|
54
|
+
|
|
55
|
+
install ollama
|
|
56
|
+
run ollama run llama2
|
|
57
|
+
rename ollama.env to .env
|
|
58
|
+
install
|
|
59
|
+
build project
|
|
60
|
+
and rune it
|
|
52
61
|
|
|
53
62
|
```shell
|
|
54
63
|
npm i
|
|
@@ -56,6 +65,8 @@ npm run build
|
|
|
56
65
|
node .\build\src\index.js --pivotTranslation=./tests/translations/en.json
|
|
57
66
|
```
|
|
58
67
|
|
|
68
|
+
After some time you should see es.json file with translation
|
|
69
|
+
|
|
59
70
|
## CLI PARAMETERS
|
|
60
71
|
|
|
61
72
|
```config
|
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
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": {
|
package/build/src/bin/cli.js
CHANGED
|
@@ -119,8 +119,8 @@ switch (engine) {
|
|
|
119
119
|
baseUrl: (_a = process.env.ATJ_OPEN_AI_BASE_URL) !== null && _a !== void 0 ? _a : "https://api.openai.com/v1",
|
|
120
120
|
model: (_b = process.env.ATJ_OPEN_AI_MODEL) !== null && _b !== void 0 ? _b : "gpt-3.5-turbo",
|
|
121
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 : "
|
|
122
|
+
temperature: Number((_d = process.env.ATJ_OPEN_AI_TEMPERATURE) !== null && _d !== void 0 ? _d : "0.7"),
|
|
123
|
+
topP: Number((_e = process.env.ATJ_OPEN_AI_TOP_P) !== null && _e !== void 0 ? _e : "0.9"),
|
|
124
124
|
n: Number((_f = process.env.ATJ_OPEN_AI_N) !== null && _f !== void 0 ? _f : "1"),
|
|
125
125
|
frequencyPenalty: Number((_g = process.env.ATJ_OPEN_AI_FREQUENCY_PENALTY) !== null && _g !== void 0 ? _g : "0"),
|
|
126
126
|
presencePenalty: Number((_h = process.env.ATJ_OPEN_AI_PRESENCE_PENALTY) !== null && _h !== void 0 ? _h : "0"),
|
package/build/src/index.js
CHANGED
|
@@ -102,8 +102,8 @@ function setConfigurationFromEnvironment() {
|
|
|
102
102
|
baseUrl: (_a = process.env.ATJ_OPEN_AI_BASE_URL) !== null && _a !== void 0 ? _a : "https://api.openai.com/v1",
|
|
103
103
|
model: (_b = process.env.ATJ_OPEN_AI_MODEL) !== null && _b !== void 0 ? _b : "gpt-3.5-turbo",
|
|
104
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 : "
|
|
105
|
+
temperature: Number((_d = process.env.ATJ_OPEN_AI_TEMPERATURE) !== null && _d !== void 0 ? _d : "0.7"),
|
|
106
|
+
topP: Number((_e = process.env.ATJ_OPEN_AI_TOP_P) !== null && _e !== void 0 ? _e : "0.9"),
|
|
107
107
|
n: Number((_f = process.env.ATJ_OPEN_AI_N) !== null && _f !== void 0 ? _f : "1"),
|
|
108
108
|
frequencyPenalty: Number((_g = process.env.ATJ_OPEN_AI_FREQUENCY_PENALTY) !== null && _g !== void 0 ? _g : "0"),
|
|
109
109
|
presencePenalty: Number((_h = process.env.ATJ_OPEN_AI_PRESENCE_PENALTY) !== null && _h !== void 0 ? _h : "0"),
|
package/build/src/openai.js
CHANGED
|
@@ -148,9 +148,9 @@ class OpenAITranslate {
|
|
|
148
148
|
let result = "";
|
|
149
149
|
let args;
|
|
150
150
|
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
151
|
-
const systemPrompt = `You will be provided with a sentence in English, and your task is to translate it into ${supportedLanguages[targetLocale]}`;
|
|
151
|
+
const systemPrompt = `You will be provided with a sentence or words in English, and your task is to translate it into ${supportedLanguages[targetLocale]}`;
|
|
152
152
|
const userPrompt = text;
|
|
153
|
-
|
|
153
|
+
const response = yield this.openai.chat.completions.create({
|
|
154
154
|
model: this.model,
|
|
155
155
|
messages: [
|
|
156
156
|
{ role: "system", content: systemPrompt },
|
|
@@ -163,23 +163,6 @@ class OpenAITranslate {
|
|
|
163
163
|
frequency_penalty: this.frequencyPenalty,
|
|
164
164
|
presence_penalty: this.presencePenalty,
|
|
165
165
|
});
|
|
166
|
-
try {
|
|
167
|
-
console.log(response.choices[0].message.content);
|
|
168
|
-
}
|
|
169
|
-
catch (_a) {
|
|
170
|
-
try {
|
|
171
|
-
// for local server sometimes does not return response in json format
|
|
172
|
-
// disable type script compiler for next line
|
|
173
|
-
// @ts-ignore
|
|
174
|
-
response = JSON.parse(response);
|
|
175
|
-
console.log(response.choices[0].message.content);
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
console.error(error);
|
|
179
|
-
console.log("can not parse response");
|
|
180
|
-
console.log(response);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
166
|
if (response.choices[0].message.content !== null) {
|
|
184
167
|
result = util_1.Util.replaceArgumentsWithNumbers(args, response.choices[0].message.content);
|
|
185
168
|
result = result.replace(/^\n+|\n+$/g, "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
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": {
|