Update Gemini service to use "user" role for function responses, as shown in the Gemini docs
This commit is contained in:
@@ -242,7 +242,7 @@ class GeminiLLMAdapter(BaseLLMAdapter[GeminiLLMInvocationParams]):
|
|||||||
Converts to Google Content with::
|
Converts to Google Content with::
|
||||||
|
|
||||||
Content(
|
Content(
|
||||||
role="model",
|
role="user",
|
||||||
parts=[Part(function_call=FunctionCall(name="search", args={"query": "test"}))]
|
parts=[Part(function_call=FunctionCall(name="search", args={"query": "test"}))]
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
@@ -273,7 +273,7 @@ class GeminiLLMAdapter(BaseLLMAdapter[GeminiLLMInvocationParams]):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif role == "tool":
|
elif role == "tool":
|
||||||
role = "model"
|
role = "user"
|
||||||
try:
|
try:
|
||||||
response = json.loads(message["content"])
|
response = json.loads(message["content"])
|
||||||
if isinstance(response, dict):
|
if isinstance(response, dict):
|
||||||
@@ -285,13 +285,11 @@ class GeminiLLMAdapter(BaseLLMAdapter[GeminiLLMInvocationParams]):
|
|||||||
# This occurs with a UserImageFrame, for example, where we get a plain "COMPLETED" string.
|
# This occurs with a UserImageFrame, for example, where we get a plain "COMPLETED" string.
|
||||||
response_dict = {"value": message["content"]}
|
response_dict = {"value": message["content"]}
|
||||||
parts.append(
|
parts.append(
|
||||||
Part(
|
Part.from_function_response(
|
||||||
function_response=FunctionResponse(
|
|
||||||
name="tool_call_result", # seems to work to hard-code the same name every time
|
name="tool_call_result", # seems to work to hard-code the same name every time
|
||||||
response=response_dict,
|
response=response_dict,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
elif isinstance(content, str):
|
elif isinstance(content, str):
|
||||||
parts.append(Part(text=content))
|
parts.append(Part(text=content))
|
||||||
elif isinstance(content, list):
|
elif isinstance(content, list):
|
||||||
|
|||||||
Reference in New Issue
Block a user