From 0fd8545862e69e2afb3de7c6c26df2cf9912e5f7 Mon Sep 17 00:00:00 2001 From: anakin87 Date: Tue, 15 Oct 2024 12:11:44 +0200 Subject: [PATCH] keep metadata var --- .../components/generators/google_ai/chat/gemini.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integrations/google_ai/src/haystack_integrations/components/generators/google_ai/chat/gemini.py b/integrations/google_ai/src/haystack_integrations/components/generators/google_ai/chat/gemini.py index af54459ca..9392530c4 100644 --- a/integrations/google_ai/src/haystack_integrations/components/generators/google_ai/chat/gemini.py +++ b/integrations/google_ai/src/haystack_integrations/components/generators/google_ai/chat/gemini.py @@ -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( @@ -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