ahvn.utils.basic.debug_utils module

ahvn.utils.basic.debug_utils.value_match(supported, got, thres=0.3)[源代码]

Find similar values from a list of supported values, returning matches sorted by similarity score.

参数:
  • supported (List[Any]) -- A list of supported values.

  • got (Any) -- The value to match against the supported list.

  • thres (float) -- The minimum similarity threshold. Only matches with similarity >= thres are returned. Defaults to 0.3.

返回:

A list of (value, score) tuples sorted by score descending.

Only includes values with similarity >= thres.

返回类型:

List[Tuple[Any, float]]

ahvn.utils.basic.debug_utils.raise_mismatch(supported, got, name='value', mode='raise', comment=None, thres=0.3)[源代码]

Raise an error if the value is not in the list of supported values, suggesting the closest match.

参数:
  • supported (List[Any]) -- A list of supported values.

  • got (Any) -- The value to check against the supported list.

  • name (str) -- The name of the value for error messages. Defaults to 'value'.

  • mode (Literal['ignore','match','warn','exit','raise']) -- The mode of handling the mismatch. - 'ignore': Do nothing.Directly returns the original value if no close match is found. - 'match': Do nothing. Directly returns the suggestion if a close match is found. - 'warn': Log a warning message. Returns the suggestion if a close match is found. - 'exit': Log an error message and exit the program with status 1. - 'raise': Raise a ValueError with the error message. Defaults to 'raise'.

  • comment (Optional[str]) -- An optional comment to include in the error message. Defaults to None.

  • thres (float) -- The threshold for similarity to consider a suggestion valid. Defaults to 0.3.

返回:

The suggested value if a close match is found and mode is 'warn'. Otherwise, returns None.

If got is in supported, does nothing and returns got.

返回类型:

str

抛出:
ahvn.utils.basic.debug_utils.error_str(err=None, tb=True)[源代码]

Get a string representation of an error, optionally including the traceback.

参数:
  • err (Optional[Exception]) -- The exception to format. If None, returns None.

  • tb (Optional[bool]) -- Whether to include the traceback in the output. Defaults to True.

返回:

The formatted error string. Or None if err is None.

返回类型:

str

exception ahvn.utils.basic.debug_utils.FunctionDeserializationError[源代码]

基类:Exception

exception ahvn.utils.basic.debug_utils.LLMError[源代码]

基类:Exception

exception ahvn.utils.basic.debug_utils.ToolError[源代码]

基类:Exception

exception ahvn.utils.basic.debug_utils.DatabaseError[源代码]

基类:Exception

exception ahvn.utils.basic.debug_utils.AutoFuncError[源代码]

基类:Exception

exception ahvn.utils.basic.debug_utils.DependencyError[源代码]

基类:ImportError