Skip to content

Commit eb89f31

Browse files
committed
sys prompt fix
1 parent 5d1bddc commit eb89f31

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

README.md

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

2729
<details>

scripts/translate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def protect_match(match):
4646

4747
text_to_translate = original_text
4848

49+
# 0. Protect Explicit Blocks (<!-- b --> ... <!-- e -->)
50+
text_to_translate = re.sub(r'(<!--\s*b\s*-->.*?<!--\s*e\s*-->)', protect_match, text_to_translate, flags=re.DOTALL)
4951
# 1. Protect Navigation Bar (Robust regex for attributes and whitespace)
5052
text_to_translate = re.sub(r'(<div\s+[^>]*align=["\']center["\'][^>]*>.*?</div>)', protect_match, text_to_translate, flags=re.DOTALL | re.IGNORECASE)
5153
# 2. Protect Logo Block (Robust regex for style attribute)

scripts/translate_eastern.py

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

30+
# --- PRE-PROCESSING ---
31+
protected_blocks = []
32+
33+
def protect_match(match):
34+
placeholder = f"__PB_{len(protected_blocks)}__"
35+
protected_blocks.append(match.group(0))
36+
return placeholder
37+
3038
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)
3140

3241
# Specialized Prompt for CJK/Eastern Languages
3342
prompt = f"""<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
3443
You are a professional technical {target_lang_name} translator.
3544
Your task is to translate the README into {target_lang_name}.
3645
Keep the markdown format and HTML tags the same.
3746
CRITICAL INSTRUCTIONS:
38-
1. **Preserve HTML**: Do NOT translate or modify any HTML tags (lines starting with `<`). Output them exactly as they are in the source.
39-
2. **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.
40-
3. **Translation**: Translate only the text content (paragraphs, headers, lists) into {target_lang_name}.
41-
4. **Technical Terms**: Keep terms like GPU, CLI, VRAM, SSH, Docker, API, CUDA in English.
42-
5. **Context**:
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.
52+
6. **Context**:
4353
- 'Enforcement' = Policy restriction (e.g., JA: 制限/強制).
4454
- 'Headless' = Server without GUI/display.
4555
- 'Agnostic' = Hardware Independence (JA: 非依存, ZH: 无关性).
46-
6. **No Conversational Text**: Output only the final Markdown file content. No "Here is the translation" or code fences.
56+
7. **No Conversational Text**: Output only the final Markdown file content. No "Here is the translation" or code fences.
4757
<|END_OF_TURN_TOKEN|>
4858
<|START_OF_TURN_TOKEN|><|USER_TOKEN|>
4959
{text_to_translate}<|END_OF_TURN_TOKEN|>
@@ -62,6 +72,11 @@
6272
lines = lines[:-1]
6373
translated_content = "\n".join(lines).strip()
6474

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+
6580
# 2. Path Correction
6681
# Prepend ../ to relative paths
6782
translated_content = re.sub(r'(\[.*?\]\()(?!(?:http|/|#|\.\./))', r'\1../', translated_content)

scripts/translate_western.py

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

30-
# --- PRE-PROCESSING---
30+
# --- PRE-PROCESSING ---
31+
protected_blocks = []
32+
33+
def protect_match(match):
34+
placeholder = f"__PB_{len(protected_blocks)}__"
35+
protected_blocks.append(match.group(0))
36+
return placeholder
3137

3238
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)
3340

3441
prompt = f"""<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
3542
You are a professional technical {target_lang_name} translator.
3643
Your task is to translate the README into {target_lang_name}.
3744
Keep the markdown format and HTML tags the same.
3845
CRITICAL INSTRUCTIONS:
39-
1. **Preserve HTML**: Do NOT translate or modify any HTML tags (lines starting with `<`). Output them exactly as they are in the source.
40-
2. **Preserve Images**: Do NOT translate or modify any Markdown images or badges (lines starting with `![`). Output them exactly as they are in the source.
41-
3. **Translation**: Translate only the text content (paragraphs, headers, lists) into {target_lang_name}.
42-
4. **Technical Terms**: Keep terms like GPU, CLI, VRAM, SSH, Docker, API, CUDA in English.
43-
5. **No Conversational Text**: Output only the final Markdown file content. No code fences.
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.
4452
<|END_OF_TURN_TOKEN|>
4553
<|START_OF_TURN_TOKEN|><|USER_TOKEN|>
4654
{text_to_translate}<|END_OF_TURN_TOKEN|>
@@ -59,6 +67,11 @@
5967
lines = lines[:-1]
6068
translated_content = "\n".join(lines).strip()
6169

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+
6275
# 2. Path Correction
6376
# Prepend ../ to relative paths
6477
translated_content = re.sub(r'(\[.*?\]\()(?!(?:http|/|#|\.\./))', r'\1../', translated_content)

0 commit comments

Comments
 (0)