mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
fix(main.py): fix order of assembly for streaming chunks
This commit is contained in:
parent
09ec6d6458
commit
bbe6a92eb9
3 changed files with 8 additions and 1 deletions
|
@ -3343,6 +3343,12 @@ def stream_chunk_builder(
|
|||
chunks: list, messages: Optional[list] = None, start_time=None, end_time=None
|
||||
):
|
||||
model_response = litellm.ModelResponse()
|
||||
### SORT CHUNKS BASED ON CREATED ORDER ##
|
||||
if chunks[0]._hidden_params.get("created_at", None):
|
||||
# Sort chunks based on created_at in ascending order
|
||||
chunks = sorted(
|
||||
chunks, key=lambda x: x._hidden_params.get("created_at", float("inf"))
|
||||
)
|
||||
# set hidden params from chunk to model_response
|
||||
if model_response is not None and hasattr(model_response, "_hidden_params"):
|
||||
model_response._hidden_params = chunks[0].get("_hidden_params", {})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue