types.py 1021 B

123456789101112131415161718192021222324252627282930313233
  1. from __future__ import annotations
  2. import os
  3. from .stubs import ChatCompletion, ChatCompletionChunk
  4. from ..providers.types import BaseProvider
  5. from typing import Union, Iterator, AsyncIterator
  6. ImageProvider = Union[BaseProvider, object]
  7. Proxies = Union[dict, str]
  8. IterResponse = Iterator[Union[ChatCompletion, ChatCompletionChunk]]
  9. AsyncIterResponse = AsyncIterator[Union[ChatCompletion, ChatCompletionChunk]]
  10. class Client():
  11. def __init__(
  12. self,
  13. api_key: str = None,
  14. proxies: Proxies = None,
  15. **kwargs
  16. ) -> None:
  17. self.api_key: str = api_key
  18. self.proxies= proxies
  19. self.proxy: str = self.get_proxy()
  20. def get_proxy(self) -> Union[str, None]:
  21. if isinstance(self.proxies, str):
  22. return self.proxies
  23. elif self.proxies is None:
  24. return os.environ.get("G4F_PROXY")
  25. elif "all" in self.proxies:
  26. return self.proxies["all"]
  27. elif "https" in self.proxies:
  28. return self.proxies["https"]