@gringow/gringow 0.1.2 → 0.1.3
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 +82 -40
- package/dist/browser.d.mts +2 -1
- package/dist/browser.mjs +61 -4
- package/dist/config.mjs +3 -3
- package/dist/config.test.mjs +50 -67
- package/dist/{data/create-cache-id.d.mts → create-cache-id.d.mts} +2 -2
- package/dist/create-cache-id.mjs +54 -0
- package/dist/create-cache-id.test.d.mts +2 -0
- package/dist/create-cache-id.test.mjs +18464 -0
- package/dist/data/check-cache.d.mts +1 -1
- package/dist/data/check-cache.mjs +12 -7
- package/dist/data/clear-cache.mjs +12 -7
- package/dist/data/create-cache-dir.mjs +3 -3
- package/dist/data/delete-cache-item.d.mts +1 -1
- package/dist/data/delete-cache-item.mjs +12 -7
- package/dist/data/get-cache.mjs +3 -3
- package/dist/data/get-or-create-cache.d.mts +1 -1
- package/dist/data/get-or-create-cache.mjs +12 -7
- package/dist/data/md5.d.mts +13 -0
- package/dist/data/md5.mjs +47 -0
- package/dist/data/md5.test.d.mts +2 -0
- package/dist/data/md5.test.mjs +18457 -0
- package/dist/data/save-cache.d.mts +2 -2
- package/dist/data/save-cache.mjs +12 -7
- package/dist/data/write-cache-to-disk.d.mts +1 -1
- package/dist/data/write-cache-to-disk.mjs +12 -7
- package/dist/flat-template-string.test.mjs +10 -10
- package/dist/gringow.d.mts +1 -1
- package/dist/gringow.mjs +98 -35
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +98 -35
- package/dist/interpolate-template.d.mts +3 -0
- package/dist/interpolate-template.mjs +14 -0
- package/dist/io/anthropic/ask.mjs +3 -3
- package/dist/io/anthropic/commit-response.d.mts +1 -1
- package/dist/io/anthropic/index.d.mts +1 -1
- package/dist/io/anthropic/index.mjs +3 -3
- package/dist/io/anthropic/parse.d.mts +1 -1
- package/dist/io/ask-llm.d.mts +1 -1
- package/dist/io/ask-llm.mjs +36 -25
- package/dist/io/gemini/ask.mjs +36 -25
- package/dist/io/gemini/index.d.mts +1 -1
- package/dist/io/gemini/index.mjs +36 -25
- package/dist/io/gemini/parse.d.mts +1 -1
- package/dist/io/huggingface/ask.d.mts +1 -1
- package/dist/io/huggingface/ask.mjs +3 -3
- package/dist/io/huggingface/commit-response.d.mts +1 -1
- package/dist/io/huggingface/index.d.mts +1 -1
- package/dist/io/huggingface/index.mjs +3 -3
- package/dist/io/huggingface/parse.d.mts +1 -1
- package/dist/logger.test.mjs +10 -10
- package/dist/types/index.d.mts +1 -1
- package/package.json +10 -10
- package/dist/data/create-cache-id.mjs +0 -10
|
@@ -102,9 +102,9 @@ async function loadUserConfig() {
|
|
|
102
102
|
var awaitedConfig = loadUserConfig();
|
|
103
103
|
function defaultPrePrompt(config, extraInstructions) {
|
|
104
104
|
return `
|
|
105
|
-
You are a translation generator.
|
|
105
|
+
You are a ultimate translation generator server api.
|
|
106
106
|
|
|
107
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
107
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
108
108
|
|
|
109
109
|
Follow these rules strictly:
|
|
110
110
|
|
|
@@ -114,7 +114,7 @@ Follow these rules strictly:
|
|
|
114
114
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
115
115
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
116
116
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
117
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
117
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
118
118
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
119
119
|
|
|
120
120
|
{
|
|
@@ -4,8 +4,8 @@ import '../../config.mjs';
|
|
|
4
4
|
import '../../constants/default-config.mjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '../../schemas/config.shcema.mjs';
|
|
7
|
+
import '../../create-cache-id.mjs';
|
|
7
8
|
import '../../data/clear-cache.mjs';
|
|
8
|
-
import '../../data/create-cache-id.mjs';
|
|
9
9
|
import '../../data/get-cache.mjs';
|
|
10
10
|
import '../../flat-template-string.mjs';
|
|
11
11
|
|
package/dist/io/ask-llm.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ import '../config.mjs';
|
|
|
3
3
|
import '../constants/default-config.mjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '../schemas/config.shcema.mjs';
|
|
6
|
+
import '../create-cache-id.mjs';
|
|
6
7
|
import '../data/clear-cache.mjs';
|
|
7
|
-
import '../data/create-cache-id.mjs';
|
|
8
8
|
import '../data/get-cache.mjs';
|
|
9
9
|
import '../flat-template-string.mjs';
|
|
10
10
|
|
package/dist/io/ask-llm.mjs
CHANGED
|
@@ -105,9 +105,9 @@ async function loadUserConfig() {
|
|
|
105
105
|
var awaitedConfig = loadUserConfig();
|
|
106
106
|
function defaultPrePrompt(config, extraInstructions) {
|
|
107
107
|
return `
|
|
108
|
-
You are a translation generator.
|
|
108
|
+
You are a ultimate translation generator server api.
|
|
109
109
|
|
|
110
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
110
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
111
111
|
|
|
112
112
|
Follow these rules strictly:
|
|
113
113
|
|
|
@@ -117,7 +117,7 @@ Follow these rules strictly:
|
|
|
117
117
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
118
118
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
119
119
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
120
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
120
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
121
121
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
122
122
|
|
|
123
123
|
{
|
|
@@ -205,23 +205,40 @@ function parseAnthropic(unparsed) {
|
|
|
205
205
|
const parsed = JSON.parse(unparsed);
|
|
206
206
|
return parsed;
|
|
207
207
|
}
|
|
208
|
-
async function generateResponse(prompt,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
const generativeAIClient = new GoogleGenerativeAI(config.keys.geminiApiKey);
|
|
214
|
-
const model = generativeAIClient.getGenerativeModel({
|
|
215
|
-
model: config.llm.model,
|
|
216
|
-
generationConfig: {
|
|
217
|
-
temperature
|
|
208
|
+
async function generateResponse(prompt, config) {
|
|
209
|
+
try {
|
|
210
|
+
if (!config.keys.geminiApiKey) {
|
|
211
|
+
throw new Error("Gemini API key is not set in the config");
|
|
218
212
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
const generativeAIClient = new GoogleGenerativeAI(config.keys.geminiApiKey);
|
|
214
|
+
const model = generativeAIClient.getGenerativeModel({
|
|
215
|
+
model: config.llm.model,
|
|
216
|
+
generationConfig: {
|
|
217
|
+
temperature: config.llm.temperature ?? 0.8
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
if (config.debug) {
|
|
221
|
+
console.log("Gemini model prompt:", JSON.stringify({ prompt }));
|
|
222
|
+
}
|
|
223
|
+
const response = await model.generateContent([prompt]);
|
|
224
|
+
return response;
|
|
225
|
+
} catch (err) {
|
|
226
|
+
const error = err;
|
|
227
|
+
console.log("Error details from Gemini model", JSON.stringify({ error }, null, 2));
|
|
228
|
+
const retryDelay = error?.errorDetails?.find(
|
|
229
|
+
(detail) => detail?.["@type"] === "type.googleapis.com/google.rpc.RetryInfo"
|
|
230
|
+
)?.retryDelay ?? void 0;
|
|
231
|
+
if (error.status === 429 && retryDelay !== void 0) {
|
|
232
|
+
const sleepTime = config.llm.sleep ?? 3;
|
|
233
|
+
console.warn(
|
|
234
|
+
`Rate limit exceeded when generating response from Gemini model, retrying in... ${retryDelay} + ${sleepTime / 1e3}s`
|
|
235
|
+
);
|
|
236
|
+
await new Promise((resolve) => setTimeout(resolve, (parseInt(retryDelay, 10) + sleepTime / 1e3) * 1e3));
|
|
237
|
+
return generateResponse(prompt, config);
|
|
238
|
+
}
|
|
239
|
+
console.error("Error generating response from Gemini model", { error });
|
|
240
|
+
throw error;
|
|
222
241
|
}
|
|
223
|
-
const response = await model.generateContent([prompt]);
|
|
224
|
-
return response;
|
|
225
242
|
}
|
|
226
243
|
async function askGemini(prompt, prePrompt2, postPrompt2) {
|
|
227
244
|
const config = await awaitedConfig;
|
|
@@ -243,13 +260,7 @@ ${prompt}
|
|
|
243
260
|
${postPrompt2}`).trim();
|
|
244
261
|
let response;
|
|
245
262
|
for (let i = 0; i < 3; i++) {
|
|
246
|
-
const maybeResponse = await generateResponse(fullPrompt, config
|
|
247
|
-
console.log(
|
|
248
|
-
"maybeResponse:",
|
|
249
|
-
"\n\n",
|
|
250
|
-
JSON.stringify({ maybeResponse: maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text }),
|
|
251
|
-
"\n"
|
|
252
|
-
);
|
|
263
|
+
const maybeResponse = await generateResponse(fullPrompt, config);
|
|
253
264
|
const responseString = String(maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text ?? "").replace(/```json/g, "").replace(/```/g, "").trim();
|
|
254
265
|
if (responseString.startsWith("{") && responseString.endsWith("}")) {
|
|
255
266
|
response = maybeResponse;
|
package/dist/io/gemini/ask.mjs
CHANGED
|
@@ -102,9 +102,9 @@ async function loadUserConfig() {
|
|
|
102
102
|
var awaitedConfig = loadUserConfig();
|
|
103
103
|
function defaultPrePrompt(config, extraInstructions) {
|
|
104
104
|
return `
|
|
105
|
-
You are a translation generator.
|
|
105
|
+
You are a ultimate translation generator server api.
|
|
106
106
|
|
|
107
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
107
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
108
108
|
|
|
109
109
|
Follow these rules strictly:
|
|
110
110
|
|
|
@@ -114,7 +114,7 @@ Follow these rules strictly:
|
|
|
114
114
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
115
115
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
116
116
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
117
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
117
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
118
118
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
119
119
|
|
|
120
120
|
{
|
|
@@ -155,23 +155,40 @@ function postPrompt(config, prepend, replace) {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// src/io/gemini/ask.ts
|
|
158
|
-
async function generateResponse(prompt,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
const generativeAIClient = new GoogleGenerativeAI(config.keys.geminiApiKey);
|
|
164
|
-
const model = generativeAIClient.getGenerativeModel({
|
|
165
|
-
model: config.llm.model,
|
|
166
|
-
generationConfig: {
|
|
167
|
-
temperature
|
|
158
|
+
async function generateResponse(prompt, config) {
|
|
159
|
+
try {
|
|
160
|
+
if (!config.keys.geminiApiKey) {
|
|
161
|
+
throw new Error("Gemini API key is not set in the config");
|
|
168
162
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
163
|
+
const generativeAIClient = new GoogleGenerativeAI(config.keys.geminiApiKey);
|
|
164
|
+
const model = generativeAIClient.getGenerativeModel({
|
|
165
|
+
model: config.llm.model,
|
|
166
|
+
generationConfig: {
|
|
167
|
+
temperature: config.llm.temperature ?? 0.8
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
if (config.debug) {
|
|
171
|
+
console.log("Gemini model prompt:", JSON.stringify({ prompt }));
|
|
172
|
+
}
|
|
173
|
+
const response = await model.generateContent([prompt]);
|
|
174
|
+
return response;
|
|
175
|
+
} catch (err) {
|
|
176
|
+
const error = err;
|
|
177
|
+
console.log("Error details from Gemini model", JSON.stringify({ error }, null, 2));
|
|
178
|
+
const retryDelay = error?.errorDetails?.find(
|
|
179
|
+
(detail) => detail?.["@type"] === "type.googleapis.com/google.rpc.RetryInfo"
|
|
180
|
+
)?.retryDelay ?? void 0;
|
|
181
|
+
if (error.status === 429 && retryDelay !== void 0) {
|
|
182
|
+
const sleepTime = config.llm.sleep ?? 3;
|
|
183
|
+
console.warn(
|
|
184
|
+
`Rate limit exceeded when generating response from Gemini model, retrying in... ${retryDelay} + ${sleepTime / 1e3}s`
|
|
185
|
+
);
|
|
186
|
+
await new Promise((resolve) => setTimeout(resolve, (parseInt(retryDelay, 10) + sleepTime / 1e3) * 1e3));
|
|
187
|
+
return generateResponse(prompt, config);
|
|
188
|
+
}
|
|
189
|
+
console.error("Error generating response from Gemini model", { error });
|
|
190
|
+
throw error;
|
|
172
191
|
}
|
|
173
|
-
const response = await model.generateContent([prompt]);
|
|
174
|
-
return response;
|
|
175
192
|
}
|
|
176
193
|
async function askGemini(prompt, prePrompt2, postPrompt2) {
|
|
177
194
|
const config = await awaitedConfig;
|
|
@@ -193,13 +210,7 @@ ${prompt}
|
|
|
193
210
|
${postPrompt2}`).trim();
|
|
194
211
|
let response;
|
|
195
212
|
for (let i = 0; i < 3; i++) {
|
|
196
|
-
const maybeResponse = await generateResponse(fullPrompt, config
|
|
197
|
-
console.log(
|
|
198
|
-
"maybeResponse:",
|
|
199
|
-
"\n\n",
|
|
200
|
-
JSON.stringify({ maybeResponse: maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text }),
|
|
201
|
-
"\n"
|
|
202
|
-
);
|
|
213
|
+
const maybeResponse = await generateResponse(fullPrompt, config);
|
|
203
214
|
const responseString = String(maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text ?? "").replace(/```json/g, "").replace(/```/g, "").trim();
|
|
204
215
|
if (responseString.startsWith("{") && responseString.endsWith("}")) {
|
|
205
216
|
response = maybeResponse;
|
|
@@ -7,8 +7,8 @@ import '../../config.mjs';
|
|
|
7
7
|
import '../../constants/default-config.mjs';
|
|
8
8
|
import 'zod';
|
|
9
9
|
import '../../schemas/config.shcema.mjs';
|
|
10
|
+
import '../../create-cache-id.mjs';
|
|
10
11
|
import '../../data/clear-cache.mjs';
|
|
11
|
-
import '../../data/create-cache-id.mjs';
|
|
12
12
|
import '../../data/get-cache.mjs';
|
|
13
13
|
import '../../flat-template-string.mjs';
|
|
14
14
|
import '../../types/index.mjs';
|
package/dist/io/gemini/index.mjs
CHANGED
|
@@ -102,9 +102,9 @@ async function loadUserConfig() {
|
|
|
102
102
|
var awaitedConfig = loadUserConfig();
|
|
103
103
|
function defaultPrePrompt(config, extraInstructions) {
|
|
104
104
|
return `
|
|
105
|
-
You are a translation generator.
|
|
105
|
+
You are a ultimate translation generator server api.
|
|
106
106
|
|
|
107
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
107
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
108
108
|
|
|
109
109
|
Follow these rules strictly:
|
|
110
110
|
|
|
@@ -114,7 +114,7 @@ Follow these rules strictly:
|
|
|
114
114
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
115
115
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
116
116
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
117
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
117
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
118
118
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
119
119
|
|
|
120
120
|
{
|
|
@@ -155,23 +155,40 @@ function postPrompt(config, prepend, replace) {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// src/io/gemini/ask.ts
|
|
158
|
-
async function generateResponse(prompt,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
const generativeAIClient = new GoogleGenerativeAI(config.keys.geminiApiKey);
|
|
164
|
-
const model = generativeAIClient.getGenerativeModel({
|
|
165
|
-
model: config.llm.model,
|
|
166
|
-
generationConfig: {
|
|
167
|
-
temperature
|
|
158
|
+
async function generateResponse(prompt, config) {
|
|
159
|
+
try {
|
|
160
|
+
if (!config.keys.geminiApiKey) {
|
|
161
|
+
throw new Error("Gemini API key is not set in the config");
|
|
168
162
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
163
|
+
const generativeAIClient = new GoogleGenerativeAI(config.keys.geminiApiKey);
|
|
164
|
+
const model = generativeAIClient.getGenerativeModel({
|
|
165
|
+
model: config.llm.model,
|
|
166
|
+
generationConfig: {
|
|
167
|
+
temperature: config.llm.temperature ?? 0.8
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
if (config.debug) {
|
|
171
|
+
console.log("Gemini model prompt:", JSON.stringify({ prompt }));
|
|
172
|
+
}
|
|
173
|
+
const response = await model.generateContent([prompt]);
|
|
174
|
+
return response;
|
|
175
|
+
} catch (err) {
|
|
176
|
+
const error = err;
|
|
177
|
+
console.log("Error details from Gemini model", JSON.stringify({ error }, null, 2));
|
|
178
|
+
const retryDelay = error?.errorDetails?.find(
|
|
179
|
+
(detail) => detail?.["@type"] === "type.googleapis.com/google.rpc.RetryInfo"
|
|
180
|
+
)?.retryDelay ?? void 0;
|
|
181
|
+
if (error.status === 429 && retryDelay !== void 0) {
|
|
182
|
+
const sleepTime = config.llm.sleep ?? 3;
|
|
183
|
+
console.warn(
|
|
184
|
+
`Rate limit exceeded when generating response from Gemini model, retrying in... ${retryDelay} + ${sleepTime / 1e3}s`
|
|
185
|
+
);
|
|
186
|
+
await new Promise((resolve) => setTimeout(resolve, (parseInt(retryDelay, 10) + sleepTime / 1e3) * 1e3));
|
|
187
|
+
return generateResponse(prompt, config);
|
|
188
|
+
}
|
|
189
|
+
console.error("Error generating response from Gemini model", { error });
|
|
190
|
+
throw error;
|
|
172
191
|
}
|
|
173
|
-
const response = await model.generateContent([prompt]);
|
|
174
|
-
return response;
|
|
175
192
|
}
|
|
176
193
|
async function askGemini(prompt, prePrompt2, postPrompt2) {
|
|
177
194
|
const config = await awaitedConfig;
|
|
@@ -193,13 +210,7 @@ ${prompt}
|
|
|
193
210
|
${postPrompt2}`).trim();
|
|
194
211
|
let response;
|
|
195
212
|
for (let i = 0; i < 3; i++) {
|
|
196
|
-
const maybeResponse = await generateResponse(fullPrompt, config
|
|
197
|
-
console.log(
|
|
198
|
-
"maybeResponse:",
|
|
199
|
-
"\n\n",
|
|
200
|
-
JSON.stringify({ maybeResponse: maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text }),
|
|
201
|
-
"\n"
|
|
202
|
-
);
|
|
213
|
+
const maybeResponse = await generateResponse(fullPrompt, config);
|
|
203
214
|
const responseString = String(maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text ?? "").replace(/```json/g, "").replace(/```/g, "").trim();
|
|
204
215
|
if (responseString.startsWith("{") && responseString.endsWith("}")) {
|
|
205
216
|
response = maybeResponse;
|
|
@@ -4,8 +4,8 @@ import '../../config.mjs';
|
|
|
4
4
|
import '../../constants/default-config.mjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '../../schemas/config.shcema.mjs';
|
|
7
|
+
import '../../create-cache-id.mjs';
|
|
7
8
|
import '../../data/clear-cache.mjs';
|
|
8
|
-
import '../../data/create-cache-id.mjs';
|
|
9
9
|
import '../../data/get-cache.mjs';
|
|
10
10
|
import '../../flat-template-string.mjs';
|
|
11
11
|
|
|
@@ -6,8 +6,8 @@ import '../../index.mjs';
|
|
|
6
6
|
import '../../config.mjs';
|
|
7
7
|
import '../../constants/default-config.mjs';
|
|
8
8
|
import '../../schemas/config.shcema.mjs';
|
|
9
|
+
import '../../create-cache-id.mjs';
|
|
9
10
|
import '../../data/clear-cache.mjs';
|
|
10
|
-
import '../../data/create-cache-id.mjs';
|
|
11
11
|
import '../../data/get-cache.mjs';
|
|
12
12
|
import '../../flat-template-string.mjs';
|
|
13
13
|
import './parse.mjs';
|
|
@@ -103,9 +103,9 @@ async function loadUserConfig() {
|
|
|
103
103
|
var awaitedConfig = loadUserConfig();
|
|
104
104
|
function defaultPrePrompt(config, extraInstructions) {
|
|
105
105
|
return `
|
|
106
|
-
You are a translation generator.
|
|
106
|
+
You are a ultimate translation generator server api.
|
|
107
107
|
|
|
108
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
108
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
109
109
|
|
|
110
110
|
Follow these rules strictly:
|
|
111
111
|
|
|
@@ -115,7 +115,7 @@ Follow these rules strictly:
|
|
|
115
115
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
116
116
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
117
117
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
118
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
118
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
119
119
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
120
120
|
|
|
121
121
|
{
|
|
@@ -6,8 +6,8 @@ import '../../index.mjs';
|
|
|
6
6
|
import '../../config.mjs';
|
|
7
7
|
import '../../constants/default-config.mjs';
|
|
8
8
|
import '../../schemas/config.shcema.mjs';
|
|
9
|
+
import '../../create-cache-id.mjs';
|
|
9
10
|
import '../../data/clear-cache.mjs';
|
|
10
|
-
import '../../data/create-cache-id.mjs';
|
|
11
11
|
import '../../data/get-cache.mjs';
|
|
12
12
|
import '../../flat-template-string.mjs';
|
|
13
13
|
|
|
@@ -7,7 +7,7 @@ import '../../index.mjs';
|
|
|
7
7
|
import '../../config.mjs';
|
|
8
8
|
import '../../constants/default-config.mjs';
|
|
9
9
|
import '../../schemas/config.shcema.mjs';
|
|
10
|
+
import '../../create-cache-id.mjs';
|
|
10
11
|
import '../../data/clear-cache.mjs';
|
|
11
|
-
import '../../data/create-cache-id.mjs';
|
|
12
12
|
import '../../data/get-cache.mjs';
|
|
13
13
|
import '../../flat-template-string.mjs';
|
|
@@ -103,9 +103,9 @@ async function loadUserConfig() {
|
|
|
103
103
|
var awaitedConfig = loadUserConfig();
|
|
104
104
|
function defaultPrePrompt(config, extraInstructions) {
|
|
105
105
|
return `
|
|
106
|
-
You are a translation generator.
|
|
106
|
+
You are a ultimate translation generator server api.
|
|
107
107
|
|
|
108
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
108
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
109
109
|
|
|
110
110
|
Follow these rules strictly:
|
|
111
111
|
|
|
@@ -115,7 +115,7 @@ Follow these rules strictly:
|
|
|
115
115
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
116
116
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
117
117
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
118
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
118
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
119
119
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
120
120
|
|
|
121
121
|
{
|
|
@@ -4,8 +4,8 @@ import '../../config.mjs';
|
|
|
4
4
|
import '../../constants/default-config.mjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '../../schemas/config.shcema.mjs';
|
|
7
|
+
import '../../create-cache-id.mjs';
|
|
7
8
|
import '../../data/clear-cache.mjs';
|
|
8
|
-
import '../../data/create-cache-id.mjs';
|
|
9
9
|
import '../../data/get-cache.mjs';
|
|
10
10
|
import '../../flat-template-string.mjs';
|
|
11
11
|
|
package/dist/logger.test.mjs
CHANGED
|
@@ -1389,7 +1389,7 @@ var require_utils = __commonJS({
|
|
|
1389
1389
|
// ../node_modules/.pnpm/expect-type@1.2.2/node_modules/expect-type/dist/index.js
|
|
1390
1390
|
var require_dist = __commonJS({
|
|
1391
1391
|
"../node_modules/.pnpm/expect-type@1.2.2/node_modules/expect-type/dist/index.js"(exports) {
|
|
1392
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m3, k2, k22) {
|
|
1392
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m3, k2, k22) {
|
|
1393
1393
|
if (k22 === void 0) k22 = k2;
|
|
1394
1394
|
var desc = Object.getOwnPropertyDescriptor(m3, k2);
|
|
1395
1395
|
if (!desc || ("get" in desc ? !m3.__esModule : desc.writable || desc.configurable)) {
|
|
@@ -1398,10 +1398,10 @@ var require_dist = __commonJS({
|
|
|
1398
1398
|
} };
|
|
1399
1399
|
}
|
|
1400
1400
|
Object.defineProperty(o, k22, desc);
|
|
1401
|
-
} : function(o, m3, k2, k22) {
|
|
1401
|
+
}) : (function(o, m3, k2, k22) {
|
|
1402
1402
|
if (k22 === void 0) k22 = k2;
|
|
1403
1403
|
o[k22] = m3[k2];
|
|
1404
|
-
});
|
|
1404
|
+
}));
|
|
1405
1405
|
var __exportStar = exports && exports.__exportStar || function(m3, exports2) {
|
|
1406
1406
|
for (var p4 in m3) if (p4 !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p4)) __createBinding(exports2, m3, p4);
|
|
1407
1407
|
};
|
|
@@ -13257,7 +13257,7 @@ function afterEach(fn2, timeout) {
|
|
|
13257
13257
|
globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
13258
13258
|
globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
13259
13259
|
|
|
13260
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.
|
|
13260
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_terser@5.44.1/node_modules/vitest/dist/chunks/utils.C8RiOc4B.js
|
|
13261
13261
|
var NAME_WORKER_STATE = "__vitest_worker__";
|
|
13262
13262
|
function getWorkerState() {
|
|
13263
13263
|
const workerState = globalThis[NAME_WORKER_STATE];
|
|
@@ -13317,7 +13317,7 @@ async function waitForImportsToResolve() {
|
|
|
13317
13317
|
await waitForImportsToResolve();
|
|
13318
13318
|
}
|
|
13319
13319
|
|
|
13320
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.
|
|
13320
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_terser@5.44.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
|
|
13321
13321
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
13322
13322
|
function getDefaultExportFromCjs2(x2) {
|
|
13323
13323
|
return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
|
|
@@ -15351,7 +15351,7 @@ var SnapshotClient = class {
|
|
|
15351
15351
|
}
|
|
15352
15352
|
};
|
|
15353
15353
|
|
|
15354
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.
|
|
15354
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_terser@5.44.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.js
|
|
15355
15355
|
var RealDate = Date;
|
|
15356
15356
|
var now2 = null;
|
|
15357
15357
|
var MockDate = class _MockDate extends RealDate {
|
|
@@ -15404,7 +15404,7 @@ function resetDate() {
|
|
|
15404
15404
|
globalThis.Date = RealDate;
|
|
15405
15405
|
}
|
|
15406
15406
|
|
|
15407
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.
|
|
15407
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_terser@5.44.1/node_modules/vitest/dist/chunks/vi.DgezovHB.js
|
|
15408
15408
|
var unsupported = [
|
|
15409
15409
|
// .poll is meant to retry matchers until they succeed, and
|
|
15410
15410
|
// snapshots will always succeed as long as the poll method doesn't thow an error
|
|
@@ -16233,7 +16233,7 @@ function requireTypeDetect() {
|
|
|
16233
16233
|
(function(module, exports) {
|
|
16234
16234
|
(function(global3, factory) {
|
|
16235
16235
|
module.exports = factory();
|
|
16236
|
-
})(typeDetect, function() {
|
|
16236
|
+
})(typeDetect, (function() {
|
|
16237
16237
|
var promiseExists = typeof Promise === "function";
|
|
16238
16238
|
var globalObject = typeof self === "object" ? self : commonjsGlobal;
|
|
16239
16239
|
var symbolExists = typeof Symbol !== "undefined";
|
|
@@ -16342,7 +16342,7 @@ function requireTypeDetect() {
|
|
|
16342
16342
|
return Object.prototype.toString.call(obj).slice(toStringLeftSliceLength, toStringRightSliceLength);
|
|
16343
16343
|
}
|
|
16344
16344
|
return typeDetect2;
|
|
16345
|
-
});
|
|
16345
|
+
}));
|
|
16346
16346
|
})(typeDetect$1);
|
|
16347
16347
|
return typeDetect$1.exports;
|
|
16348
16348
|
}
|
|
@@ -18136,7 +18136,7 @@ function getImporter(name) {
|
|
|
18136
18136
|
return stack?.file || "";
|
|
18137
18137
|
}
|
|
18138
18138
|
|
|
18139
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.
|
|
18139
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_terser@5.44.1/node_modules/vitest/dist/index.js
|
|
18140
18140
|
__toESM(require_dist(), 1);
|
|
18141
18141
|
|
|
18142
18142
|
// src/logger.ts
|
package/dist/types/index.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ import { GringowTranslation, GringowCacheItem } from '../index.mjs';
|
|
|
3
3
|
import { llmOptionsSchema } from '../schemas/config.shcema.mjs';
|
|
4
4
|
import '../config.mjs';
|
|
5
5
|
import '../constants/default-config.mjs';
|
|
6
|
+
import '../create-cache-id.mjs';
|
|
6
7
|
import '../data/clear-cache.mjs';
|
|
7
|
-
import '../data/create-cache-id.mjs';
|
|
8
8
|
import '../data/get-cache.mjs';
|
|
9
9
|
import '../flat-template-string.mjs';
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gringow/gringow",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"main": "./dist/index.
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"main": "./dist/index.mjs",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
|
-
"types": "./dist/index.d.
|
|
6
|
+
"types": "./dist/index.d.mts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"types": "./dist/index.d.
|
|
10
|
-
"require": "./dist/index.
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
|
+
"require": "./dist/index.mjs",
|
|
11
11
|
"import": "./dist/index.mjs"
|
|
12
12
|
},
|
|
13
13
|
"./flat-template-string": {
|
|
14
|
-
"types": "./dist/flat-template-string.d.
|
|
15
|
-
"require": "./dist/flat-template-string.
|
|
14
|
+
"types": "./dist/flat-template-string.d.mts",
|
|
15
|
+
"require": "./dist/flat-template-string.mjs",
|
|
16
16
|
"import": "./dist/flat-template-string.mjs"
|
|
17
17
|
},
|
|
18
18
|
"./browser": {
|
|
19
|
-
"types": "./dist/browser.d.
|
|
20
|
-
"require": "./dist/browser.
|
|
19
|
+
"types": "./dist/browser.d.mts",
|
|
20
|
+
"require": "./dist/browser.mjs",
|
|
21
21
|
"import": "./dist/browser.mjs"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"@google/generative-ai": "^0.24.1",
|
|
71
71
|
"@huggingface/transformers": "^3.6.3",
|
|
72
72
|
"@types/lodash.merge": "^4.6.9",
|
|
73
|
+
"@types/md5": "^2.3.6",
|
|
73
74
|
"cosmiconfig": "^9.0.0",
|
|
74
|
-
"crypto-js": "^4.2.0",
|
|
75
75
|
"lodash.merge": "^4.6.2",
|
|
76
76
|
"onnxruntime-node": "1.22.0-rev",
|
|
77
77
|
"zod": "^3.25.76"
|