12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 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
|