generaltranslation 1.1.7 → 1.1.9
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/package.json +1 -1
- package/prompts/prompts.js +6 -7
package/package.json
CHANGED
package/prompts/prompts.js
CHANGED
|
@@ -9,6 +9,7 @@ const _processPrompt = (prompt) => {
|
|
|
9
9
|
const processed = [];
|
|
10
10
|
const redacted = [];
|
|
11
11
|
if (Array.isArray(prompt)) {
|
|
12
|
+
console.log(prompt)
|
|
12
13
|
for (const item of prompt) {
|
|
13
14
|
if (typeof item === 'string') {
|
|
14
15
|
processed.push({
|
|
@@ -21,10 +22,6 @@ const _processPrompt = (prompt) => {
|
|
|
21
22
|
redacted.push(item);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
return {
|
|
25
|
-
processed: processed,
|
|
26
|
-
redacted: redacted.length > 0 ? redacted : null
|
|
27
|
-
}
|
|
28
25
|
} else {
|
|
29
26
|
if (typeof prompt === 'string') {
|
|
30
27
|
processed.push({
|
|
@@ -44,7 +41,7 @@ const _processPrompt = (prompt) => {
|
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
// Build prompt string from array or single item
|
|
47
|
-
const _constructPrompt = (translated, redacted = null) => {
|
|
44
|
+
const _constructPrompt = ({translated, redacted = null}) => {
|
|
48
45
|
if (Array.isArray(translated)) {
|
|
49
46
|
let final = '';
|
|
50
47
|
for (const item of translated) {
|
|
@@ -76,7 +73,9 @@ const _getPrompt = async (prompt, language, defaultLanguage, apiKey) => {
|
|
|
76
73
|
return _constructPrompt(prompt);
|
|
77
74
|
}
|
|
78
75
|
const { processed, redacted } = _processPrompt(prompt);
|
|
79
|
-
|
|
76
|
+
console.log(processed)
|
|
77
|
+
console.log(redacted)
|
|
78
|
+
const response = await fetch('http://prompts.gtx.dev/internationalize', {
|
|
80
79
|
method: 'POST',
|
|
81
80
|
headers: {
|
|
82
81
|
'Content-Type': 'application/json',
|
|
@@ -93,7 +92,7 @@ const _getPrompt = async (prompt, language, defaultLanguage, apiKey) => {
|
|
|
93
92
|
throw new Error(`${result || response.status}`);
|
|
94
93
|
} else {
|
|
95
94
|
const result = await response.json();
|
|
96
|
-
return _constructPrompt(result, redacted);
|
|
95
|
+
return _constructPrompt({translated: result, redacted: redacted});
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
|