feat:截断优化
This commit is contained in:
@@ -888,7 +888,16 @@ class AIChat(PluginBase):
|
|||||||
max_chars = 0
|
max_chars = 0
|
||||||
|
|
||||||
if max_chars and max_chars > 0 and cleaned and len(cleaned) > max_chars:
|
if max_chars and max_chars > 0 and cleaned and len(cleaned) > max_chars:
|
||||||
cleaned = cleaned[:max_chars].rstrip()
|
trimmed = cleaned[:max_chars].rstrip()
|
||||||
|
# 尽量在句末截断,避免半句被硬切(仍保证不超过上限)
|
||||||
|
cut_idx = -1
|
||||||
|
for ch in ("。", "!", "?", "!", "?", "\n"):
|
||||||
|
idx = trimmed.rfind(ch)
|
||||||
|
if idx > cut_idx:
|
||||||
|
cut_idx = idx
|
||||||
|
if cut_idx >= max_chars * 0.5:
|
||||||
|
trimmed = trimmed[:cut_idx + 1].rstrip()
|
||||||
|
cleaned = trimmed
|
||||||
|
|
||||||
if cleaned:
|
if cleaned:
|
||||||
return cleaned
|
return cleaned
|
||||||
|
|||||||
Reference in New Issue
Block a user