Skip to content

Commit 0232829

Browse files
committed
sys prompt fix
1 parent 6df56fd commit 0232829

File tree

3 files changed

+34
-36
lines changed

3 files changed

+34
-36
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!--b-->
21
<div align="center">
32
<a href="README.md">🇺🇸 English</a> |
43
<a href="locales/README.de.md">🇩🇪 Deutsch</a> |
@@ -14,16 +13,15 @@
1413
<div style="text-align:center; margin:18px 0;">
1514
<img src="monitor/api/static/logo.png" alt="MyGPU logo"/>
1615
</div>
17-
<!--e-->
16+
1817
> *MyGPU: Lightweight GPU Management Utility: a compact `nvidia-smi` wrapper with an elegant web dashboard.*
19-
<!-- b-->
2018
2119
![License](https://img.shields.io/badge/license-MIT-blue.svg)
2220
![Python](https://img.shields.io/badge/python-3.10%2B-blue)
2321
![Version](https://img.shields.io/badge/version-1.2.3-blue)
2422
![Platform](https://img.shields.io/badge/platform-Windows-lightgrey)
2523
![cuda 12.x](https://img.shields.io/badge/CUDA-12.x-0f9d58?logo=nvidia)
26-
<!--e-->
24+
2725
## Gallery
2826

2927
<details>

scripts/translate_eastern.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,33 @@
2727
with open(README_PATH, "r", encoding="utf-8") as f:
2828
original_text = f.read()
2929

30-
# --- PRE-PROCESSING ---
30+
# --- UNIVERSAL PRE-PROCESSING ---
3131
protected_blocks = []
3232

3333
def protect_match(match):
34-
placeholder = f"__PB_{len(protected_blocks)}__"
34+
placeholder = f"[[PB_{len(protected_blocks)}]]"
3535
protected_blocks.append(match.group(0))
3636
return placeholder
3737

3838
text_to_translate = original_text
39-
text_to_translate = re.sub(r'(<!--\s*b\s*-->.*?<!--\s*e\s*-->)', protect_match, text_to_translate, flags=re.DOTALL)
4039

40+
# 1. Protect ALL Code Blocks (Triple Backticks)
41+
text_to_translate = re.sub(r'(```.*?```)', protect_match, text_to_translate, flags=re.DOTALL)
42+
43+
# 2. Protect ALL HTML tags (e.g., <div...>, <img...>, <a...>)
44+
text_to_translate = re.sub(r'(<[^>]+>)', protect_match, text_to_translate)
45+
46+
# 3. Protect ALL Markdown Images and Badges
47+
text_to_translate = re.sub(r'(!\[[^\]]*\]\([^\)]+\))', protect_match, text_to_translate)
4148
# Specialized Prompt for CJK/Eastern Languages
4249
prompt = f"""<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
4350
You are a professional technical {target_lang_name} translator.
4451
Your task is to translate the README into {target_lang_name}.
45-
Keep the markdown format and HTML tags the same.
52+
Keep the markdown and html tag element in original format.
4653
CRITICAL INSTRUCTIONS:
47-
1. **Placeholders**: Keep `__PB_0__`, `__PB_1__` etc. exactly as is. These are protected blocks.
48-
2. **Preserve HTML**: Do NOT translate or modify any HTML tags (lines starting with `<`). Output them exactly as they are in the source.
49-
3. **Preserve Images**: Do NOT translate or modify any Markdown images or badges (lines starting with `![`). Output them exactly as they are in the source. Do NOT add spaces inside URLs.
50-
4. **Translation**: Translate only the text content (paragraphs, headers, lists) into {target_lang_name}.
51-
5. **Technical Terms**: Keep terms like GPU, CLI, VRAM, SSH, Docker, API, CUDA in English.
54+
1. **Technical Preservation**: Keep all product names and technical jargon in English.
55+
2. **System Tags**: Return any text like [[PB_X]] exactly as is. Do not translate or change brackets.
56+
3. **Accuracy**: Maintain 100% technical context.
5257
6. **Context**:
5358
- 'Enforcement' = Policy restriction (e.g., JA: 制限/強制).
5459
- 'Headless' = Server without GUI/display.
@@ -72,11 +77,6 @@ def protect_match(match):
7277
lines = lines[:-1]
7378
translated_content = "\n".join(lines).strip()
7479

75-
# Restore Protected Blocks
76-
for i, block in enumerate(protected_blocks):
77-
placeholder = f"__PB_{i}__"
78-
translated_content = translated_content.replace(placeholder, block)
79-
8080
# 2. Path Correction
8181
# Prepend ../ to relative paths
8282
translated_content = re.sub(r'(\[.*?\]\()(?!(?:http|/|#|\.\./))', r'\1../', translated_content)

scripts/translate_western.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,33 @@
2828
original_text = f.read()
2929

3030
# --- PRE-PROCESSING ---
31+
# --- UNIVERSAL PRE-PROCESSING ---
3132
protected_blocks = []
3233

3334
def protect_match(match):
34-
placeholder = f"__PB_{len(protected_blocks)}__"
35+
placeholder = f"[[PB_{len(protected_blocks)}]]"
3536
protected_blocks.append(match.group(0))
3637
return placeholder
3738

3839
text_to_translate = original_text
39-
text_to_translate = re.sub(r'(<!--\s*b\s*-->.*?<!--\s*e\s*-->)', protect_match, text_to_translate, flags=re.DOTALL)
4040

41+
# 1. Protect ALL Code Blocks (Triple Backticks)
42+
text_to_translate = re.sub(r'(```.*?```)', protect_match, text_to_translate, flags=re.DOTALL)
43+
44+
# 2. Protect ALL HTML tags (e.g., <div...>, <img...>, <a...>)
45+
text_to_translate = re.sub(r'(<[^>]+>)', protect_match, text_to_translate)
46+
47+
# 3. Protect ALL Markdown Images and Badges
48+
text_to_translate = re.sub(r'(!\[[^\]]*\]\([^\)]+\))', protect_match, text_to_translate)
49+
50+
# --- REFINED AGNOSTIC PROMPT ---
4151
prompt = f"""<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
42-
You are a professional technical {target_lang_name} translator.
43-
Your task is to translate the README into {target_lang_name}.
44-
Keep the markdown format and HTML tags the same.
45-
CRITICAL INSTRUCTIONS:
46-
1. **Placeholders**: Keep `__PB_0__`, `__PB_1__` etc. exactly as is. These are protected blocks.
47-
2. **Preserve HTML**: Do NOT translate or modify any HTML tags (lines starting with `<`). Output them exactly as they are in the source.
48-
3. **Preserve Images**: Do NOT translate or modify any Markdown images or badges (lines starting with `![`). Output them exactly as they are in the source.
49-
4. **Translation**: Translate only the text content (paragraphs, headers, lists) into {target_lang_name}.
50-
5. **Technical Terms**: Keep terms like GPU, CLI, VRAM, SSH, Docker, API, CUDA in English.
51-
6. **No Conversational Text**: Output only the final Markdown file content. No code fences.
52-
<|END_OF_TURN_TOKEN|>
52+
You are a professional technical translator. Translate the provided text into professional {target_lang_name}.
53+
RULES:
54+
1. **Technical Preservation**: Keep all product names and technical jargon in English.
55+
2. **System Tags**: Return any text like [[PB_X]] exactly as is. Do not translate or change brackets.
56+
3. **Accuracy**: Maintain 100% technical context.
57+
4. **No Talk**: Output ONLY the translated Markdown.<|END_OF_TURN_TOKEN|>
5358
<|START_OF_TURN_TOKEN|><|USER_TOKEN|>
5459
{text_to_translate}<|END_OF_TURN_TOKEN|>
5560
<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"""
@@ -67,11 +72,6 @@ def protect_match(match):
6772
lines = lines[:-1]
6873
translated_content = "\n".join(lines).strip()
6974

70-
# Restore Protected Blocks
71-
for i, block in enumerate(protected_blocks):
72-
placeholder = f"__PB_{i}__"
73-
translated_content = translated_content.replace(placeholder, block)
74-
7575
# 2. Path Correction
7676
# Prepend ../ to relative paths
7777
translated_content = re.sub(r'(\[.*?\]\()(?!(?:http|/|#|\.\./))', r'\1../', translated_content)

0 commit comments

Comments
 (0)