perf(prompt_opt): optimize streaming output structure and add variable parsing

This commit is contained in:
mengyonghao
2026-01-05 17:31:28 +08:00
parent 29ccf956ec
commit 05ec76f940
2 changed files with 5 additions and 5 deletions

View File

@@ -117,7 +117,7 @@ async def get_prompt_opt(
user_require=data.message
):
# chunk 是 prompt 的增量内容
yield f"event:'message'\ndata: {json.dumps(chunk)}\n\n"
yield f"event:message\ndata: {json.dumps(chunk)}\n\n"
return StreamingResponse(
event_generator(),

View File

@@ -231,9 +231,9 @@ class PromptOptimizerService:
if m:
prompt_index = m.start()
prompt_finished = True
yield {"type": "delta", "content": buffer[idx:prompt_index]}
yield {"content": buffer[idx:prompt_index]}
else:
yield {"type": "delta", "content": cache[idx:]}
yield {"content": cache[idx:]}
if len(cache) != 0:
idx = len(cache)
@@ -249,8 +249,8 @@ class PromptOptimizerService:
role=RoleType.ASSISTANT,
content=desc
)
yield {"type": "done", "desc": optim_result.get("desc")}
variables = self.parser_prompt_variables(optim_result.get("prompt"))
yield {"desc": optim_result.get("desc"), "variables": variables}
@staticmethod
def parser_prompt_variables(prompt: str):