Skip to content

Commit 47d4a87

Browse files
Remove extra noqa:E501 and split long strings
Split long error messages and test strings across multiple lines to improve readability and remove unnecessary noqa: E501 comments. Also reformatted SQL condition string construction in oraclevs.py for better clarity.
1 parent 55c9ecb commit 47d4a87

File tree

8 files changed

+45
-30
lines changed

8 files changed

+45
-30
lines changed

libs/oci/langchain_oci/chat_models/oci_generative_ai.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ def process_tool_choice(
534534
"""Cohere does not support tool choices."""
535535
if tool_choice is not None:
536536
raise ValueError(
537-
"Tool choice is not supported for Cohere models.Please remove the tool_choice parameter." # noqa: E501
537+
"Tool choice is not supported for Cohere models."
538+
"Please remove the tool_choice parameter."
538539
)
539540
return None
540541

@@ -998,7 +999,8 @@ def process_tool_choice(
998999
# For Meta, we use ToolChoiceAuto for tool selection
9991000
return self.oci_tool_choice_auto()
10001001
raise ValueError(
1001-
f"Unrecognized tool_choice type. Expected str, bool or dict. Received: {tool_choice}" # noqa: E501
1002+
f"Unrecognized tool_choice type. Expected str, bool or dict. "
1003+
f"Received: {tool_choice}"
10021004
)
10031005

10041006
def process_stream_tool_calls(
@@ -1151,7 +1153,8 @@ def _prepare_request(
11511153

11521154
except ImportError as ex:
11531155
raise ModuleNotFoundError(
1154-
"Could not import oci python package. Please make sure you have the oci package installed." # noqa: E501
1156+
"Could not import oci python package. "
1157+
"Please make sure you have the oci package installed."
11551158
) from ex
11561159

11571160
oci_params = self._provider.messages_to_oci_params(

libs/oci/langchain_oci/embeddings/oci_data_science_model_deployment_endpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def validate_environment( # pylint: disable=no-self-argument
7272

7373
except ImportError as ex:
7474
raise ImportError(
75-
"Could not import ads python package. Please install it with `pip install oracle_ads`." # noqa: E501
75+
"Could not import ads python package. "
76+
"Please install it with `pip install oracle_ads`."
7677
) from ex
7778
if not values.get("auth", None):
7879
values["auth"] = ads.common.auth.default_signer()

libs/oci/langchain_oci/embeddings/oci_generative_ai.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def make_security_token_signer(oci_config): # type: ignore[no-untyped-def]
159159

160160
except ImportError as ex:
161161
raise ImportError(
162-
"Could not import oci python package. Please make sure you have the oci package installed." # noqa: E501
162+
"Could not import oci python package. "
163+
"Please make sure you have the oci package installed."
163164
) from ex
164165
except Exception as e:
165166
raise ValueError(

libs/oci/langchain_oci/llms/oci_data_science_model_deployment_endpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def validate_environment(cls, values: Dict) -> Dict:
9797

9898
except ImportError as ex:
9999
raise ImportError(
100-
"Could not import ads python package. Please install it with `pip install oracle_ads`." # noqa: E501
100+
"Could not import ads python package. "
101+
"Please install it with `pip install oracle_ads`."
101102
) from ex
102103

103104
if not values.get("auth", None):

libs/oci/langchain_oci/llms/oci_generative_ai.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def make_security_token_signer(oci_config): # type: ignore[no-untyped-def]
178178
)
179179
else:
180180
raise ValueError(
181-
f"Please provide valid value to auth_type, {values['auth_type']} is not valid." # noqa: E501
181+
"Please provide valid value to auth_type, "
182+
f"{values['auth_type']} is not valid."
182183
)
183184

184185
values["client"] = oci.generative_ai_inference.GenerativeAiInferenceClient(
@@ -187,7 +188,8 @@ def make_security_token_signer(oci_config): # type: ignore[no-untyped-def]
187188

188189
except ImportError as ex:
189190
raise ModuleNotFoundError(
190-
"Could not import oci python package. Please make sure you have the oci package installed." # noqa: E501
191+
"Could not import oci python package. "
192+
"Please make sure you have the oci package installed."
191193
) from ex
192194
except Exception as e:
193195
raise ValueError(

libs/oci/tests/integration_tests/chat_models/test_tool_calling.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ def test_tool_calling_no_infinite_loop(model_id: str, weather_tool: StructuredTo
147147
agent = create_agent(model_id, weather_tool)
148148

149149
# Invoke the agent
150-
system_msg = "You are a helpful assistant. Use the available tools when needed to answer questions accurately." # noqa: E501
150+
system_msg = (
151+
"You are a helpful assistant. Use the available tools when "
152+
"needed to answer questions accurately."
153+
)
151154
result = agent.invoke(
152155
{
153156
"messages": [
@@ -175,13 +178,13 @@ def test_tool_calling_no_infinite_loop(model_id: str, weather_tool: StructuredTo
175178
type(msg).__name__ == "AIMessage"
176179
and hasattr(msg, "tool_calls")
177180
and msg.tool_calls
178-
) # noqa: E501
181+
)
179182
]
180183
# The model should call the tool, but after receiving results,
181184
# should not call again. Allow flexibility - some models might make
182185
# 1 call, others might need 2, but should stop
183186
error_msg = (
184-
f"Model made too many tool calls ({len(ai_tool_calls)}), possible infinite loop" # noqa: E501
187+
f"Model made too many tool calls ({len(ai_tool_calls)}), possible infinite loop"
185188
)
186189
assert len(ai_tool_calls) <= 2, error_msg
187190

@@ -450,7 +453,7 @@ def should_continue(state: MessagesState):
450453
type(msg).__name__ == "AIMessage"
451454
and hasattr(msg, "tool_calls")
452455
and msg.tool_calls
453-
) # noqa: E501
456+
)
454457
]
455458
tool_result_messages = [
456459
msg for msg in messages if type(msg).__name__ == "ToolMessage"
@@ -464,7 +467,8 @@ def should_continue(state: MessagesState):
464467
# The agent should stop at or before the limit (8 tool calls)
465468
# This is the key protection against infinite loops
466469
assert len(tool_call_messages) <= 8, (
467-
f"Too many tool calls ({len(tool_call_messages)}), max_sequential_tool_calls limit not enforced" # noqa: E501
470+
f"Too many tool calls ({len(tool_call_messages)}), "
471+
"max_sequential_tool_calls limit not enforced"
468472
)
469473

470474
# Verify tool results were received

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def mocked_response(*args, **kwargs): # type: ignore[no-untyped-def]
192192
{
193193
"type": "FUNCTION",
194194
"id": "call_456",
195-
"name": "get_weather", # noqa: E501
195+
"name": "get_weather",
196196
"arguments": '{"location": "San Francisco"}', # noqa: E501
197197
"attribute_map": {
198198
"id": "id",
@@ -330,7 +330,7 @@ def get_weather(location: str) -> str:
330330
# Test that tool choice raises ValueError
331331
with pytest.raises(
332332
ValueError, match="Tool choice is not supported for Cohere models"
333-
): # noqa: E501
333+
):
334334
llm.bind_tools(
335335
tools=[get_weather],
336336
tool_choice="auto",
@@ -585,7 +585,7 @@ def test_auth_file_location(monkeypatch: MonkeyPatch) -> None:
585585
with patch("oci.config.from_file") as mock_from_file:
586586
with patch(
587587
"oci.generative_ai_inference.generative_ai_inference_client.validate_config"
588-
): # noqa: E501
588+
):
589589
with patch("oci.base_client.validate_config"):
590590
with patch("oci.signer.load_private_key"):
591591
custom_config_path = "/custom/path/config"
@@ -595,7 +595,7 @@ def test_auth_file_location(monkeypatch: MonkeyPatch) -> None:
595595
)
596596
mock_from_file.assert_called_once_with(
597597
file_location=custom_config_path, profile_name="DEFAULT"
598-
) # noqa: E501
598+
)
599599

600600

601601
@pytest.mark.requires("oci")
@@ -643,7 +643,7 @@ def mocked_response(*args, **kwargs): # type: ignore[no-untyped-def]
643643
# Test with include_raw=True
644644
structured_llm = llm.with_structured_output(
645645
WeatherResponse, method="json_schema", include_raw=True
646-
) # noqa: E501
646+
)
647647
response = structured_llm.invoke(messages)
648648
assert isinstance(response, dict)
649649
assert "parsed" in response
@@ -694,7 +694,7 @@ def mocked_response(*args, **kwargs): # type: ignore[no-untyped-def]
694694
{
695695
"text": (
696696
"I'll help you."
697-
), # noqa: E501
697+
),
698698
"type": "TEXT",
699699
}
700700
)
@@ -767,7 +767,7 @@ def mocked_response(*args, **kwargs): # type: ignore[no-untyped-def]
767767
{
768768
"text": (
769769
"I'll help you."
770-
), # noqa: E501
770+
),
771771
"type": "TEXT",
772772
}
773773
)
@@ -829,7 +829,7 @@ def test_get_provider():
829829

830830

831831
@pytest.mark.requires("oci")
832-
def test_tool_choice_none_after_tool_results() -> None: # noqa: E501
832+
def test_tool_choice_none_after_tool_results() -> None:
833833
"""Test tool_choice='none' when max_sequential_tool_calls is exceeded.
834834
835835
This prevents infinite loops with Meta Llama models by limiting the number
@@ -865,28 +865,28 @@ def get_weather(city: str) -> str:
865865
tool_calls=[
866866
{"id": "call_1", "name": "get_weather", "args": {"city": "Chicago"}}
867867
],
868-
), # noqa: E501
868+
),
869869
ToolMessage(content="Sunny, 65°F", tool_call_id="call_1"),
870870
AIMessage(
871871
content="",
872872
tool_calls=[
873873
{"id": "call_2", "name": "get_weather", "args": {"city": "New York"}}
874874
],
875-
), # noqa: E501
875+
),
876876
ToolMessage(content="Rainy, 55°F", tool_call_id="call_2"),
877877
AIMessage(
878878
content="",
879879
tool_calls=[
880880
{"id": "call_3", "name": "get_weather", "args": {"city": "Seattle"}}
881881
],
882-
), # noqa: E501
882+
),
883883
ToolMessage(content="Cloudy, 60°F", tool_call_id="call_3"),
884884
]
885885

886886
# Prepare the request - need to pass tools from the bound model kwargs
887887
request = llm_with_tools._prepare_request(
888888
messages, stop=None, stream=False, **llm_with_tools.kwargs
889-
) # noqa: E501
889+
)
890890

891891
# Verify that tool_choice is set to 'none' because limit was reached
892892
assert hasattr(request.chat_request, "tool_choice")

libs/oracledb/langchain_oracledb/vectorstores/oraclevs.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,21 @@ def _generate_condition(
279279
bind_variables.append(json.dumps(v))
280280

281281
all_conditions.append(
282-
f"JSON_EQUAL( JSON_QUERY(metadata, '$.{metadata_key}' ), "
283-
f"JSON(:value{bind_l}))"
282+
f"JSON_EQUAL("
283+
f" JSON_QUERY(metadata, '$.{metadata_key}' ),"
284+
f" JSON(:value{bind_l})"
285+
")"
284286
)
285287

286288
elif k == "$ne":
287289
bind_l = len(bind_variables)
288290
bind_variables.append(json.dumps(v))
289291

290292
all_conditions.append(
291-
f"NOT (JSON_EQUAL( "
292-
f"JSON_QUERY(metadata, '$.{metadata_key}' ), "
293-
f"JSON(:value{bind_l})))"
293+
f"NOT (JSON_EQUAL("
294+
f" JSON_QUERY(metadata, '$.{metadata_key}' ),"
295+
f" JSON(:value{bind_l})"
296+
"))"
294297
)
295298

296299
res = " AND ".join(all_conditions)

0 commit comments

Comments
 (0)