ahvn.utils.basic.debug_utils module¶

ahvn.utils.basic.debug_utils.value_match(supported, got, thres=0.3)[source]¶

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

Parameters:
  • 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.

Returns:

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

Only includes values with similarity >= thres.

Return type:

List[Tuple[Any, float]]

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

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

Parameters:
  • 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.

Returns:

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.

Return type:

str

Raises:
  • ValueError – If the value is not in the supported list and the mode is ‘raise’.

  • NotImplementedError – If an unknown mode is provided.

ahvn.utils.basic.debug_utils.error_str(err=None, tb=True)[source]¶

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

Parameters:
  • 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.

Returns:

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

Return type:

str

exception ahvn.utils.basic.debug_utils.FunctionDeserializationError[source]¶

Bases: Exception

exception ahvn.utils.basic.debug_utils.LLMError[source]¶

Bases: Exception

exception ahvn.utils.basic.debug_utils.ToolError[source]¶

Bases: Exception

exception ahvn.utils.basic.debug_utils.DatabaseError[source]¶

Bases: Exception

exception ahvn.utils.basic.debug_utils.AutoFuncError[source]¶

Bases: Exception

exception ahvn.utils.basic.debug_utils.DependencyError[source]¶

Bases: ImportError