Common
Common utils for all models.
WaldiezBase
¶
Bases: BaseModel
Base model class to inherit from.
It contains the default configuration for all models. It also model_dumps
by alias by default.
model_dump(**kwargs: Any) -> Dict[str, Any]
¶
Dump the model to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Additional keyword arguments. | {} |
Returns:
Type | Description |
---|---|
Dict[str, Any] | The dictionary representation of the model. |
Source code in waldiez/models/common/base.py
model_dump_json(**kwargs: Any) -> str
¶
Dump the model to a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Additional keyword arguments. | {} |
Returns:
Type | Description |
---|---|
str | The JSON string. |
Source code in waldiez/models/common/base.py
ag2_version
¶
Get the autogen version.
get_autogen_version() -> str
cached
¶
Get the autogen version.
Returns:
Type | Description |
---|---|
str | The autogen version. |
Raises:
Type | Description |
---|---|
ValueError | If pyautogen is not installed. |
Source code in waldiez/models/common/ag2_version.py
base
¶
Base class to inherit from.
WaldiezBase
¶
Bases: BaseModel
Base model class to inherit from.
It contains the default configuration for all models. It also model_dumps
by alias by default.
model_dump(**kwargs: Any) -> Dict[str, Any]
¶
Dump the model to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Additional keyword arguments. | {} |
Returns:
Type | Description |
---|---|
Dict[str, Any] | The dictionary representation of the model. |
Source code in waldiez/models/common/base.py
model_dump_json(**kwargs: Any) -> str
¶
Dump the model to a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Additional keyword arguments. | {} |
Returns:
Type | Description |
---|---|
str | The JSON string. |
Source code in waldiez/models/common/base.py
check_function(code_string: str, function_name: str, function_args: List[str]) -> Tuple[bool, str]
¶
Check the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string to check. | required |
function_name | str | The expected method name. | required |
function_args | List[str] | The expected method arguments. | required |
Returns:
Type | Description |
---|---|
Tuple[bool, str] | If valid, True and the function body (only), no extra lines. If invalid, False and the error message. |
Source code in waldiez/models/common/method_utils.py
date_utils
¶
dict_utils
¶
Dictionary related utilities.
update_dict(original: Dict[str, Any]) -> Dict[str, Any]
¶
Try to determine the type of the dictionary values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original | Dict[str, Any] | The original dictionary. | required |
Returns:
Type | Description |
---|---|
Dict[str, Any] | The updated dictionary with values converted to the detected types. |
Source code in waldiez/models/common/dict_utils.py
gather_code_imports(code_string: str, is_interop: bool) -> Tuple[List[str], List[str]]
¶
Gather the imports from the code string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
is_interop | bool | If True, make sure the interoperability import is present. | required |
Returns:
Type | Description |
---|---|
Tuple[List[str], List[str]] | The standard library imports and the third party imports. |
Source code in waldiez/models/common/method_utils.py
generate_function(function_name: str, function_args: List[str], function_types: Tuple[List[str], str], function_body: str, types_as_comments: bool = False) -> str
¶
Generate a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_name | str | The function name. | required |
function_args | List[str] | The function arguments. | required |
function_types | Tuple[List[str], str] | The function types. | required |
function_body | str | The function body. | required |
types_as_comments | bool | Include the type hints as comments (or in the function signature) (default is False). | False |
Returns:
Type | Description |
---|---|
str | The generated function. |
Source code in waldiez/models/common/method_utils.py
get_autogen_version() -> str
cached
¶
Get the autogen version.
Returns:
Type | Description |
---|---|
str | The autogen version. |
Raises:
Type | Description |
---|---|
ValueError | If pyautogen is not installed. |
Source code in waldiez/models/common/ag2_version.py
get_function(code_string: str, function_name: str) -> str
¶
Get the function signature and body.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
function_name | str | The function name. | required |
Returns:
Type | Description |
---|---|
str | The function signature and body. |
Source code in waldiez/models/common/method_utils.py
method_utils
¶
Function related utilities.
check_function(code_string: str, function_name: str, function_args: List[str]) -> Tuple[bool, str]
¶
Check the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string to check. | required |
function_name | str | The expected method name. | required |
function_args | List[str] | The expected method arguments. | required |
Returns:
Type | Description |
---|---|
Tuple[bool, str] | If valid, True and the function body (only), no extra lines. If invalid, False and the error message. |
Source code in waldiez/models/common/method_utils.py
gather_code_imports(code_string: str, is_interop: bool) -> Tuple[List[str], List[str]]
¶
Gather the imports from the code string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
is_interop | bool | If True, make sure the interoperability import is present. | required |
Returns:
Type | Description |
---|---|
Tuple[List[str], List[str]] | The standard library imports and the third party imports. |
Source code in waldiez/models/common/method_utils.py
generate_function(function_name: str, function_args: List[str], function_types: Tuple[List[str], str], function_body: str, types_as_comments: bool = False) -> str
¶
Generate a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_name | str | The function name. | required |
function_args | List[str] | The function arguments. | required |
function_types | Tuple[List[str], str] | The function types. | required |
function_body | str | The function body. | required |
types_as_comments | bool | Include the type hints as comments (or in the function signature) (default is False). | False |
Returns:
Type | Description |
---|---|
str | The generated function. |
Source code in waldiez/models/common/method_utils.py
get_function(code_string: str, function_name: str) -> str
¶
Get the function signature and body.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
function_name | str | The function name. | required |
Returns:
Type | Description |
---|---|
str | The function signature and body. |
Source code in waldiez/models/common/method_utils.py
is_standard_library(module_name: str) -> bool
¶
Check if the module is part of the standard library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name | str | The module name. | required |
Returns:
Type | Description |
---|---|
bool | True if the module is part of the standard library. |
Source code in waldiez/models/common/method_utils.py
parse_code_string(code_string: str) -> Tuple[Optional[str], Optional[ast.Module]]
¶
Parse the code string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
Returns:
Type | Description |
---|---|
Tuple[Optional[str], Optional[Module]] | If valid, None and the ast module. If invalid, the error message and None. |
Source code in waldiez/models/common/method_utils.py
now() -> str
¶
Get the current date and time in UTC.
Returns:
Type | Description |
---|---|
str | The current date and time in UTC. |
Source code in waldiez/models/common/date_utils.py
parse_code_string(code_string: str) -> Tuple[Optional[str], Optional[ast.Module]]
¶
Parse the code string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
Returns:
Type | Description |
---|---|
Tuple[Optional[str], Optional[Module]] | If valid, None and the ast module. If invalid, the error message and None. |
Source code in waldiez/models/common/method_utils.py
update_dict(original: Dict[str, Any]) -> Dict[str, Any]
¶
Try to determine the type of the dictionary values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original | Dict[str, Any] | The original dictionary. | required |
Returns:
Type | Description |
---|---|
Dict[str, Any] | The updated dictionary with values converted to the detected types. |