From 023f96f713b8e94b90e1984985b2caa09e3f34ac Mon Sep 17 00:00:00 2001 From: kqlio67 <> Date: Wed, 15 Jan 2025 14:54:52 +0200 Subject: [PATCH] Fix for why web_search = True didn't work --- g4f/tools/run_tools.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/g4f/tools/run_tools.py b/g4f/tools/run_tools.py index f52623e9a56..1006b8f972e 100644 --- a/g4f/tools/run_tools.py +++ b/g4f/tools/run_tools.py @@ -65,8 +65,18 @@ def iter_run_tools( messages: Messages, provider: Optional[str] = None, tool_calls: Optional[list] = None, + web_search: bool = False, **kwargs ) -> AsyncIterator: + # If web_search is True, enable safe search directly + if web_search: + try: + messages[-1]["content"] = asyncio.run(do_search(messages[-1]["content"])) + except Exception as e: + debug.log(f"Couldn't do web search: {e.__class__.__name__}: {e}") + # Enable provider native web search + kwargs["web_search"] = True + if tool_calls is not None: for tool in tool_calls: if tool.get("type") == "function": @@ -77,14 +87,6 @@ def iter_run_tools( raise_search_exceptions=True, **tool["function"]["arguments"] ) - elif tool.get("function", {}).get("name") == "safe_search_tool": - tool["function"]["arguments"] = validate_arguments(tool["function"]) - try: - messages[-1]["content"] = asyncio.run(do_search(messages[-1]["content"], **tool["function"]["arguments"])) - except Exception as e: - debug.log(f"Couldn't do web search: {e.__class__.__name__}: {e}") - # Enable provider native web search - kwargs["web_search"] = True elif tool.get("function", {}).get("name") == "continue_tool": if provider not in ("OpenaiAccount", "HuggingFace"): last_line = messages[-1]["content"].strip().splitlines()[-1] @@ -107,4 +109,4 @@ def on_bucket(match): if has_bucket and isinstance(messages[-1]["content"], str): messages[-1]["content"] += BUCKET_INSTRUCTIONS - return iter_callback(model=model, messages=messages, provider=provider, **kwargs) \ No newline at end of file + return iter_callback(model=model, messages=messages, provider=provider, **kwargs)