Utils Module#
- 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:
- Returns:
The hexadecimal MD5 hash string of the dictionary's content.
- Return type:
- 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:
RuntimeError -- If no JSON content in the expected format is found.
json.JSONDecodeError -- If the extracted content is not valid JSON.
- 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.