EmbeddedIPythonCodeExecutor
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.Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be
validated to form a valid model.self is explicitly positional-only to allow self as a field name.
Parameters:
Class Attributes
kernel_name
model_computed_fields
model_config
model_fields
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
copy
!!! warning “Deprecated” This method is now deprecated; use
model_copy instead.If you need
include or exclude, use:
Returns:
dict
execute_code_blocks
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.
Parameters:
Returns:
from_orm
json
model_construct
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.Parameters:
Returns:
model_copy
model_copy
Returns a copy of the model.!!! note The underlying instance’s [
__dict__][object.dict] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).Parameters:
Returns:
model_dump
model_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.Parameters:
Returns:
model_dump_json
model_dump_json
Generates a JSON representation of the model using Pydantic’s to_json method.Parameters:
Returns:
model_json_schema
Parameters:
Returns:
model_parametrized_name
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
Returns:
model_post_init
__init__ and model_construct.This is useful if you want to do some validation that requires the entire model to be initialized. Parameters:
model_rebuild
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.
Parameters:
model_validate
Parameters:
Returns:
model_validate_json
Parameters:
Returns:
model_validate_strings
Parameters:
Returns:
parse_file
parse_obj
parse_raw
restart
schema
schema_json
update_forward_refs