gen_ai_hub.proxy.core.utils
index
/home/jenkins/agent/workspace/ation_generative-ai-hub-sdk_main/gen_ai_hub/proxy/core/utils.py

 
Modules
       
time
warnings

 
Classes
       
builtins.object
NotGiven
Omit
PredictionURLs

 
class NotGiven(builtins.object)
     Methods defined here:
__bool__(self) -> 'Literal[False]'

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Omit(builtins.object)
     Methods defined here:
__bool__(self) -> 'Literal[False]'

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class PredictionURLs(builtins.object)
    PredictionURLs(suffixes: 'Optional[Dict[str, str]]' = None) -> 'None'
 
Generate prediction URLs with dynamic suffixes for different models.
 
  Methods defined here:
__call__(self, model_name: 'str', url: 'str', fixed_suffix: 'Optional[str]' = None) -> 'str'
Generate a complete URL for a given model.
 
:param model_name: the name of the model.
:type model_name: str
:param url: the base URL.
:type url: str
:param fixed_suffix: A fixed suffix to override the registered one.
:type fixed_suffix: Optional[str], optional
:return: The complete URL for the model. None means there is no suffix registered for the model 
         and usally the url should be used.
:rtype: str
__init__(self, suffixes: 'Optional[Dict[str, str]]' = None) -> 'None'
Initialize the PredictionURLs with optional suffixes.
 
:param suffixes: A dictionary of model names and their corresponding URL suffixes.
:type suffixes: Optional[Dict[str, str]], optional
register(self, suffixes: 'Dict[str, str | Omit]') -> 'None'
Register new model suffixes.
 
:param suffixes: A dictionary of model names and their corresponding URL suffixes.
:type suffixes: Dict[str, str  |  Omit]

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
if_set(value, alternative=<gen_ai_hub.proxy.core.utils.NotGiven object at 0x7f403f71e770>)
Check if a value is set (not NotGiven and not None), otherwise return an alternative.
 
:param value: the value to check.
:type value: any
:param alternative: the alternative value to return if the original value is not set.
:type alternative: any
:return: The original value if set, otherwise the alternative.
:rtype: any
if_str_set(value: 'str', alternative: 'str' = '')
Check if a string value is set (not empty), otherwise return an alternative.
 
:param value: the string value to check.
:type value: str
:param alternative: the alternative string to return if the original value is empty.
:type alternative: str, optional
:return: The original string if not empty, otherwise the alternative.
:rtype: str
kwargs_if_set(**kwargs)
Filter keyword arguments to include only those that are set (not NotGiven and not None).
 
:return: A dictionary of keyword arguments that are set.
:rtype: Dict[str, any]
lru_cache_extended(timeout: 'Optional[int]' = None, maxsize: 'Optional[int]' = None, typed: 'bool' = False, first_arg_self: 'bool' = False)
Decorator to add LRU caching with optional timeout to methods. 
Handles 'self' as a weak reference for instance methods if required.
 
:param timeout: time in seconds after which the cache will be refreshed. If None, never expires.
:type timeout: Optional[int], optional
:param maxsize: maximum size of the cache.
:type maxsize: Optional[int], optional
:param typed: if True, arguments of different types will be cached separately.
:type typed: bool, optional
:param first_arg_self: if True, treats the first argument as 'self' and uses its id for caching.
:type first_arg_self: bool, optional
:return: Decorated method with cache and optional timeout.
:rtype: Callable
warn_once(msg, category=None)
Issue a warning only once for a given message.
 
:param msg: the warning message.
:type msg: str
:param category: the warning category.
:type category: Optional[Warning], optional

 
Data
        Any = typing.Any
Dict = typing.Dict
List = typing.List
Literal = typing.Literal
NOT_GIVEN = <gen_ai_hub.proxy.core.utils.NotGiven object>
OMIT = <gen_ai_hub.proxy.core.utils.Omit object>
Optional = typing.Optional
Tuple = typing.Tuple
annotations = _Feature((3, 7, 0, 'beta', 1), (3, 11, 0, 'alpha', 0), 16777216)