mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-30 02:35:29 +08:00
28 lines
801 B
Python
28 lines
801 B
Python
import typing
|
|
from subprocess import Popen
|
|
from typing import Optional
|
|
|
|
from model_providers.core.bootstrap.openai_protocol import (
|
|
ChatCompletionStreamResponse,
|
|
ChatCompletionStreamResponseChoice,
|
|
Finish,
|
|
)
|
|
from model_providers.core.utils.generic import jsonify
|
|
|
|
if typing.TYPE_CHECKING:
|
|
from model_providers.core.bootstrap.openai_protocol import ChatCompletionMessage
|
|
|
|
|
|
def create_stream_chunk(
|
|
request_id: str,
|
|
model: str,
|
|
delta: "ChatCompletionMessage",
|
|
index: Optional[int] = 0,
|
|
finish_reason: Optional[Finish] = None,
|
|
) -> str:
|
|
choice = ChatCompletionStreamResponseChoice(
|
|
index=index, delta=delta, finish_reason=finish_reason
|
|
)
|
|
chunk = ChatCompletionStreamResponse(id=request_id, model=model, choices=[choice])
|
|
return jsonify(chunk)
|