Commit eb02c241 authored by 于飞's avatar 于飞

和上次一样。

parent b16d3991
...@@ -533,7 +533,10 @@ async def stream_generator(chat, incremental: bool, model_name: str): ...@@ -533,7 +533,10 @@ async def stream_generator(chat, incremental: bool, model_name: str):
if chunk: if chunk:
msg = chunk.replace("\ufffd", "") msg = chunk.replace("\ufffd", "")
if incremental: if incremental:
incremental_output = msg[len(previous_response):] incremental_output = msg[len(previous_response):].replace("\n", "\\n")
# 处理连续换行符
incremental_output = incremental_output.replace("\n\n", "\\n\\n")
choice_data = ChatCompletionResponseStreamChoice( choice_data = ChatCompletionResponseStreamChoice(
index=0, index=0,
delta=DeltaMessage(role="assistant", content=incremental_output), delta=DeltaMessage(role="assistant", content=incremental_output),
...@@ -541,9 +544,7 @@ async def stream_generator(chat, incremental: bool, model_name: str): ...@@ -541,9 +544,7 @@ async def stream_generator(chat, incremental: bool, model_name: str):
chunk = ChatCompletionStreamResponse( chunk = ChatCompletionStreamResponse(
id=chat.chat_session_id, choices=[choice_data], model=model_name id=chat.chat_session_id, choices=[choice_data], model=model_name
) )
json_chunk = model_to_json( json_chunk = model_to_json(chunk, exclude_unset=True, ensure_ascii=False)
chunk, exclude_unset=True, ensure_ascii=False
)
yield f"data: {json_chunk}\n\n" yield f"data: {json_chunk}\n\n"
else: else:
# TODO generate an openai-compatible streaming responses # TODO generate an openai-compatible streaming responses
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment