Skip to content

Commit bde0456

Browse files
committed
fix web search tool
1 parent db6eeef commit bde0456

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/cleanlab_tlm/utils/chat.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -755,32 +755,14 @@ def _responses_messages_to_string(messages: list[dict[str, Any]]) -> str:
755755
)
756756

757757
if message["action"]["type"] == "search":
758-
if "annotations" in message:
759-
annotations = message["annotations"]
760-
else:
761-
next_text_message = adjusted_messages[i + 1]
762-
if next_text_message["type"] != "message":
763-
continue
764-
next_text_content = next_text_message["content"][0]
765-
if next_text_content["type"] != "output_text":
766-
continue
767-
annotations = next_text_content["annotations"]
768-
769-
urls = list(
770-
{
771-
(annotation["url"], annotation["title"])
772-
for annotation in annotations
773-
if annotation["type"] == "url_citation"
774-
}
775-
)
758+
urls = list({source["url"] for source in message["action"]["sources"] if source["type"] == "url"})
776759

777760
with ThreadPoolExecutor() as executor:
778761

779-
def extract_text(pair: tuple[str, str]) -> str:
762+
def extract_text(url: str) -> str:
780763
fallback_text = "Response is not shown, but the LLM can still access it. Assume that whatever the LLM references in this URL is true."
781764

782765
try:
783-
url = pair[0]
784766
if url in _url_cache:
785767
return _url_cache[url]
786768

@@ -814,10 +796,9 @@ def extract_text(pair: tuple[str, str]) -> str:
814796
websites = [
815797
{
816798
"url": url,
817-
"title": title,
818799
"content": data,
819800
}
820-
for (url, title), data in zip(urls, requests)
801+
for url, data in zip(urls, requests)
821802
]
822803

823804
tool_call = {

tests/test_chat.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
from openai.types.responses.response_function_web_search import (
1313
ActionSearch,
14+
ActionSearchSource,
1415
ResponseFunctionWebSearch,
1516
)
1617
from openai.types.responses.response_output_message import ResponseOutputMessage
@@ -1308,6 +1309,12 @@ def test_form_prompt_string_responses_web_search() -> None:
13081309
action=ActionSearch(
13091310
query="Give me a positive news story from today",
13101311
type="search",
1312+
sources=[
1313+
ActionSearchSource(
1314+
type="url",
1315+
url="https://www.podego.com/insights/august-2025-good-news-ai-pfas-stories?utm_source=openai",
1316+
),
1317+
],
13111318
),
13121319
status="completed",
13131320
type="web_search_call",
@@ -1394,7 +1401,6 @@ def test_form_prompt_string_responses_web_search() -> None:
13941401
"output": [
13951402
{
13961403
"url": "https://www.podego.com/insights/august-2025-good-news-ai-pfas-stories?utm_source=openai",
1397-
"title": "Positive News Highlights | AI, PFAS Breakthroughs & More \\u2014 August 2025 \\u2014 Podego",
13981404
"content": "MOCK CONTENT"
13991405
}
14001406
]
@@ -2342,6 +2348,12 @@ def test_form_response_string_responses_web_search() -> None:
23422348
action=ActionSearch(
23432349
query="Give me a positive news story from today",
23442350
type="search",
2351+
sources=[
2352+
ActionSearchSource(
2353+
type="url",
2354+
url="https://www.podego.com/insights/august-2025-good-news-ai-pfas-stories?utm_source=openai",
2355+
),
2356+
],
23452357
),
23462358
status="completed",
23472359
type="web_search_call",

0 commit comments

Comments
 (0)