Skip to content

Commit d17fc8f

Browse files
committed
Fix mypy linting issues for Python 3.9 compatibility
- Reorder convert_to_oci_tool checks to avoid unreachable code warning - Fix type annotation in test_stream_vllm to use BaseMessageChunk
1 parent d0d2c5d commit d17fc8f

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

libs/oci/langchain_oci/chat_models/oci_generative_ai.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -945,22 +945,8 @@ def convert_to_oci_tool(
945945
Raises:
946946
ValueError: If the tool type is not supported.
947947
"""
948-
if (isinstance(tool, type) and issubclass(tool, BaseModel)) or callable(tool):
949-
as_json_schema_function = convert_to_openai_function(tool)
950-
parameters = as_json_schema_function.get("parameters", {})
951-
return self.oci_function_definition(
952-
name=as_json_schema_function.get("name"),
953-
description=as_json_schema_function.get(
954-
"description",
955-
as_json_schema_function.get("name"),
956-
),
957-
parameters={
958-
"type": "object",
959-
"properties": parameters.get("properties", {}),
960-
"required": parameters.get("required", []),
961-
},
962-
)
963-
elif isinstance(tool, BaseTool):
948+
# Check BaseTool first since it's callable but needs special handling
949+
if isinstance(tool, BaseTool):
964950
return self.oci_function_definition(
965951
name=tool.name,
966952
description=OCIUtils.remove_signature_from_tool_description(
@@ -982,6 +968,21 @@ def convert_to_oci_tool(
982968
],
983969
},
984970
)
971+
if (isinstance(tool, type) and issubclass(tool, BaseModel)) or callable(tool):
972+
as_json_schema_function = convert_to_openai_function(tool)
973+
parameters = as_json_schema_function.get("parameters", {})
974+
return self.oci_function_definition(
975+
name=as_json_schema_function.get("name"),
976+
description=as_json_schema_function.get(
977+
"description",
978+
as_json_schema_function.get("name"),
979+
),
980+
parameters={
981+
"type": "object",
982+
"properties": parameters.get("properties", {}),
983+
"required": parameters.get("required", []),
984+
},
985+
)
985986
raise ValueError(
986987
f"Unsupported tool type {type(tool)}. "
987988
"Tool must be passed in as a BaseTool "

libs/oci/tests/unit_tests/chat_models/test_oci_data_science.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from unittest import mock
66

77
import pytest
8-
from langchain_core.messages import AIMessage, AIMessageChunk
8+
from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessageChunk
99
from requests.exceptions import HTTPError
1010

1111
from langchain_oci.chat_models import (
@@ -145,7 +145,7 @@ def test_stream_vllm(*args: Any) -> None:
145145
endpoint=CONST_ENDPOINT, model=CONST_MODEL_NAME, streaming=True
146146
)
147147
assert llm._headers().get("route") == CONST_COMPLETION_ROUTE
148-
output: Optional[AIMessageChunk] = None
148+
output: Optional[BaseMessageChunk] = None
149149
count = 0
150150
for chunk in llm.stream(CONST_PROMPT):
151151
assert isinstance(chunk, AIMessageChunk)
@@ -156,8 +156,7 @@ def test_stream_vllm(*args: Any) -> None:
156156
count += 1
157157
assert count == 5
158158
assert output is not None
159-
if output is not None:
160-
assert str(output.content).strip() == CONST_COMPLETION
159+
assert str(output.content).strip() == CONST_COMPLETION
161160

162161

163162
async def mocked_async_streaming_response(

0 commit comments

Comments
 (0)