Skip to content

Commit

Permalink
Merge pull request #2574 from hlohaus/16Jan
Browse files Browse the repository at this point in the history
Add missing webview requirements
  • Loading branch information
hlohaus authored Jan 15, 2025
2 parents 55d6709 + 78fa745 commit a73c33f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
11 changes: 3 additions & 8 deletions g4f/gui/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,9 @@ def _prepare_conversation_kwargs(self, json_data: dict, kwargs: dict):
},
"type": "function"
}]
do_web_search = json_data.get('web_search')
if do_web_search and provider:
kwargs["tool_calls"].append({
"function": {
"name": "safe_search_tool"
},
"type": "function"
})
web_search = json_data.get('web_search')
if web_search:
kwargs["web_search"] = web_search
action = json_data.get('action')
if action == "continue":
kwargs["tool_calls"].append({
Expand Down
12 changes: 8 additions & 4 deletions g4f/tools/run_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def validate_arguments(data: dict) -> dict:

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'):
web_search = kwargs.get('web_search')
if web_search:
try:
messages = messages.copy()
messages[-1]["content"] = await do_search(messages[-1]["content"])
web_search = web_search if isinstance(web_search, str) and web_search != "true" else None
messages[-1]["content"] = await do_search(messages[-1]["content"], web_search)
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
Expand Down Expand Up @@ -78,10 +80,12 @@ def iter_run_tools(
**kwargs
) -> AsyncIterator:
# Handle web_search from kwargs
if kwargs.get('web_search'):
web_search = kwargs.get('web_search')
if web_search:
try:
messages = messages.copy()
messages[-1]["content"] = asyncio.run(do_search(messages[-1]["content"]))
web_search = web_search if isinstance(web_search, str) and web_search != "true" else None
messages[-1]["content"] = asyncio.run(do_search(messages[-1]["content"], web_search))
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
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ brotli
beautifulsoup4
aiohttp_socks
pywebview
plyer
setuptools
cryptography
nodriver
python-multipart
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"uvicorn", # api
"nodriver",
"python-multipart",
"pywebview",
"plyer",
"setuptools",
"pypdf2", # files
"docx",
"odfpy",
Expand Down

0 comments on commit a73c33f

Please sign in to comment.