Skip to content

Commit

Permalink
keep metadata var
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Oct 15, 2024
1 parent 0582d32 commit 0fd8545
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,16 @@ def _get_stream_response(
replies: List[ChatMessage] = []
for chunk in stream:
content: Union[str, Dict[str, Any]] = ""
dict_chunk = chunk.to_dict() # we store whole chunk as metadata in streaming calls
dict_chunk = chunk.to_dict()
metadata = dict(dict_chunk) # we copy and store the whole chunk as metadata in streaming calls
for candidate in dict_chunk["candidates"]:
for part in candidate["content"]["parts"]:
if "text" in part and part["text"] != "":
content = part["text"]
replies.append(
ChatMessage(content=content, role=ChatRole.ASSISTANT, meta=dict_chunk, name=None)
ChatMessage(content=content, role=ChatRole.ASSISTANT, meta=metadata, name=None)
)
elif "function_call" in part and len(part["function_call"]) > 0:
metadata = dict(dict_chunk)
metadata["function_call"] = part["function_call"]
content = part["function_call"]["args"]
replies.append(
Expand All @@ -368,5 +368,5 @@ def _get_stream_response(
)
)

streaming_callback(StreamingChunk(content=content, meta=dict_chunk))
streaming_callback(StreamingChunk(content=content, meta=metadata))
return replies

0 comments on commit 0fd8545

Please sign in to comment.