mocks.py 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from g4f.providers.base_provider import AbstractProvider, AsyncProvider, AsyncGeneratorProvider
  2. class ProviderMock(AbstractProvider):
  3. working = True
  4. def create_completion(
  5. model, messages, stream, **kwargs
  6. ):
  7. yield "Mock"
  8. class AsyncProviderMock(AsyncProvider):
  9. working = True
  10. async def create_async(
  11. model, messages, **kwargs
  12. ):
  13. return "Mock"
  14. class AsyncGeneratorProviderMock(AsyncGeneratorProvider):
  15. working = True
  16. async def create_async_generator(
  17. model, messages, stream, **kwargs
  18. ):
  19. yield "Mock"
  20. class ModelProviderMock(AbstractProvider):
  21. working = True
  22. def create_completion(
  23. model, messages, stream, **kwargs
  24. ):
  25. yield model
  26. class YieldProviderMock(AsyncGeneratorProvider):
  27. working = True
  28. async def create_async_generator(
  29. model, messages, stream, **kwargs
  30. ):
  31. for message in messages:
  32. yield message["content"]