Utils Module#

class isek.utils.log.InfoOnlyFilter(name='')[source]#

Bases: Filter

filter(record)[source]#

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

class isek.utils.log.LoggerManager(*args, **kwargs)[source]#

Bases: object

classmethod debug_mode(level='DEBUG')[source]#
static get_logger()[source]#
classmethod plain_mode(level='INFO')[source]#
isek.utils.tools.dict_md5(dict_content: Dict[str, Any], exclude_fields: List[str] | None = None) str[source]#

Computes the MD5 hash of a dictionary's content.

The dictionary is first serialized to a JSON string with sorted keys (to ensure consistent hashing regardless of initial key order) and ensure_ascii=False (to handle non-ASCII characters correctly). Specified fields can be excluded from the hashing process.

Parameters:
  • dict_content (Dict[str, Any]) -- The dictionary whose content is to be hashed.

  • exclude_fields (Optional[List[str]]) -- An optional list of field names (keys) to exclude from the dictionary before generating the hash. Defaults to None (no fields excluded).

Returns:

The hexadecimal MD5 hash string of the dictionary's content.

Return type:

str

isek.utils.tools.function_to_schema(func: Callable[[...], Any]) Dict[str, Any][source]#

Converts a Python function into an LLM-compatible tool schema.

This schema typically follows a format similar to OpenAI's function calling schema, detailing the function's name, description (from its docstring), and parameters (derived from its signature and type annotations).

Supported Python types for parameters are mapped to JSON schema types: str -> "string", int -> "integer", float -> "number", bool -> "boolean", list -> "array", dict -> "object", NoneType -> "null". Unannotated parameters or parameters with unsupported annotations default to "string".

Parameter descriptions are basic and include type and default value if present.

Parameters:

func (Callable[..., Any]) -- The callable function to convert. It should ideally have type hints for its parameters and a docstring for its description.

Returns:

A dictionary representing the tool schema.

Return type:

FunctionSchema

Raises:

ValueError -- If the function signature cannot be inspected (e.g., for some built-ins) or if a parameter's type annotation is of a type that cannot be directly mapped and is not a common built-in.

isek.utils.tools.load_json_from_chat_response(chat_result: str) str | int | float | bool | None | Dict[str, Any] | List[Any][source]#

Extracts and parses JSON data from a chat response string.

It looks for JSON content enclosed in markdown-style code blocks (e.g., `json ... `).

Parameters:

chat_result (str) -- The string chat response, potentially containing JSON.

Returns:

The parsed JSON data (dictionary or list).

Return type:

JsonType

Raises:
isek.utils.tools.md5(source: str) str[source]#

Computes the MD5 hash of a given string.

The input string is encoded to UTF-8 before hashing.

Parameters:

source (str) -- The string to hash.

Returns:

The hexadecimal MD5 hash string.

Return type:

str

isek.utils.tools.split_list(input_list: List[Any], chunk_size: int) List[List[Any]][source]#

Splits a list into smaller chunks of a specified maximum size.

Parameters:
  • input_list (List[Any]) -- The list to be split.

  • chunk_size (int) -- The maximum size of each chunk. Must be a positive integer.

Returns:

A list of lists, where each inner list is a chunk.

Return type:

List[List[Any]]

Raises:

ValueError -- If chunk_size is not a positive integer.