File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed
Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,8 @@ def chat_completion(
124124 f"Retrying in { sleep_time :.2f} s..."
125125 )
126126 time .sleep (sleep_time )
127+ if attempt == self .max_retry - 1 :
128+ raise
127129
128130 return self .get_text_from_all_candidates (response ), cost
129131
@@ -234,12 +236,21 @@ def get_text_from_all_candidates(
234236
235237 return all_texts
236238
237- @functools .lru_cache ()
238- @staticmethod
239- def get_gemini_client (api_key : str ) -> genai .Client :
240- """
241- Create a Gemini client using the provided API key.
242- :param api_key: The API key for authentication.
243- :return: A Gemini client instance.
244- """
245- return genai .Client (api_key = api_key )
239+
240+ # Module-level cache for Gemini clients
241+ _gemini_client_cache : dict = {}
242+
243+
244+ def _get_gemini_client (api_key : str ) -> genai .Client :
245+ """
246+ Create or retrieve a cached Gemini client using the provided API key.
247+ :param api_key: The API key for authentication.
248+ :return: A Gemini client instance.
249+ """
250+ if api_key not in _gemini_client_cache :
251+ _gemini_client_cache [api_key ] = genai .Client (api_key = api_key )
252+ return _gemini_client_cache [api_key ]
253+
254+
255+ # Bind as static method for backward compatibility
256+ GeminiService .get_gemini_client = staticmethod (_get_gemini_client )
You can’t perform that action at this time.
0 commit comments