mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
(fix) streaming openai + function calling
This commit is contained in:
parent
7a669a36d2
commit
1927167bde
1 changed files with 7 additions and 5 deletions
|
@ -162,10 +162,8 @@ class Message(OpenAIObject):
|
||||||
class Delta(OpenAIObject):
|
class Delta(OpenAIObject):
|
||||||
def __init__(self, content=None, role=None, **params):
|
def __init__(self, content=None, role=None, **params):
|
||||||
super(Delta, self).__init__(**params)
|
super(Delta, self).__init__(**params)
|
||||||
if content is not None:
|
self.content = content
|
||||||
self.content = content
|
self.role = role
|
||||||
if role:
|
|
||||||
self.role = role
|
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
# Define custom behavior for the 'in' operator
|
# Define custom behavior for the 'in' operator
|
||||||
|
@ -4867,7 +4865,11 @@ class CustomStreamWrapper:
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
elif response_obj.get("original_chunk", None) is not None: # function / tool calling branch
|
elif response_obj.get("original_chunk", None) is not None: # function / tool calling branch
|
||||||
model_response = response_obj.get("original_chunk", None)
|
original_chunk = response_obj.get("original_chunk", None)
|
||||||
|
model_response.id = original_chunk.id
|
||||||
|
delta = dict(original_chunk.choices[0].delta)
|
||||||
|
model_response.choices[0].delta = Delta(**delta)
|
||||||
|
model_response.system_fingerprint = original_chunk.system_fingerprint
|
||||||
if self.sent_first_chunk == False:
|
if self.sent_first_chunk == False:
|
||||||
completion_obj["role"] = "assistant"
|
completion_obj["role"] = "assistant"
|
||||||
self.sent_first_chunk = True
|
self.sent_first_chunk = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue