autogen_ext.code_executors.docker#
- class DockerCommandLineCodeExecutor(image: str = 'python:3-slim', container_name: str | 无 = None, *, timeout: int = 60, work_dir: 路径 | str = Path('.'), bind_dir: 路径 | str | 无 = None, auto_remove: bool = True, stop_container: bool = True, functions: Sequence[FunctionWithRequirements[任何, A] | Callable[[...], 任何] | FunctionWithRequirementsStr] = [], functions_module: str = 'functions', extra_volumes: 字典[str, 字典[str, str]] | 无 = None, extra_hosts: 字典[str, str] | 无 = None, init_command: str | 无 = None)[源代码]#
基础类:
CodeExecutor,Component[DockerCommandLineCodeExecutorConfig]通过Docker容器中的命令行环境执行代码。
注意
此类需要
docker额外的autogen-ext包:pip install "autogen-ext[docker]"
执行器首先将每个代码块保存在工作目录中的文件中,然后在容器中执行代码文件。 执行器按照接收到的顺序执行代码块。 目前,执行器仅支持Python和shell脚本。 对于Python代码,请使用“python”作为代码块的语言。 对于shell脚本,请使用“bash”、“shell”或“sh”作为代码块的语言。
- Parameters:
image (_type_, optional) – 用于代码执行的Docker镜像。默认为“python:3-slim”。
container_name (可选[str], 可选) – Docker容器的名称。如果为None,将自动生成一个名称。默认值为None。
timeout (int, optional) – 代码执行的超时时间。默认为60。
work_dir (Union[Path, str], optional) – 代码执行的工作目录。默认为 Path(“.”)。
bind_dir (Union[Path, str], optional) – 将被绑定的目录
spawn (到代码执行器容器。在您希望的情况下非常有用)
work_dir. (容器中的容器。默认为)
auto_remove (bool, 可选) – 如果为true,当Docker容器停止时,将自动移除。默认为True。
stop_container (bool, optional) – 如果为true,在调用stop时,当上下文管理器退出或Python进程以文本形式退出时,将自动停止容器。默认为True。
functions (列表[联合[FunctionWithRequirements[任何, A], 可调用[..., 任何]]]) – 可供代码执行器使用的函数列表。默认值为空列表。
functions_module (str, 可选) – 用于存储函数的模块名称。默认为“functions”。
extra_volumes (可选[Dict[str, Dict[str, str]]], 可选) – 一个额外卷的字典(除了work_dir之外)用于挂载到容器;键是主机源路径,值‘bind’是容器路径。参见 默认为 None。 示例:extra_volumes = {‘/home/user1/’: {‘bind’: ‘/mnt/vol2’, ‘mode’: ‘rw’}, ‘/var/www’: {‘bind’: ‘/mnt/vol1’, ‘mode’: ‘ro’}}
extra_hosts (Optional[Dict[str, str]], optional) – 一个主机映射的字典,用于添加到容器中。(参见 Docker 文档中的 extra_hosts)默认为 None。 示例: extra_hosts = {“kubernetes.docker.internal”: “host-gateway”}
init_command (可选[str], 可选) – 在每次shell操作执行前运行的shell命令。默认值为None。 示例:init_command=”kubectl config use-context docker-hub”
- FUNCTION_PROMPT_TEMPLATE: ClassVar[str] = 'You have access to the following user defined functions. They can be accessed from the module called `$module_name` by their function names.\n\nFor example, if there was a function called `foo` you could import it by writing `from $module_name import foo`\n\n$functions'#
- SUPPORTED_LANGUAGES: ClassVar[List[str]] = ['bash', 'shell', 'sh', 'pwsh', 'powershell', 'ps1', 'python']#
- component_config_schema#
DockerCommandLineCodeExecutorConfig的别名
- component_provider_override: ClassVar[str | 无] = 'autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor'#
覆盖组件的提供商字符串。这应用于防止内部模块名称成为模块名称的一部分。