autogen_ext.code_executors.azure#
- class ACADynamicSessionsCodeExecutor(pool_management_endpoint: str, credential: TokenProvider, timeout: int = 60, work_dir: Path | str | None = None, functions: Sequence[FunctionWithRequirements[Any, A] | Callable[[...], Any] | FunctionWithRequirementsStr] = [], functions_module: str = 'functions', suppress_result_output: bool = False, session_id: str | None = None)[源代码]#
基类:
CodeExecutor
(实验性)一个通过 Azure 容器应用动态会话实例执行代码的代码执行器类。
备注
此类需要
autogen-ext
包的azure
额外依赖:pip install "autogen-ext[azure]"
小心
这将在 Azure 动态代码容器上执行 LLM 生成的代码。
执行环境类似于 Jupyter 笔记本,允许增量代码执行。参数函数在每次会话开始时按顺序执行一次。然后每个代码块按接收顺序串行执行。每个环境都有一组静态定义的可用包,这些包无法更改。 目前,尝试使用环境中不可用的包将导致错误。要获取支持的包列表,请调用 get_available_packages 函数。 目前唯一支持的语言是 Python。 对于 Python 代码,请使用语言标识 "python" 作为代码块。
- 参数:
pool_management_endpoint (str) -- Azure 容器应用动态会话端点。
credential (TokenProvider) -- 实现 get_token 函数的对象。
timeout (int) -- 任何单个代码块的执行超时时间。默认为 60。
work_dir (str) -- 代码执行的工作目录。如果为 None, 将使用默认工作目录。默认工作 目录是一个临时目录。
functions (List[Union[FunctionWithRequirements[Any, A], Callable[..., Any]]]) -- 可供代码执行器使用的函数列表。默认为空列表。
bool (suppress_result_output) -- 默认情况下,执行器会将执行响应中的任何结果信息附加到结果输出。设置为 True 可阻止此行为。
session_id (str) -- 代码执行的会话 ID(传递给动态会话)。如果为 None,将生成新的会话 ID。默认为 None。注意调用 restart 时此值将被重置
备注
使用当前目录 (".") 作为工作目录已弃用。使用它将引发弃用警告。
- FUNCTION_PROMPT_TEMPLATE: ClassVar[str] = 'You have access to the following user defined functions.\n\n$functions'#
- async download_files(files: List[Path | str], cancellation_token: CancellationToken) List[str] [源代码]#
- async execute_code_blocks(code_blocks: List[CodeBlock], cancellation_token: CancellationToken) CodeResult [源代码]#
(实验性)执行代码块并返回结果。
- 参数:
code_blocks (List[CodeBlock]) -- 要执行的代码块
cancellation_token (CancellationToken) -- 用于取消操作的令牌
input_files (Optional[Union[Path, str]]) -- 代码块需要访问的任何文件
- Returns:
CodeResult -- 代码执行的结果
- format_functions_for_prompt(prompt_template: str = FUNCTION_PROMPT_TEMPLATE) str [源代码]#
(实验性)为提示格式化函数。
模板包含一个变量: - $functions: 格式化为存根的函数,每个函数之间有两个换行符。
- 参数:
prompt_template (str) -- 提示模板。默认为类默认值。
- Returns:
str -- 格式化后的提示。
- async get_available_packages(cancellation_token: CancellationToken) set[str] [源代码]#
- async get_file_list(cancellation_token: CancellationToken) List[str] [源代码]#