mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +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
|
chunks: list, messages: Optional[list] = None, start_time=None, end_time=None
|
||||||
):
|
):
|
||||||
model_response = litellm.ModelResponse()
|
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
|
# set hidden params from chunk to model_response
|
||||||
if model_response is not None and hasattr(model_response, "_hidden_params"):
|
if model_response is not None and hasattr(model_response, "_hidden_params"):
|
||||||
model_response._hidden_params = chunks[0].get("_hidden_params", {})
|
model_response._hidden_params = chunks[0].get("_hidden_params", {})
|
||||||
|
|
|
@ -211,7 +211,7 @@ def test_azure_completion_stream():
|
||||||
{"role": "system", "content": "You are a helpful assistant."},
|
{"role": "system", "content": "You are a helpful assistant."},
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "write 1 sentence about litellm being amazing",
|
"content": f"write 1 sentence about litellm being amazing {time.time()}",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
complete_streaming_response = ""
|
complete_streaming_response = ""
|
||||||
|
|
|
@ -7714,6 +7714,7 @@ class CustomStreamWrapper:
|
||||||
else:
|
else:
|
||||||
self.response_id = model_response.id
|
self.response_id = model_response.id
|
||||||
model_response._hidden_params["custom_llm_provider"] = self.custom_llm_provider
|
model_response._hidden_params["custom_llm_provider"] = self.custom_llm_provider
|
||||||
|
model_response._hidden_params["created_at"] = time.time()
|
||||||
model_response.choices = [StreamingChoices()]
|
model_response.choices = [StreamingChoices()]
|
||||||
model_response.choices[0].finish_reason = None
|
model_response.choices[0].finish_reason = None
|
||||||
response_obj = {}
|
response_obj = {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue