gpt4free/etc/unittest/mocks.py
H Lohaus 79c407b939
IterListProvider support for generating images (#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
2024-11-29 13:56:11 +01:00

91 lines
2.2 KiB
Python

from g4f.providers.base_provider import AbstractProvider, AsyncProvider, AsyncGeneratorProvider
from g4f.image import ImageResponse
from g4f.errors import MissingAuthError
class ProviderMock(AbstractProvider):
working = True
def create_completion(
model, messages, stream, **kwargs
):
yield "Mock"
class AsyncProviderMock(AsyncProvider):
working = True
async def create_async(
model, messages, **kwargs
):
return "Mock"
class AsyncGeneratorProviderMock(AsyncGeneratorProvider):
working = True
async def create_async_generator(
model, messages, stream, **kwargs
):
yield "Mock"
class ModelProviderMock(AbstractProvider):
working = True
def create_completion(
model, messages, stream, **kwargs
):
yield model
class YieldProviderMock(AsyncGeneratorProvider):
working = True
async def create_async_generator(
model, messages, stream, **kwargs
):
for message in messages:
yield message["content"]
class YieldImageResponseProviderMock(AsyncGeneratorProvider):
working = True
@classmethod
async def create_async_generator(
cls, model, messages, stream, prompt: str, **kwargs
):
yield ImageResponse(prompt, "")
class MissingAuthProviderMock(AbstractProvider):
working = True
@classmethod
def create_completion(
cls, model, messages, stream, **kwargs
):
raise MissingAuthError(cls.__name__)
yield cls.__name__
class RaiseExceptionProviderMock(AbstractProvider):
working = True
@classmethod
def create_completion(
cls, model, messages, stream, **kwargs
):
raise RuntimeError(cls.__name__)
yield cls.__name__
class AsyncRaiseExceptionProviderMock(AsyncGeneratorProvider):
working = True
@classmethod
async def create_async_generator(
cls, model, messages, stream, **kwargs
):
raise RuntimeError(cls.__name__)
yield cls.__name__
class YieldNoneProviderMock(AsyncGeneratorProvider):
working = True
async def create_async_generator(
model, messages, stream, **kwargs
):
yield None