From 1b116d2ecacb25f5085a1b1bcafbd4c445a0cb64 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 May 2026 12:54:15 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../core/inference/external_provider.py | 27 ++++++++++++------- .../test_openai_tool_result_fallbacks.py | 6 ++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/studio/backend/core/inference/external_provider.py b/studio/backend/core/inference/external_provider.py index 2e0c5e6256..64e142d5f0 100644 --- a/studio/backend/core/inference/external_provider.py +++ b/studio/backend/core/inference/external_provider.py @@ -276,9 +276,7 @@ def _extract_web_search_action(item: dict[str, Any]) -> dict[str, Any]: return out -def _format_web_search_per_call_sources( - results: Any, sources: Any -) -> str: +def _format_web_search_per_call_sources(results: Any, sources: Any) -> str: """Format per-call sources as the Title/URL/Snippet block the frontend's parseSearchResults expects. Prefers `results` (snippet bearing, reasoning models) then `action.sources` (urls only). @@ -3583,7 +3581,12 @@ class ExternalProviderClient: if isinstance(entry, str) and entry: parts.append(entry) continue - stdout = entry.get("stdout") or entry.get("text") or entry.get("content") or "" + stdout = ( + entry.get("stdout") + or entry.get("text") + or entry.get("content") + or "" + ) stderr = entry.get("stderr") or "" outcome = entry.get("outcome") or {} chunk_parts: list[str] = [] @@ -3603,7 +3606,7 @@ class ExternalProviderClient: # Unknown shape: surface the raw dict so the # user can see what OpenAI actually returned. try: - chunk_parts.append(_json.dumps(entry, indent=2)) + chunk_parts.append(_json.dumps(entry, indent = 2)) except (TypeError, ValueError): pass if chunk_parts: @@ -3982,16 +3985,22 @@ class ExternalProviderClient: # as the Title/URL/Snippet block the frontend # parser already understands. action_obj = ( - item.get("action") if isinstance(item.get("action"), dict) else {} + item.get("action") + if isinstance(item.get("action"), dict) + else {} ) or {} - per_call_sources = _format_web_search_per_call_sources( - item.get("results"), action_obj.get("sources") + per_call_sources = ( + _format_web_search_per_call_sources( + item.get("results"), + action_obj.get("sources"), + ) ) yield _emit_tool_event( { "type": "tool_end", "tool_call_id": item_id, - "result": per_call_sources or _web_search_card_text(args), + "result": per_call_sources + or _web_search_card_text(args), } ) elif item.get("type") == "shell_call": diff --git a/studio/backend/tests/test_openai_tool_result_fallbacks.py b/studio/backend/tests/test_openai_tool_result_fallbacks.py index e9f8f2a308..f80ca22c21 100644 --- a/studio/backend/tests/test_openai_tool_result_fallbacks.py +++ b/studio/backend/tests/test_openai_tool_result_fallbacks.py @@ -284,7 +284,11 @@ def test_web_search_per_call_results_formatted_as_source_blocks(monkeypatch): "id": "ws_r", "action": {"type": "search", "query": "tiger ranking"}, "results": [ - {"url": "https://a.example/1", "title": "Tigers", "snippet": "Big cats"}, + { + "url": "https://a.example/1", + "title": "Tigers", + "snippet": "Big cats", + }, {"url": "https://b.example/2", "title": "Lion stats"}, ], },