Update types.py

This commit is contained in:
H Lohaus 2024-04-06 21:15:07 +02:00 committed by GitHub
parent 393be6be6b
commit c9a83e53b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 3 deletions

View File

@ -5,7 +5,18 @@ ImageProvider = Union[BaseProvider, object]
Proxies = Union[dict, str]
IterResponse = Iterator[Union[ChatCompletion, ChatCompletionChunk]]
class Client():
class ClientProxyMixin():
def get_proxy(self) -> Union[str, None]:
if isinstance(self.proxies, str):
return self.proxies
elif self.proxies is None:
return os.environ.get("G4F_PROXY")
elif "all" in self.proxies:
return self.proxies["all"]
elif "https" in self.proxies:
return self.proxies["https"]
class Client(ClientProxyMixin):
def __init__(
self,
api_key: str = None,
@ -16,5 +27,3 @@ class Client():
) -> None:
self.api_key: str = api_key
self.proxies: Proxies = proxies
self.chat: Chat = Chat(self, provider)
self.images: Images = Images(self, image_provider)