From 57bf30eca15e643909ef02496bb7c4a3003b641d Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 15 Jul 2026 19:32:21 +0200 Subject: [PATCH] fix: normalize CosyVoice3 instructions --- deploy/selfmedia-voice/api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/deploy/selfmedia-voice/api.py b/deploy/selfmedia-voice/api.py index ae55a9e2..b889921a 100644 --- a/deploy/selfmedia-voice/api.py +++ b/deploy/selfmedia-voice/api.py @@ -89,6 +89,17 @@ async def lifespan(_: FastAPI): app = FastAPI(title="SelfMedia Voice", version="1", lifespan=lifespan) +INSTRUCTION_END_TOKEN = "<|endofprompt|>" + + +def normalize_instruction(value: str | None) -> str | None: + if value is None or not value.strip(): + return None + normalized = value.strip() + if INSTRUCTION_END_TOKEN in normalized: + return normalized + return f"You are a helpful assistant. {normalized}{INSTRUCTION_END_TOKEN}" + @app.get("/health") def health() -> dict: @@ -125,7 +136,7 @@ def speech(request: SpeechRequest) -> Response: raise HTTPException(status_code=400, detail="voice must select the configured reference voice") started = time.perf_counter() - instruction = request.instructions or request.instruct + instruction = normalize_instruction(request.instructions or request.instruct) with runtime.lock: inference = ( runtime.model.inference_instruct2(