Spaces:
Sleeping
Sleeping
Try a better prompt
Browse files- document-authoring.js +29 -11
- service-config.yml +2 -1
document-authoring.js
CHANGED
|
@@ -102,7 +102,8 @@ script.onload = async () => {
|
|
| 102 |
for (let key in obj) {
|
| 103 |
const newPath = [...path, key];
|
| 104 |
if (typeof obj[key] === "string" && key === "text" && obj[key].length > 0) {
|
| 105 |
-
|
|
|
|
| 106 |
} else if (typeof obj[key] === "object") {
|
| 107 |
flattenTextRuns(obj[key], newPath, result);
|
| 108 |
}
|
|
@@ -146,19 +147,36 @@ script.onload = async () => {
|
|
| 146 |
messages: [
|
| 147 |
{
|
| 148 |
role: "user",
|
| 149 |
-
content: `
|
| 150 |
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
-
|
| 155 |
-
1. Do NOT translate proper nouns (names of people, companies, products, places)
|
| 156 |
-
2. Preserve original capitalization and punctuation
|
| 157 |
-
3. Add spaces at the start or end of segments only if they exist in the original text
|
| 158 |
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
${content}`
|
| 164 |
}
|
|
|
|
| 102 |
for (let key in obj) {
|
| 103 |
const newPath = [...path, key];
|
| 104 |
if (typeof obj[key] === "string" && key === "text" && obj[key].length > 0) {
|
| 105 |
+
// Trim any whitespace between text and delimiters.
|
| 106 |
+
result.push({ text: obj[key].trim(), path: newPath });
|
| 107 |
} else if (typeof obj[key] === "object") {
|
| 108 |
flattenTextRuns(obj[key], newPath, result);
|
| 109 |
}
|
|
|
|
| 147 |
messages: [
|
| 148 |
{
|
| 149 |
role: "user",
|
| 150 |
+
content: `You are a translator. Translate ONLY the exact text between ||| delimiters. Each segment must be translated separately and maintain its own delimiters. The word "Nutrient" must stay EXACTLY as "Nutrient".
|
| 151 |
|
| 152 |
+
Rules:
|
| 153 |
+
1. Do NOT translate proper nouns
|
| 154 |
+
2. Keep original capitalization and punctuation
|
| 155 |
+
3. Preserve ALL spaces exactly as they appear in the original text
|
| 156 |
+
4. For Spanish, use proper inverted punctuation (¡ ¿)
|
| 157 |
+
5. Keep each segment separate - do not combine segments
|
| 158 |
|
| 159 |
+
Examples of correct translations:
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
+
Complex sentence split across segments:
|
| 162 |
+
|||John's report shows that|||
|
| 163 |
+
|||John muestra que|||
|
| 164 |
+
|
| 165 |
+
|||the project will be|||
|
| 166 |
+
|||el proyecto estará|||
|
| 167 |
+
|
| 168 |
+
|||completed by Friday.|||
|
| 169 |
+
|||terminado el viernes.|||
|
| 170 |
+
|
| 171 |
+
Punctuation and spacing:
|
| 172 |
+
|||Hello, world!|||
|
| 173 |
+
|||¡Hola, mundo!|||
|
| 174 |
+
|
| 175 |
+
Mixed content with numbers:
|
| 176 |
+
|||Room 101 is empty.|||
|
| 177 |
+
|||La habitación 101 está vacía.|||
|
| 178 |
+
|
| 179 |
+
Now translate this text from ${sourceLang} to ${targetLang}:
|
| 180 |
|
| 181 |
${content}`
|
| 182 |
}
|
service-config.yml
CHANGED
|
@@ -16,4 +16,5 @@ aiServices:
|
|
| 16 |
model:
|
| 17 |
name: 'tgi'
|
| 18 |
id: 'gemma-2b'
|
| 19 |
-
topP: 0.
|
|
|
|
|
|
| 16 |
model:
|
| 17 |
name: 'tgi'
|
| 18 |
id: 'gemma-2b'
|
| 19 |
+
topP: 0.7
|
| 20 |
+
temperature: 0.5
|