forked from xtekky/gpt4free
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IterListProvider support for generating images (xtekky#2441)
* IterListProvider support for generating images * Add missing get_har_files import in Copilot * Fix typo in dall-e-3 model name * Add image client unittests * Add MicrosoftDesigner provider * Import MicrosoftDesigner and add it to the model list
- Loading branch information
Showing
16 changed files
with
392 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
import unittest | ||
|
||
from g4f.client import AsyncClient, ImagesResponse | ||
from g4f.providers.retry_provider import IterListProvider | ||
from .mocks import ( | ||
YieldImageResponseProviderMock, | ||
MissingAuthProviderMock, | ||
AsyncRaiseExceptionProviderMock, | ||
YieldNoneProviderMock | ||
) | ||
|
||
DEFAULT_MESSAGES = [{'role': 'user', 'content': 'Hello'}] | ||
|
||
class TestIterListProvider(unittest.IsolatedAsyncioTestCase): | ||
|
||
async def test_skip_provider(self): | ||
client = AsyncClient(image_provider=IterListProvider([MissingAuthProviderMock, YieldImageResponseProviderMock], False)) | ||
response = await client.images.generate("Hello", "", response_format="orginal") | ||
self.assertIsInstance(response, ImagesResponse) | ||
self.assertEqual("Hello", response.data[0].url) | ||
|
||
async def test_only_one_result(self): | ||
client = AsyncClient(image_provider=IterListProvider([YieldImageResponseProviderMock, YieldImageResponseProviderMock], False)) | ||
response = await client.images.generate("Hello", "", response_format="orginal") | ||
self.assertIsInstance(response, ImagesResponse) | ||
self.assertEqual("Hello", response.data[0].url) | ||
|
||
async def test_skip_none(self): | ||
client = AsyncClient(image_provider=IterListProvider([YieldNoneProviderMock, YieldImageResponseProviderMock], False)) | ||
response = await client.images.generate("Hello", "", response_format="orginal") | ||
self.assertIsInstance(response, ImagesResponse) | ||
self.assertEqual("Hello", response.data[0].url) | ||
|
||
def test_raise_exception(self): | ||
async def run_exception(): | ||
client = AsyncClient(image_provider=IterListProvider([YieldNoneProviderMock, AsyncRaiseExceptionProviderMock], False)) | ||
await client.images.generate("Hello", "") | ||
self.assertRaises(RuntimeError, asyncio.run, run_exception()) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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.