fix: normalize CosyVoice3 instructions
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user