Generate a cache key from client type and configuration parameters. Uses the same approach as OpenAIGPT._cache_lookup for consistency. Args: client_type: Type of client (e.g., "openai", "groq", "cerebras") **kwargs: Configuration parameters (api_key, base_url, timeout,
(client_type: str, **kwargs: Any)
| 25 | |
| 26 | |
| 27 | def _get_cache_key(client_type: str, **kwargs: Any) -> str: |
| 28 | """ |
| 29 | Generate a cache key from client type and configuration parameters. |
| 30 | Uses the same approach as OpenAIGPT._cache_lookup for consistency. |
| 31 | |
| 32 | Args: |
| 33 | client_type: Type of client (e.g., "openai", "groq", "cerebras") |
| 34 | **kwargs: Configuration parameters (api_key, base_url, timeout, etc.) |
| 35 | |
| 36 | Returns: |
| 37 | SHA256 hash of the configuration as a hex string |
| 38 | """ |
| 39 | # Convert kwargs to sorted string representation |
| 40 | sorted_kwargs_str = str(sorted(kwargs.items())) |
| 41 | |
| 42 | # Create raw key combining client type and sorted kwargs |
| 43 | raw_key = f"{client_type}:{sorted_kwargs_str}" |
| 44 | |
| 45 | # Hash the key for consistent length and to handle complex objects |
| 46 | hashed_key = hashlib.sha256(raw_key.encode()).hexdigest() |
| 47 | |
| 48 | return hashed_key |
| 49 | |
| 50 | |
| 51 | def _get_cached_client(cache_key: str) -> Optional[Any]: |
no outgoing calls
no test coverage detected
searching dependent graphs…