gpt-po 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/package.json +1 -1
- package/lib/src/systemprompt.txt +3 -4
- package/lib/src/translate.js +6 -4
- package/lib/src/utils.d.ts +1 -1
- package/lib/src/utils.js +4 -3
- package/package.json +1 -1
package/lib/package.json
CHANGED
package/lib/src/systemprompt.txt
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
You are a language translation expert.
|
2
2
|
You will be translating text from one language to another.
|
3
|
-
|
4
|
-
The text is in the gettext format, which uses placeholders like %s, %d, etc. These placeholders must remain
|
3
|
+
In my prompt to you I may identify languages via ISO 639, ISO 3166 and/or IETF language tag codes. Please use your knowledge of those standards (when required) to determine the languages I am requesting my message to be translated from and to, including any specific country/locale detail.
|
4
|
+
The text is in the gettext format, which uses placeholders like %s, %d, etc. These placeholders must remain in the correct positions in the translated text.
|
5
5
|
Untranslatable portions should retain their original formatting.
|
6
|
-
For example, you may encounter placeholders such as "%s" - these must be retained in the correct position.
|
7
6
|
Do not add a period (.) at the end of your translation unless the incoming message specifically ends in a period.
|
8
7
|
Likewise, ensure to add a period (.) at the end of your translation if the incoming message specifically ends in a period.
|
9
8
|
Ensure to preserve any whitespace present in the incoming message. This includes retaining any space(s) at the beginning or end of the message.
|
10
9
|
I will provide the message wrapped in `translate` XML tags. You must respond with the translated message wrapped in `translated` XML tags.
|
11
|
-
For example, let's say you were translating
|
10
|
+
For example, let's say you were translating en_US (United States English) to es (Spanish) and I send (without quotes) "<translate>This is a message. </translate>". You would respond with (without quotes) "<translated>Este es un mensaje. </translated>".
|
12
11
|
Notice how the period and space were retained at the end of the translated message?
|
13
12
|
Another example: I send (without quotes) "<translate> Hello %s</translate>". You would reply with (without quotes) "<translated> Hola %s</translated>".
|
14
13
|
Notice in that second example the space at the beginning of the string was retained, and also the gettext placeholder was retained in its correct position?
|
package/lib/src/translate.js
CHANGED
@@ -28,14 +28,16 @@ function init(force) {
|
|
28
28
|
}
|
29
29
|
_openai = new openai_1.OpenAIApi(configuration);
|
30
30
|
}
|
31
|
-
// load systemprompt.txt
|
31
|
+
// load systemprompt.txt from homedir
|
32
32
|
if (!_systemprompt || force) {
|
33
33
|
const systemprompt = (0, utils_1.findConfig)("systemprompt.txt");
|
34
|
+
(0, utils_1.copyFileIfNotExists)(systemprompt, (0, path_1.join)(__dirname, "systemprompt.txt"));
|
34
35
|
_systemprompt = fs.readFileSync(systemprompt, "utf-8");
|
35
36
|
}
|
36
|
-
// load dictionary.json
|
37
|
+
// load dictionary.json from homedir
|
37
38
|
if (!_userdict || force) {
|
38
39
|
const userdict = (0, utils_1.findConfig)("dictionary.json");
|
40
|
+
(0, utils_1.copyFileIfNotExists)(userdict, (0, path_1.join)(__dirname, "dictionary-template.json"));
|
39
41
|
_userdict = { "default": JSON.parse(fs.readFileSync(userdict, "utf-8")) };
|
40
42
|
}
|
41
43
|
return _openai;
|
@@ -66,11 +68,11 @@ function translate(text, src, lang, model, comments, contextFile) {
|
|
66
68
|
},
|
67
69
|
{
|
68
70
|
role: "user",
|
69
|
-
content: `Wait for my incoming message in "${src
|
71
|
+
content: `Wait for my incoming message in "${src}" and translate it into "${lang}", carefully following your system prompt. ` + notes
|
70
72
|
},
|
71
73
|
{
|
72
74
|
role: "assistant",
|
73
|
-
content: `Understood, I will translate your incoming "${src
|
75
|
+
content: `Understood, I will translate your incoming "${src}" message into "${lang}", carefully following my system prompt. Please go ahead and send your message for translation.`
|
74
76
|
},
|
75
77
|
// add userdict here
|
76
78
|
...dicts,
|
package/lib/src/utils.d.ts
CHANGED
@@ -13,7 +13,7 @@ export declare function printProgress(progress: number, total: number, extra?: s
|
|
13
13
|
export declare function gitRootDir(dir?: string): string | null;
|
14
14
|
/**
|
15
15
|
* find config file in the following order:
|
16
|
-
* 1. current directory
|
16
|
+
* 1. current working directory of the Node.js process
|
17
17
|
* 2. git root directory
|
18
18
|
* 3. home directory
|
19
19
|
* @param fileName
|
package/lib/src/utils.js
CHANGED
@@ -90,7 +90,7 @@ function gitRootDir(dir) {
|
|
90
90
|
exports.gitRootDir = gitRootDir;
|
91
91
|
/**
|
92
92
|
* find config file in the following order:
|
93
|
-
* 1. current directory
|
93
|
+
* 1. current working directory of the Node.js process
|
94
94
|
* 2. git root directory
|
95
95
|
* 3. home directory
|
96
96
|
* @param fileName
|
@@ -101,9 +101,10 @@ function findConfig(fileName) {
|
|
101
101
|
const gitDir = gitRootDir() || currentDir;
|
102
102
|
const homeDir = (0, os_1.homedir)();
|
103
103
|
const filePaths = [
|
104
|
-
path.join(currentDir, "
|
104
|
+
path.join(currentDir, ".gpt-po", fileName),
|
105
|
+
path.join(currentDir, fileName),
|
105
106
|
path.join(gitDir, ".gpt-po", fileName),
|
106
|
-
path.join(homeDir, ".
|
107
|
+
path.join(homeDir, ".gpt-po", fileName)
|
107
108
|
];
|
108
109
|
// check if file exists and return the first one
|
109
110
|
for (const filePath of filePaths) {
|