Skip to content
Snippets Groups Projects
Unverified Commit 9e142ab4 authored by Logan's avatar Logan Committed by GitHub
Browse files

fix gemini roles (#18108)

parent afe3dcbf
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,8 @@ def chat_from_gemini_response( ...@@ -64,7 +64,8 @@ def chat_from_gemini_response(
raw["usage_metadata"] = response.usage_metadata.model_dump() raw["usage_metadata"] = response.usage_metadata.model_dump()
try: try:
text = response.text parts = response.candidates[0].content.parts
text = "".join([part.text for part in parts if part.text])
except ValueError: except ValueError:
text = None text = None
...@@ -111,9 +112,16 @@ def chat_message_to_gemini(message: ChatMessage) -> types.Content: ...@@ -111,9 +112,16 @@ def chat_message_to_gemini(message: ChatMessage) -> types.Content:
raise ValueError(msg) raise ValueError(msg)
for tool_call in message.additional_kwargs.get("tool_calls", []): for tool_call in message.additional_kwargs.get("tool_calls", []):
parts.append( if isinstance(tool_call, dict):
types.Part.from_function_call(name=tool_call.name, args=tool_call.args) parts.append(
) types.Part.from_function_call(
name=tool_call.get("name"), args=tool_call.get("args")
)
)
else:
parts.append(
types.Part.from_function_call(name=tool_call.name, args=tool_call.args)
)
# the tool call id is the name of the tool # the tool call id is the name of the tool
# the tool call response is the content of the message, overriding the existing content # the tool call response is the content of the message, overriding the existing content
...@@ -123,7 +131,9 @@ def chat_message_to_gemini(message: ChatMessage) -> types.Content: ...@@ -123,7 +131,9 @@ def chat_message_to_gemini(message: ChatMessage) -> types.Content:
name=message.additional_kwargs.get("tool_call_id"), name=message.additional_kwargs.get("tool_call_id"),
response={"result": message.content}, response={"result": message.content},
) )
return types.Content(role="tool", parts=[function_response_part]) return types.Content(
role=ROLES_TO_GEMINI[message.role], parts=[function_response_part]
)
return types.Content( return types.Content(
role=ROLES_TO_GEMINI[message.role], role=ROLES_TO_GEMINI[message.role],
......
...@@ -27,7 +27,7 @@ exclude = ["**/BUILD"] ...@@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT" license = "MIT"
name = "llama-index-llms-google-genai" name = "llama-index-llms-google-genai"
readme = "README.md" readme = "README.md"
version = "0.1.1" version = "0.1.2"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = ">=3.9,<4.0" python = ">=3.9,<4.0"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment