Skip to content

Commit

Permalink
genai: chore for changing mypy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu007 committed Sep 1, 2024
1 parent 1787dea commit 5a5f8c1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libs/genai/langchain_google_genai/_function_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def convert_to_genai_function_declarations(
tools: Sequence[_ToolsType],
) -> gapic.Tool:
if not isinstance(tools, collections.abc.Sequence):
logger.warning(
logger.warning( # type: ignore[unreachable]
"convert_to_genai_function_declarations expects a Sequence "
"and not a single tool."
)
Expand Down
2 changes: 1 addition & 1 deletion libs/genai/langchain_google_genai/_genai_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from google.api_core import client_options as client_options_lib
from google.api_core import exceptions as gapi_exception
from google.api_core import gapic_v1
from google.auth import credentials, exceptions # type: ignore
from google.auth import credentials, exceptions
from google.protobuf import timestamp_pb2

_logger = logging.getLogger(__name__)
Expand Down
8 changes: 3 additions & 5 deletions libs/genai/langchain_google_genai/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def _achat_with_retry(generation_method: Callable, **kwargs: Any) -> Any:
Any: The result from the chat generation method.
"""
retry_decorator = _create_retry_decorator()
from google.api_core.exceptions import InvalidArgument # type: ignore
from google.api_core.exceptions import InvalidArgument

@retry_decorator
async def _achat_with_retry(**kwargs: Any) -> Any:
Expand Down Expand Up @@ -1232,9 +1232,7 @@ def bind_tools(
genai_tools = [tool_to_dict(convert_to_genai_function_declarations(tools))]
if tool_choice:
all_names = [
f["name"] # type: ignore[index]
for t in genai_tools
for f in t["function_declarations"]
f["name"] for t in genai_tools for f in t["function_declarations"]
]
tool_config = _tool_choice_to_tool_config(tool_choice, all_names)
return self.bind(tools=genai_tools, tool_config=tool_config, **kwargs)
Expand All @@ -1248,4 +1246,4 @@ def _get_tool_name(
tool: Union[ToolDict, GoogleTool],
) -> str:
genai_tool = tool_to_dict(convert_to_genai_function_declarations([tool]))
return [f["name"] for f in genai_tool["function_declarations"]][0] # type: ignore[index]
return [f["name"] for f in genai_tool["function_declarations"]][0]
4 changes: 2 additions & 2 deletions libs/genai/tests/unit_tests/test_function_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def sum_two_numbers(a: float, b: float) -> str:
"""
return str(a + b)

schema = convert_to_genai_function_declarations([sum_two_numbers]) # type: ignore
schema = convert_to_genai_function_declarations([sum_two_numbers])
function_declaration = schema.function_declarations[0]
assert function_declaration.name == "sum_two_numbers"
assert function_declaration.parameters
Expand All @@ -48,7 +48,7 @@ def do_something_optional(a: float, b: float = 0) -> str:
"""Some description"""
return str(a + b)

schema = convert_to_genai_function_declarations([do_something_optional]) # type: ignore
schema = convert_to_genai_function_declarations([do_something_optional])
function_declaration = schema.function_declarations[0]
assert function_declaration.name == "do_something_optional"
assert function_declaration.parameters
Expand Down

0 comments on commit 5a5f8c1

Please sign in to comment.