Provider Updates and Fixes (#2570)

* Update providers, restore old providers, remove non-working providers

* Restoring the original providers

* Restore the original provider g4f/Provider/needs_auth/GeminiPro.py

* Deleted non-working providers, fixed providers

* Update docs/providers-and-models.md g4f/models.py g4f/Provider/hf_space/CohereForAI.py

* Restore g4f/Provider/Airforce.py Updated alias g4f/Provider/hf_space/CohereForAI.py

* Disabled provider 'g4f/Provider/ReplicateHome.py' and moved to 'g4f/Provider/not_working'

* Disconnected provider problem with Pizzagpt response

* Fix for why web_search = True didn't work

* Update docs/client.md

* Fix for why web_search = True did not work in the asychronous and sychronous versions

---------

Co-authored-by: kqlio67 <>
This commit is contained in:
kqlio67 2025-01-15 21:35:05 +00:00 committed by GitHub
parent 3f39890699
commit f105451947
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 637 additions and 728 deletions

View file

@ -28,6 +28,16 @@ def validate_arguments(data: dict) -> dict:
return {}
async def async_iter_run_tools(async_iter_callback, model, messages, tool_calls: Optional[list] = None, **kwargs):
# Handle web_search from kwargs
if kwargs.get('web_search'):
try:
messages = messages.copy()
messages[-1]["content"] = await do_search(messages[-1]["content"])
except Exception as e:
debug.log(f"Couldn't do web search: {e.__class__.__name__}: {e}")
# Keep web_search in kwargs for provider native support
pass
if tool_calls is not None:
for tool in tool_calls:
if tool.get("type") == "function":
@ -67,6 +77,16 @@ def iter_run_tools(
tool_calls: Optional[list] = None,
**kwargs
) -> AsyncIterator:
# Handle web_search from kwargs
if kwargs.get('web_search'):
try:
messages = messages.copy()
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}")
# Keep web_search in kwargs for provider native support
pass
if tool_calls is not None:
for tool in tool_calls:
if tool.get("type") == "function":
@ -77,14 +97,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 +119,4 @@ def iter_run_tools(
if has_bucket and isinstance(messages[-1]["content"], str):
messages[-1]["content"] += BUCKET_INSTRUCTIONS
return iter_callback(model=model, messages=messages, provider=provider, **kwargs)
return iter_callback(model=model, messages=messages, provider=provider, **kwargs)