26 lines
900 B
Python
26 lines
900 B
Python
|
|
"""segments_from_llm_response:与客户端 split 规则对齐的单元校验。"""
|
|||
|
|
|
|||
|
|
from app.agents.chat.reply_limits import (
|
|||
|
|
nonempty_segments_or_fallback,
|
|||
|
|
segments_from_llm_response,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_split_marker():
|
|||
|
|
assert segments_from_llm_response("a[SPLIT]b", max_segments=3) == ["a", "b"]
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_paragraph_fallback_when_no_marker():
|
|||
|
|
a = "太为你高兴了!在上海大剧院的舞台绽放,聚光灯下的你。"
|
|||
|
|
b = "说到舞台,我忽然想起你黄浦江边的童年。从看着江水流淌,到在舞台上演绎别人的悲欢。"
|
|||
|
|
assert segments_from_llm_response(f"{a}\n\n{b}", max_segments=3) == [a, b]
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_short_paragraphs_not_split():
|
|||
|
|
t = "a\n\nb"
|
|||
|
|
assert segments_from_llm_response(t, max_segments=3) == [t]
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_nonempty_fallback_when_all_blank():
|
|||
|
|
assert nonempty_segments_or_fallback(["", " "], fallback="ok") == ["ok"]
|