Skip to content

Commit ae50957

Browse files
authored
Merge pull request #11 from Ati1707/main
improve koboldcpp prompt for better task accuracy
2 parents fad1e7a + e964ea0 commit ae50957

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,9 @@ cython_debug/
169169

170170
# PyPI configuration file
171171
.pypirc
172+
/.idea/.gitignore
173+
/.idea/misc.xml
174+
/.idea/modules.xml
175+
/.idea/inspectionProfiles/profiles_settings.xml
176+
/.idea/TextAutoTranslate.iml
177+
/.idea/vcs.xml

providers/llm/koboldcpp.py

+27-22
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,44 @@ def __init__(self, api_url):
66
self.api_url = api_url
77

88
def translate(self, text, source_lang=None, target_lang="English"):
9-
source_part = (
10-
f"{source_lang.upper()}-LANGUAGE TEXT"
11-
if source_lang
12-
else "AUTO-DETECTED LANGUAGE TEXT"
13-
)
9+
source_part = f"{source_lang.upper()}" if source_lang else "CHINESE"
1410

1511
target_part = (
1612
target_lang.upper()
1713
if target_lang != "English" # Handle case-insensitive check
1814
else "ENGLISH"
1915
)
2016

21-
lang_instruction = (
22-
f"TRANSLATE THIS {source_part} TO {target_part}\n"
23-
"PRESERVE NUMBERS/NAMES/SPECIAL TERMS AND USE NATURAL FLOW"
24-
)
17+
prompt = f"""STRICT TRANSLATION TASK: {source_part}{target_part}
18+
19+
You are a professional translation engine. Your sole function is to convert Chinese text to English with absolute precision. Follow these directives without exception:
20+
21+
1. MANDATORY OUTPUT FORMAT:
22+
- PURE TRANSLATION ONLY
23+
- NO CHINESE CHARACTERS IN OUTPUT
24+
- NO EXPLANATIONS/COMMENTARY
25+
- NO MARKDOWN/FORMATTING
26+
- NO QUOTES/BRACKETS
27+
- PRESERVE ALL NUMBERS/NAMES/SPECIAL TERMS
28+
- HANDLE SPECIAL CHARACTERS EXACTLY (%, $, ©, etc.)
29+
- SINGLE PARAGRAPH, NO LINE BREAKS
2530
26-
prompt = f"""Execute this translation task precisely:
31+
2. CRITICAL RULES:
32+
- IF INPUT CONTAINS CHINESE, OUTPUT MUST BE ENGLISH
33+
- NEVER PRESERVE CHINESE CHARACTERS
34+
- TRANSLATE ALL TEXT, INCLUDING IDIOMS/PROVERBS
35+
- MAINTAIN ORIGINAL TEXT STRUCTURE
36+
- USE NATURAL, COLLOQUIAL ENGLISH
2737
28-
1. {lang_instruction}
29-
2. OUTPUT MUST BE:
30-
- PURE TRANSLATION ONLY
31-
- NO EXPLANATIONS
32-
- NO FORMATTING
33-
- NO MARKDOWN
34-
- NO QUOTES
35-
3. IF INPUT IS ENGLISH, OUTPUT IDENTICAL TEXT
36-
4. PRESERVE NUMBERS/NAMES/SPECIAL TERMS
37-
5. RESPONSE MUST BE 1 PARAGRAPH, NO LINE BREAKS
38+
3. FAILURE CONDITIONS:
39+
- CHINESE CHARACTERS IN OUTPUT = INCOMPLETE TRANSLATION
40+
- ADDED EXPLANATIONS = TASK FAILURE
41+
- FORMATTING DEVIATIONS = ERROR
3842
39-
INPUT: "{text}"
43+
INPUT TEXT FOR TRANSLATION:
44+
{text}
4045
41-
TRANSLATION OUTPUT: """
46+
TRANSLATION OUTPUT:"""
4247

4348
data = {
4449
"max_context_length": 4096,

0 commit comments

Comments
 (0)