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

Function calling mode patch #271

Merged
13 changes: 12 additions & 1 deletion google/generativeai/types/content_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,19 @@ class FunctionCallingConfigDict(TypedDict):


def to_function_calling_config(obj: FunctionCallingConfigType) -> glm.FunctionCallingConfig:
if isinstance(obj, (FunctionCallingMode, str, int)):
if isinstance(obj, glm.FunctionCallingConfig):
return obj
elif isinstance(obj, (FunctionCallingMode, str, int)):
obj = {"mode": to_function_calling_mode(obj)}
elif isinstance(obj, dict):
obj = obj.copy()
mode = obj.pop("mode")
obj["mode"] = to_function_calling_mode(mode)
else:
raise TypeError(
f"Could not convert input to `glm.FunctionCallingConfig`: \n'" f" type: {type(obj)}\n",
obj,
)

return glm.FunctionCallingConfig(obj)

Expand Down
Loading