def _make_tools()

in google/generativeai/types/content_types.py [0:0]


def _make_tools(tools: ToolsType) -> list[Tool]:
    if isinstance(tools, str):
        if tools.lower() == "code_execution" or tools.lower() == "google_search_retrieval":
            return [_make_tool(tools)]
        else:
            raise ValueError("The only string that can be passed as a tool is 'code_execution'.")
    elif isinstance(tools, Iterable) and not isinstance(tools, Mapping):
        tools = [_make_tool(t) for t in tools]
        if len(tools) > 1 and all(len(t.function_declarations) == 1 for t in tools):
            # flatten into a single tool.
            tools = [_make_tool([t.function_declarations[0] for t in tools])]
        return tools
    else:
        tool = tools
        return [_make_tool(tool)]