Files
DPM/backend/vendor/s2s-cloud/tests/test_text_prompt.py
T
Pine 7f25c8f6bb refactor(backend): 启动环境初始化与资源项目化(零跨项目依赖)
- main.py:uv run main.py 一键启动——读取 backend/.env、TORCH_HOME/NLTK_DATA 指向项目内缓存、certifi SSL + NO_PROXY 网络直连、默认开启 s2s,启动横幅
- vendor/:补丁后 s2s 云化栈移入项目(backend/vendor/s2s-cloud),pyproject sources 改相对路径
- .gitignore:忽略 .torch-cache / nltk_data 缓存
- AGENTS.md:进程管理铁律(AI 不启动/重启服务,由用户操作)
2026-08-18 01:37:57 +08:00

52 lines
2.0 KiB
Python

from speech_to_speech.LLM.text_prompt import TEXT_SYSTEM_PROMPT, build_text_system_prompt
from speech_to_speech.LLM.tool_call.function_tool import FunctionTool
from speech_to_speech.LLM.tool_call.tool_prompt import build_tool_system_prompt
def test_text_prompt_keeps_persona_in_session_prompt():
prompt = build_text_system_prompt("Be helpful.")
assert "Be helpful." in prompt
assert "You are a helpful assistant in a text conversation." in prompt
assert "You are a helpful assistant in a text conversation." in TEXT_SYSTEM_PROMPT
def test_text_prompt_allows_markdown_and_drops_voice_rules():
prompt = build_text_system_prompt("Be helpful.")
assert "Use markdown when it helps" in prompt
assert "If unsure whether a tool is needed, just answer directly." in prompt
# No spoken-channel rules leak into the text prompt.
assert "Speech is the default." not in prompt
assert "Treat transcripts as noisy." not in prompt
assert "Before a tool call, use a brief natural utterance" not in prompt
assert "speak first" not in prompt
def _dance_tool() -> FunctionTool:
return FunctionTool(
type="function",
name="dance",
description="Dance once.",
parameters={"type": "object", "properties": {}},
)
def test_text_tool_prompt_drops_speak_first_but_keeps_structural_rules():
prompt = build_tool_system_prompt([_dance_tool()], text_only=True)
assert "no preamble sentence is required" in prompt
assert "Only one tool call may appear in a response." in prompt
assert "Omit optional args instead of placeholder values" in prompt
assert "do not claim tool results before a tool result is available" in prompt
# Voice choreography must not appear in the text variant.
assert "always speak first" not in prompt
assert "Sure, here's my best <emotion>." not in prompt
assert "fitting empathetic sentence" not in prompt
def test_voice_tool_prompt_is_default():
prompt = build_tool_system_prompt([_dance_tool()])
assert "always speak first" in prompt