Refactor settings store to rename proModel to proThinking and update related logic; enhance CSS for energy efficiency and reduced motion preferences; improve i18n translations for better clarity and consistency; modify proBlock utility functions for clearer instruction handling; streamline Vite configuration by removing unnecessary Univer.js dependencies.
This commit is contained in:
+56
-21
@@ -65,6 +65,53 @@ def _prepare_context(prefix: str, suffix: str) -> Tuple[str, str]:
|
||||
return clean_prefix, clean_suffix
|
||||
|
||||
|
||||
def _strip_hidden_tail_context(text: str) -> str:
|
||||
"""
|
||||
Return the likely visible tail segment used for prefill.
|
||||
|
||||
The frontend prepends hidden OCR/doc context before the visible markdown and
|
||||
joins those blocks with blank lines. For prefill we only want the active
|
||||
visible segment near the cursor, not earlier hidden context.
|
||||
"""
|
||||
value = _normalize_newlines(text or "")
|
||||
if not value:
|
||||
return ""
|
||||
tail = re.split(r"\n{2,}", value)[-1]
|
||||
tail = re.sub(r"<!--[\s\S]*?-->", "", tail)
|
||||
tail = re.sub(r"<OCR:[^>\n]*>", "", tail)
|
||||
return tail.split("\n")[-1]
|
||||
|
||||
|
||||
def _build_completion_prefill(prefix: str) -> str:
|
||||
"""
|
||||
Build a short tail prefill after <|fim_middle|> so completion models keep
|
||||
writing from the existing text instead of explaining the boundary rules.
|
||||
"""
|
||||
normalized = _normalize_newlines(prefix or "")
|
||||
if not normalized or normalized[-1].isspace():
|
||||
return ""
|
||||
|
||||
tail = _strip_hidden_tail_context(normalized).strip()
|
||||
if len(tail) < 2:
|
||||
return ""
|
||||
|
||||
cjk_match = re.search(r"[\u3400-\u9fff]{2,6}$", tail)
|
||||
if cjk_match:
|
||||
value = cjk_match.group(0)
|
||||
return value[-2:] if len(value) > 2 else value
|
||||
|
||||
token_match = re.search(r"[A-Za-z0-9_+\-.]{2,12}$", tail)
|
||||
if token_match:
|
||||
value = token_match.group(0)
|
||||
return value[-12:]
|
||||
|
||||
compact_match = re.search(r"\S{2,12}$", tail)
|
||||
if compact_match:
|
||||
return compact_match.group(0)[-12:]
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
FENCE_LINE_RE = re.compile(r"^[ \t]*```.*$")
|
||||
FENCE_INFO_RE = re.compile(r"^[ \t]*```[ \t]*(.*)$")
|
||||
MERMAID_CONTEXT_RE = re.compile(
|
||||
@@ -256,7 +303,7 @@ def build_completion_prompts(
|
||||
location: str = "",
|
||||
thinking_level: str = "low",
|
||||
preferences: UserPreferences | None = None,
|
||||
) -> Tuple[str, str]:
|
||||
) -> Tuple[str, str, str]:
|
||||
safe_language_id = _canonical_language_id(language_id)
|
||||
recent_prefix, recent_suffix = _prepare_context(prefix, suffix)
|
||||
recent_prefix = _normalize_newlines(recent_prefix)
|
||||
@@ -269,6 +316,7 @@ def build_completion_prompts(
|
||||
)
|
||||
prefix_ends_with_newline = recent_prefix.endswith("\n")
|
||||
suffix_starts_with_newline = recent_suffix.startswith("\n")
|
||||
prefill = _build_completion_prefill(recent_prefix)
|
||||
|
||||
tz_pref = preferences.timezone if preferences else "auto"
|
||||
current_time = _get_current_datetime(tz_pref)
|
||||
@@ -303,38 +351,25 @@ Requirements:
|
||||
- Concise unless structure needs more
|
||||
- Follows markdown rules in system prompt
|
||||
- Use real line breaks instead of spelled-out escape sequences unless PREFIX or SUFFIX clearly requires that text
|
||||
|
||||
=== BOUNDARY DECISION GUIDE ===
|
||||
|
||||
Step 1: Check PREFIX_ENDS_WITH_NEWLINE
|
||||
If false, ask: "Does output need to start on a new line?"
|
||||
- YES if PREFIX ends with: ":", "steps:", "items:", heading text, or complete sentence before heading
|
||||
- If YES: make the first character of OUTPUT a real newline
|
||||
|
||||
Step 2: Check SUFFIX_STARTS_WITH_NEWLINE
|
||||
If false, ask: "Does output need to end with a newline?"
|
||||
- YES if SUFFIX starts with: heading (##), new paragraph, or list marker
|
||||
- If YES: make the last character of OUTPUT a real newline
|
||||
|
||||
Step 3: Choose newline type
|
||||
- Use a blank line for: new paragraphs, before headings, starting lists
|
||||
- Use a single line break for: continuing within blocks, list items, table cells
|
||||
- Exception: inside code fences, use real newline characters freely
|
||||
- If a boundary needs separation, put the real newline directly in OUTPUT
|
||||
- Do not explain newline or boundary choices
|
||||
- Continue after the PREFILL text already placed after <|fim_middle|>
|
||||
|
||||
=== CONTEXT NOTES ===
|
||||
- OCR metadata (e.g., <OCR:description>) is hidden context, never copy to output
|
||||
- Match PREFIX tone, style, and indentation
|
||||
- Do not repeat text from SUFFIX beginning
|
||||
- <|fim_prefix|>, <|fim_suffix|>, <|fim_middle|>, and PREFILL are control context only; never output these markers
|
||||
|
||||
=== EXAMPLES BY CATEGORY ===
|
||||
{_INLINE_EXAMPLES}
|
||||
|
||||
=== NOW COMPLETE THE TASK ===
|
||||
|
||||
<|fim_prefix|>{recent_prefix}<|fim_suffix|>{recent_suffix}<|fim_middle|>"""
|
||||
<|fim_prefix|>{recent_prefix}<|fim_suffix|>{recent_suffix}<|fim_middle|>{prefill}"""
|
||||
|
||||
system_prompt = build_inline_system_prompt(safe_language_id)
|
||||
return system_prompt.strip(), user_prompt.strip()
|
||||
return system_prompt.strip(), user_prompt.strip(), prefill
|
||||
|
||||
|
||||
def build_prompt(
|
||||
@@ -348,7 +383,7 @@ def build_prompt(
|
||||
"""
|
||||
Backward-compatible helper. Returns only the user prompt body.
|
||||
"""
|
||||
_, user_prompt = build_completion_prompts(
|
||||
_, user_prompt, _ = build_completion_prompts(
|
||||
prefix=prefix,
|
||||
suffix=suffix,
|
||||
language_id=language_id,
|
||||
|
||||
Reference in New Issue
Block a user