Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure that streaming works with function calls - (drop python3.8) #1137

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions integrations/google_ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ name = "google-ai-haystack"
dynamic = ["version"]
description = 'Use models like Gemini via Makersuite'
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = "Apache-2.0"
keywords = []
authors = [{ name = "deepset GmbH", email = "[email protected]" }]
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,20 +347,21 @@ def _get_stream_response(
replies: List[ChatMessage] = []
for chunk in stream:
content: Union[str, Dict[str, Any]] = ""
metadata = chunk.to_dict() # we store whole chunk as metadata in streaming calls
for candidate in chunk.candidates:
for part in candidate.content.parts:
if part.text != "":
content = part.text
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=metadata, name=None))
elif part.function_call is not None:
metadata["function_call"] = part.function_call
content = dict(part.function_call.args.items())
elif "function_call" in part and len(part["function_call"]) > 0:
metadata["function_call"] = part["function_call"]
content = part["function_call"]["args"]
replies.append(
ChatMessage(
content=content,
role=ChatRole.ASSISTANT,
name=part.function_call.name,
name=part["function_call"]["name"],
meta=metadata,
)
)
Expand Down