Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Free Disk Space
run: |
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force

- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Free Disk Space
run: |
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force

- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
Expand Down
2 changes: 1 addition & 1 deletion libs/oci/langchain_oci/chat_models/oci_data_science.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def with_structured_output(
if method == "json_mode":
llm = self.bind(response_format={"type": "json_object"})
output_parser = (
PydanticOutputParser(pydantic_object=schema) # type: ignore[type-var, arg-type]
PydanticOutputParser(pydantic_object=schema)
if is_pydantic_schema
else JsonOutputParser()
)
Expand Down
31 changes: 15 additions & 16 deletions libs/oci/langchain_oci/chat_models/oci_generative_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
AIMessage,
AIMessageChunk,
BaseMessage,
ChatMessage,
HumanMessage,
SystemMessage,
ToolCall,
Expand Down Expand Up @@ -350,7 +349,7 @@ def get_role(self, message: BaseMessage) -> str:
raise ValueError(f"Unknown message type: {type(message)}")

def messages_to_oci_params(
self, messages: Sequence[ChatMessage], **kwargs: Any
self, messages: Sequence[BaseMessage], **kwargs: Any
) -> Dict[str, Any]:
"""
Convert LangChain messages to OCI parameters for Cohere.
Expand Down Expand Up @@ -417,7 +416,7 @@ def messages_to_oci_params(
current_turn = list(reversed(current_turn))

# Process tool results from the current turn
oci_tool_results: List[Any] = []
oci_tool_results: Optional[List[Any]] = []
for message in current_turn:
if isinstance(message, ToolMessage):
tool_msg = message
Expand All @@ -434,7 +433,7 @@ def messages_to_oci_params(
parameters=lc_tool_call["args"],
)
tool_result.outputs = [{"output": tool_msg.content}]
oci_tool_results.append(tool_result)
oci_tool_results.append(tool_result) # type: ignore[union-attr]
if not oci_tool_results:
oci_tool_results = None

Expand Down Expand Up @@ -552,7 +551,7 @@ def process_stream_tool_calls(
Returns:
List of ToolCallChunk objects
"""
tool_call_chunks = []
tool_call_chunks: List[ToolCallChunk] = []
tool_call_response = self.chat_stream_tool_calls(event_data)

if not tool_call_response:
Expand Down Expand Up @@ -813,7 +812,7 @@ def _should_allow_more_tool_calls(
return False

# Detect infinite loop: same tool called with same arguments in succession
recent_calls = []
recent_calls: list = []
for msg in reversed(messages):
if hasattr(msg, "tool_calls") and msg.tool_calls:
for tc in msg.tool_calls:
Expand Down Expand Up @@ -895,7 +894,7 @@ def _process_message_content(

def convert_to_oci_tool(
self,
tool: Union[Type[BaseModel], Callable, BaseTool],
tool: Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool],
) -> Dict[str, Any]:
"""Convert a BaseTool instance, TypedDict or BaseModel type
to a OCI tool in Meta's format.
Expand Down Expand Up @@ -925,8 +924,8 @@ def convert_to_oci_tool(
"required": parameters.get("required", []),
},
)
elif isinstance(tool, BaseTool):
return self.oci_function_definition(
elif isinstance(tool, BaseTool): # type: ignore[unreachable]
return self.oci_function_definition( # type: ignore[unreachable]
name=tool.name,
description=OCIUtils.remove_signature_from_tool_description(
tool.name, tool.description
Expand Down Expand Up @@ -1016,7 +1015,7 @@ def process_stream_tool_calls(
Returns:
List of ToolCallChunk objects
"""
tool_call_chunks = []
tool_call_chunks: List[ToolCallChunk] = []
tool_call_response = self.chat_stream_tool_calls(event_data)

if not tool_call_response:
Expand Down Expand Up @@ -1142,7 +1141,7 @@ def _prepare_request(
stop: Optional[List[str]],
stream: bool,
**kwargs: Any,
) -> Dict[str, Any]:
) -> Any:
"""
Prepare the OCI chat request from LangChain messages.

Expand Down Expand Up @@ -1299,8 +1298,8 @@ def with_structured_output(
tool_name = getattr(self._provider.convert_to_oci_tool(schema), "name")
if is_pydantic_schema:
output_parser: OutputParserLike = PydanticToolsParser(
tools=[schema], # type: ignore[list-item]
first_tool_only=True, # type: ignore[list-item]
tools=[schema],
first_tool_only=True,
)
else:
output_parser = JsonOutputKeyToolsParser(
Expand All @@ -1309,15 +1308,15 @@ def with_structured_output(
elif method == "json_mode":
llm = self.bind(response_format={"type": "JSON_OBJECT"})
output_parser = (
PydanticOutputParser(pydantic_object=schema) # type: ignore[type-var, arg-type]
PydanticOutputParser(pydantic_object=schema)
if is_pydantic_schema
else JsonOutputParser()
)
elif method == "json_schema":
json_schema_dict = (
json_schema_dict: Dict[str, Any] = (
schema.model_json_schema() # type: ignore[union-attr]
if is_pydantic_schema
else schema
else schema # type: ignore[assignment]
)

response_json_schema = self._provider.oci_response_json_schema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,9 @@ def _completion_with_retry(**kwargs: Any) -> Any:
response.raise_for_status()
return response
except requests.exceptions.HTTPError as http_err:
if response.status_code == 401 and self._refresh_signer():
raise TokenExpiredError() from http_err
else:
raise ValueError(
f"Server error: {str(http_err)}. Message: {response.text}"
) from http_err
raise ValueError(
f"Server error: {str(http_err)}. Message: {response.text}"
) from http_err
except Exception as e:
raise ValueError(f"Error occurs by inference endpoint: {str(e)}") from e

Expand Down
2 changes: 1 addition & 1 deletion libs/oci/langchain_oci/embeddings/oci_generative_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def validate_environment(cls, values: Dict) -> Dict: # pylint: disable=no-self-
client_kwargs.pop("signer", None)
elif values["auth_type"] == OCIAuthType(2).name:

def make_security_token_signer(oci_config): # type: ignore[no-untyped-def]
def make_security_token_signer(oci_config):
pk = oci.signer.load_private_key_from_file(
oci_config.get("key_file"), None
)
Expand Down
2 changes: 1 addition & 1 deletion libs/oci/langchain_oci/llms/oci_generative_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def validate_environment(cls, values: Dict) -> Dict:
client_kwargs.pop("signer", None)
elif values["auth_type"] == OCIAuthType(2).name:

def make_security_token_signer(oci_config): # type: ignore[no-untyped-def]
def make_security_token_signer(oci_config):
pk = oci.signer.load_private_key_from_file(
oci_config.get("key_file"), None
)
Expand Down
34 changes: 20 additions & 14 deletions libs/oci/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,26 @@ ignore = [
]

[tool.mypy]
ignore_missing_imports = "True"

# Disable specific error codes that are causing issues
disallow_untyped_defs = "False"
disable_error_code = ["attr-defined", "assignment", "var-annotated", "override", "union-attr", "arg-type"]

# TODO: LangChain Google settings
# plugins = ["pydantic.mypy"]
# strict = true
# disallow_untyped_defs = true

# # TODO: activate for 'strict' checking
# disallow_any_generics = false
# warn_return_any = false
plugins = ["pydantic.mypy"]
check_untyped_defs = true
error_summary = false
pretty = true
show_column_numbers = true
show_error_codes = true
show_error_context = true
warn_redundant_casts = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true

# Ignore missing imports only for specific untyped packages
[[tool.mypy.overrides]]
module = [
"oci.*",
"ads.*",
"langchain_openai.*",
]
ignore_missing_imports = true

[tool.coverage.run]
omit = ["tests/*"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, json_data: Dict, status_code: int = 200):
def raise_for_status(self) -> None:
"""Mocked raise for status."""
if 400 <= self.status_code < 600:
raise HTTPError() # type: ignore[call-arg]
raise HTTPError(response=self) # type: ignore[arg-type]

def json(self) -> Dict:
"""Returns mocked json data."""
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_stream_vllm(*args: Any) -> None:
if output is None:
output = chunk
else:
output += chunk
output += chunk # type: ignore[assignment]
count += 1
assert count == 5
assert output is not None
Expand Down
Loading