MCPcopy
hub / github.com/langroid/langroid / _get_cache_key

Function _get_cache_key

langroid/language_models/client_cache.py:27–48  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

25
26
27def _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
51def _get_cached_client(cache_key: str) -> Optional[Any]:

Callers 6

get_openai_clientFunction · 0.85
get_async_openai_clientFunction · 0.85
get_groq_clientFunction · 0.85
get_async_groq_clientFunction · 0.85
get_cerebras_clientFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…