autogen.coding.jupyter.EmbeddedIPythonCodeExecutor
EmbeddedIPythonCodeExecutor
(Experimental) A code executor class that executes code statefully using an embedded
IPython kernel managed by this class.
This will execute LLM generated code on the local machine.
Each execution is stateful and can access variables created from previous
executions in the same session. The kernel must be installed before using
this class. The kernel can be installed using the following command: python -m ipykernel install --user --name \{kernel_name}
where kernel_name
is the name of the kernel to install.
Name | Description |
---|---|
**kwargs | Type: Any |
Class Attributes
kernel_name
model_config
output_dir
timeout
Instance Attributes
code_extractor
(Experimental) Export a code extractor that can be used by an agent.
model_extra
Get extra fields set during validation.
Returns:
A dictionary of extra fields, or None
if config.extra
is not set to "allow"
.
model_fields_set
Returns the set of fields that have been explicitly set on this model instance.
Returns:
A set of strings representing the fields that have been set,
i.e. that were not filled from defaults.
Instance Methods
construct
Name | Description |
---|---|
**values | Type: Any |
copy
Returns a copy of the model.
!!! warning “Deprecated”
This method is now deprecated; use model_copy
instead.
If you need include
or exclude
, use:
Name | Description |
---|---|
include | Optional set or mapping specifying which fields to include in the copied model. Type: AbstractSetIntStr | MappingIntStrAny | None Default: None |
exclude | Optional set or mapping specifying which fields to exclude in the copied model. Type: AbstractSetIntStr | MappingIntStrAny | None Default: None |
update | Optional dictionary of field-value pairs to override field values in the copied model. Type: Dict[str, Any] | None Default: None |
deep | If True, the values of fields that are Pydantic models will be deep-copied. Type: bool Default: False |
Type | Description |
---|---|
Self | A copy of the model with included, excluded and updated fields as specified. |
dict
Name | Description |
---|---|
include | Type: IncEx | None Default: None |
exclude | Type: IncEx | None Default: None |
by_alias | Type: bool Default: False |
exclude_unset | Type: bool Default: False |
exclude_defaults | Type: bool Default: False |
exclude_none | Type: bool Default: False |
execute_code_blocks
(Experimental) Execute a list of code blocks and return the result.
This method executes a list of code blocks as cells in an IPython kernel
managed by this class.
See: https://jupyter-client.readthedocs.io/en/stable/messaging.html
for the message protocol.
Name | Description |
---|---|
code_blocks | A list of code blocks to execute. Type: list[CodeBlock] |
Type | Description |
---|---|
autogen.coding.base.IPythonCodeResult | IPythonCodeResult: The result of the code execution. |
from_orm
Name | Description |
---|---|
obj | Type: Any |
json
Name | Description |
---|---|
include | Type: IncEx | None Default: None |
exclude | Type: IncEx | None Default: None |
by_alias | Type: bool Default: False |
exclude_unset | Type: bool Default: False |
exclude_defaults | Type: bool Default: False |
exclude_none | Type: bool Default: False |
encoder | Type: Callable[[Any], Any] | None Default: PydanticUndefined |
models_as_dict | Type: bool Default: PydanticUndefined |
**dumps_kwargs | Type: Any |
model_construct
Creates a new instance of the Model
class with validated data.
Creates a new model setting __dict__
and __pydantic_fields_set__
from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
!!! note
model_construct()
generally respects the model_config.extra
setting on the provided model.
That is, if model_config.extra == 'allow'
, then all extra passed values are added to the model instance’s __dict__
and __pydantic_extra__
fields. If model_config.extra == 'ignore'
(the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct()
, having model_config.extra == 'forbid'
does not result in
an error if extra values are passed, but they will be ignored.
Name | Description |
---|---|
**values | Type: Any |
Type | Description |
---|---|
Self | A new instance of the Model class with validated data. |
model_copy
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy
Returns a copy of the model.
Name | Description |
---|---|
update | Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. Type: Mapping[str, Any] | None Default: None |
deep | Set to True to make a deep copy of the model.Type: bool Default: False |
Type | Description |
---|---|
Self | New model instance. |
model_dump
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Name | Description |
---|---|
mode | The mode in which to_python should run.If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects. Type: “Literal[‘json’, ‘python’] | str” Default: ‘python’ |
include | A set of fields to include in the output. Type: IncEx | None Default: None |
exclude | A set of fields to exclude from the output. Type: IncEx | None Default: None |
context | Additional context to pass to the serializer. Type: Any | None Default: None |
by_alias | Whether to use the field’s alias in the dictionary key if defined. Type: bool Default: False |
exclude_unset | Whether to exclude fields that have not been explicitly set. Type: bool Default: False |
exclude_defaults | Whether to exclude fields that are set to their default value. Type: bool Default: False |
exclude_none | Whether to exclude fields that have a value of None .Type: bool Default: False |
round_trip | If True, dumped values should be valid as input for non-idempotent types such as Json[T]. Type: bool Default: False |
warnings | How to handle serialization errors. False/“none” ignores them, True/“warn” logs errors, “error” raises a [ PydanticSerializationError ][pydantic_core.PydanticSerializationError].Type: “bool | Literal[‘none’, ‘warn’, ‘error’]“ Default: True |
serialize_as_any | Whether to serialize fields with duck-typing serialization behavior. Type: bool Default: False |
Type | Description |
---|---|
dict[str, typing.Any] | A dictionary representation of the model. |
model_dump_json
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic’s to_json
method.
Name | Description |
---|---|
indent | Indentation to use in the JSON output. If None is passed, the output will be compact. Type: int | None Default: None |
include | Field(s) to include in the JSON output. Type: IncEx | None Default: None |
exclude | Field(s) to exclude from the JSON output. Type: IncEx | None Default: None |
context | Additional context to pass to the serializer. Type: Any | None Default: None |
by_alias | Whether to serialize using field aliases. Type: bool Default: False |
exclude_unset | Whether to exclude fields that have not been explicitly set. Type: bool Default: False |
exclude_defaults | Whether to exclude fields that are set to their default value. Type: bool Default: False |
exclude_none | Whether to exclude fields that have a value of None .Type: bool Default: False |
round_trip | If True, dumped values should be valid as input for non-idempotent types such as Json[T]. Type: bool Default: False |
warnings | How to handle serialization errors. False/“none” ignores them, True/“warn” logs errors, “error” raises a [ PydanticSerializationError ][pydantic_core.PydanticSerializationError].Type: “bool | Literal[‘none’, ‘warn’, ‘error’]“ Default: True |
serialize_as_any | Whether to serialize fields with duck-typing serialization behavior. Type: bool Default: False |
Type | Description |
---|---|
str | A JSON string representation of the model. |
model_json_schema
Generates a JSON schema for a model class.
Name | Description |
---|---|
by_alias | Whether to use attribute aliases or not. Type: bool Default: True |
ref_template | The reference template. Type: str Default: ’#/$defs/{model}‘ |
schema_generator | To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modificationsType: type[GenerateJsonSchema] Default: pydantic.json_schema.GenerateJsonSchema |
mode | The mode in which to generate the schema. Type: JsonSchemaMode Default: ‘validation’ |
Type | Description |
---|---|
dict[str, typing.Any] | The JSON schema for the given model class. |
model_parametrized_name
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Name | Description |
---|---|
params | Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int] , the value (str, int) would be passed to params .Type: tuple[type[Any], …] |
Type | Description |
---|---|
str | String representing the new class where params are passed to cls as type variables. |
model_post_init
Override this method to perform additional initialization after __init__
and model_construct
.
This is useful if you want to do some validation that requires the entire model to be initialized.
Name | Description |
---|---|
_BaseModel__context | Type: Any |
model_rebuild
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during
the initial attempt to build the schema, and automatic rebuilding fails.
Name | Description |
---|---|
force | Whether to force the rebuilding of the model schema, defaults to False .Type: bool Default: False |
raise_errors | Whether to raise errors, defaults to True .Type: bool Default: True |
model_validate
Validate a pydantic model instance.
Name | Description |
---|---|
obj | The object to validate. Type: Any |
strict | Whether to enforce types strictly. Type: bool | None Default: None |
from_attributes | Whether to extract data from object attributes. Type: bool | None Default: None |
context | Additional context to pass to the validator. Type: Any | None Default: None |
Type | Description |
---|---|
Self | The validated model instance. |
model_validate_json
Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing
Validate the given JSON data against the Pydantic model.
Name | Description |
---|---|
json_data | The JSON data to validate. Type: str | bytes | bytearray |
strict | Whether to enforce types strictly. Type: bool | None Default: None |
context | Extra variables to pass to the validator. Type: Any | None Default: None |
Type | Description |
---|---|
Self | The validated Pydantic model. |
model_validate_strings
Validate the given object with string data against the Pydantic model.
Name | Description |
---|---|
obj | The object containing string data to validate. Type: Any |
strict | Whether to enforce types strictly. Type: bool | None Default: None |
context | Extra variables to pass to the validator. Type: Any | None Default: None |
Type | Description |
---|---|
Self | The validated Pydantic model. |
parse_file
Name | Description |
---|---|
path | Type: str | Path |
content_type | Type: str | None Default: None |
encoding | Type: str Default: ‘utf8’ |
proto | Type: DeprecatedParseProtocol | None Default: None |
allow_pickle | Type: bool Default: False |
parse_obj
Name | Description |
---|---|
obj | Type: Any |
parse_raw
Name | Description |
---|---|
b | Type: str | bytes |
content_type | Type: str | None Default: None |
encoding | Type: str Default: ‘utf8’ |
proto | Type: DeprecatedParseProtocol | None Default: None |
allow_pickle | Type: bool Default: False |
restart
(Experimental) Restart a new session.
schema
Name | Description |
---|---|
by_alias | Type: bool Default: True |
ref_template | Type: str Default: ’#/$defs/{model}‘ |
schema_json
Name | Description |
---|---|
by_alias | Type: bool Default: True |
ref_template | Type: str Default: ’#/$defs/{model}‘ |
**dumps_kwargs | Type: Any |
update_forward_refs
Name | Description |
---|---|
**localns | Type: Any |
validate
Name | Description |
---|---|
value | Type: Any |