From 51264fe20cda57eff47ac9a386edb3563eac4568 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 23 Feb 2024 11:33:38 +0100 Subject: Add GeminiPro API provider Set min version for undetected-chromedriver Add api_key to the new client --- g4f/client.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'g4f/client.py') 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(): -- cgit v1.2.3