streaming fixes

This commit is contained in:
ishaan-jaff 2023-09-15 17:46:35 -07:00
parent e1c1493db2
commit ab58e32e90

View file

@ -2454,7 +2454,6 @@ class CustomStreamWrapper:
def __next__(self): def __next__(self):
try: try:
# return this for all models # return this for all models
model_response = ModelResponse(stream=True)
completion_obj = {"content": ""} # default to role being assistant completion_obj = {"content": ""} # default to role being assistant
if self.model in litellm.anthropic_models: if self.model in litellm.anthropic_models:
chunk = next(self.completion_stream) chunk = next(self.completion_stream)
@ -2506,8 +2505,11 @@ class CustomStreamWrapper:
# LOGGING # LOGGING
threading.Thread(target=self.logging_obj.success_handler, args=(completion_obj,)).start() threading.Thread(target=self.logging_obj.success_handler, args=(completion_obj,)).start()
model_response = ModelResponse(stream=True)
model_response.choices[0].delta = completion_obj
model_response.model = self.model
if model_response.choices[0].delta.content == "<special_litellm_token>": if model_response.choices[0].delta['content'] == "<special_litellm_token>":
model_response.choices[0].delta = { model_response.choices[0].delta = {
"content": completion_obj["content"], "content": completion_obj["content"],
} }