-
-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Path and PathLike support when uploading images (#2514)
* Add Path and PathLike support when uploading images Improve raise_for_status in special cases Move ImageResponse to providers.response module Improve OpenaiChat and OpenaiAccount providers Add Sources for web_search in OpenaiChat Add JsonConversation for import and export conversations to js Add RequestLogin response type Add TitleGeneration support in OpenaiChat and gui * Improve Docker Container Guide in README.md * Add tool calls api support, add search tool support
- Loading branch information
Showing
34 changed files
with
931 additions
and
1,329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
import unittest | ||
|
||
try: | ||
from duckduckgo_search import DDGS | ||
from duckduckgo_search.exceptions import DuckDuckGoSearchException | ||
from bs4 import BeautifulSoup | ||
has_requirements = True | ||
except ImportError: | ||
has_requirements = False | ||
|
||
from g4f.client import AsyncClient | ||
from .mocks import YieldProviderMock | ||
|
||
DEFAULT_MESSAGES = [{'role': 'user', 'content': 'Hello'}] | ||
|
||
class TestIterListProvider(unittest.IsolatedAsyncioTestCase): | ||
def setUp(self) -> None: | ||
if not has_requirements: | ||
self.skipTest('web search requirements not passed') | ||
|
||
async def test_search(self): | ||
client = AsyncClient(provider=YieldProviderMock) | ||
tool_calls = [ | ||
{ | ||
"function": { | ||
"arguments": { | ||
"query": "search query", # content of last message: messages[-1]["content"] | ||
"max_results": 5, # maximum number of search results | ||
"max_words": 500, # maximum number of used words from search results for generating the response | ||
"backend": "html", # or "lite", "api": change it to pypass rate limits | ||
"add_text": True, # do scraping websites | ||
"timeout": 5, # in seconds for scraping websites | ||
"region": "wt-wt", | ||
"instructions": "Using the provided web search results, to write a comprehensive reply to the user request.\n" | ||
"Make sure to add the sources of cites using [[Number]](Url) notation after the reference. Example: [[0]](http://google.com)", | ||
}, | ||
"name": "search_tool" | ||
}, | ||
"type": "function" | ||
} | ||
] | ||
try: | ||
response = await client.chat.completions.create([{"content": "", "role": "user"}], "", tool_calls=tool_calls) | ||
self.assertIn("Using the provided web search results", response.choices[0].message.content) | ||
except DuckDuckGoSearchException as e: | ||
self.skipTest(f'DuckDuckGoSearchException: {e}') | ||
|
||
async def test_search2(self): | ||
client = AsyncClient(provider=YieldProviderMock) | ||
tool_calls = [ | ||
{ | ||
"function": { | ||
"arguments": { | ||
"query": "search query", | ||
}, | ||
"name": "search_tool" | ||
}, | ||
"type": "function" | ||
} | ||
] | ||
try: | ||
response = await client.chat.completions.create([{"content": "", "role": "user"}], "", tool_calls=tool_calls) | ||
self.assertIn("Using the provided web search results", response.choices[0].message.content) | ||
except DuckDuckGoSearchException as e: | ||
self.skipTest(f'DuckDuckGoSearchException: {e}') | ||
|
||
async def test_search3(self): | ||
client = AsyncClient(provider=YieldProviderMock) | ||
tool_calls = [ | ||
{ | ||
"function": { | ||
"arguments": json.dumps({ | ||
"query": "search query", # content of last message: messages[-1]["content"] | ||
"max_results": 5, # maximum number of search results | ||
"max_words": 500, # maximum number of used words from search results for generating the response | ||
}), | ||
"name": "search_tool" | ||
}, | ||
"type": "function" | ||
} | ||
] | ||
try: | ||
response = await client.chat.completions.create([{"content": "", "role": "user"}], "", tool_calls=tool_calls) | ||
self.assertIn("Using the provided web search results", response.choices[0].message.content) | ||
except DuckDuckGoSearchException as e: | ||
self.skipTest(f'DuckDuckGoSearchException: {e}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.