diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-02-23 11:33:38 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-02-23 11:33:38 +0100 |
commit | 51264fe20cda57eff47ac9a386edb3563eac4568 (patch) | |
tree | 29233c3c384ebc8cc493e68842aa0dcff499cd49 /g4f/client.py | |
parent | Add missing file (diff) | |
download | gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.gz gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.bz2 gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.lz gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.xz gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.zst gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/client.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/g4f/client.py b/g4f/client.py index 023d53f6..bf2179aa 100644 --- a/g4f/client.py +++ b/g4f/client.py @@ -86,20 +86,19 @@ def iter_append_model_and_provider(response: IterResponse) -> IterResponse: yield chunk class Client(): - proxies: Proxies = None - chat: Chat - images: Images def __init__( self, + api_key: str = None, + proxies: Proxies = None, provider: ProviderType = None, image_provider: ImageProvider = None, - proxies: Proxies = None, **kwargs ) -> None: - self.chat = Chat(self, provider) - self.images = Images(self, image_provider) + self.api_key: str = api_key self.proxies: Proxies = proxies + self.chat: Chat = Chat(self, provider) + self.images: Images = Images(self, image_provider) def get_proxy(self) -> Union[str, None]: if isinstance(self.proxies, str): @@ -125,6 +124,7 @@ class Completions(): response_format: dict = None, max_tokens: int = None, stop: Union[list[str], str] = None, + api_key: str = None, **kwargs ) -> Union[ChatCompletion, Generator[ChatCompletionChunk]]: if max_tokens is not None: @@ -137,9 +137,16 @@ class Completions(): stream, **kwargs ) - response = provider.create_completion(model, messages, stream=stream, proxy=self.client.get_proxy(), **kwargs) stop = [stop] if isinstance(stop, str) else stop - response = iter_append_model_and_provider(iter_response(response, stream, response_format, max_tokens, stop)) + response = provider.create_completion( + model, messages, stream, + proxy=self.client.get_proxy(), + stop=stop, + api_key=self.client.api_key if api_key is None else api_key, + **kwargs + ) + response = iter_response(response, stream, response_format, max_tokens, stop) + response = iter_append_model_and_provider(response) return response if stream else next(response) class Chat(): |