Refactor code executor namespace (#4538)

* refactor code exec namespaces

* delete code exec init

* update conflicts

---------

Co-authored-by: Leonardo Pinheiro <lpinheiro@microsoft.com>
This commit is contained in:
Leonardo Pinheiro 2024-12-06 01:01:59 +10:00 committed by GitHub
parent c02d87e9cf
commit 4018a129f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 31 additions and 20 deletions

View File

@ -31,7 +31,7 @@ class CodeExecutorAgent(BaseChatAgent):
Follow the installation instructions for `Docker <https://docs.docker.com/get-docker/>`_.
In this example, we show how to set up a `CodeExecutorAgent` agent that uses the
:py:class:`~autogen_ext.code_executors.DockerCommandLineCodeExecutor`
:py:class:`~autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`
to execute code snippets in a Docker container. The `work_dir` parameter indicates where all executed files are first saved locally before being executed in the Docker container.
.. code-block:: python
@ -39,7 +39,7 @@ class CodeExecutorAgent(BaseChatAgent):
import asyncio
from autogen_agentchat.agents import CodeExecutorAgent
from autogen_agentchat.messages import TextMessage
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
from autogen_core import CancellationToken

View File

@ -67,8 +67,8 @@ pip install 'autogen-ext==0.4.0.dev8'
Extras:
- `langchain` needed for {py:class}`~autogen_ext.tools.LangChainToolAdapter`
- `azure` needed for {py:class}`~autogen_ext.code_executors.ACADynamicSessionsCodeExecutor`
- `docker` needed for {py:class}`~autogen_ext.code_executors.DockerCommandLineCodeExecutor`
- `azure` needed for {py:class}`~autogen_ext.code_executors.azure.ACADynamicSessionsCodeExecutor`
- `docker` needed for {py:class}`~autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`
- `openai` needed for {py:class}`~autogen_ext.models.OpenAIChatCompletionClient`
[{fas}`circle-info;pst-color-primary` User Guide](/user-guide/extensions-user-guide/index.md) | [{fas}`file-code;pst-color-primary` API Reference](/reference/python/autogen_ext.agents.web_surfer.rst) | [{fab}`python;pst-color-primary` PyPI](https://pypi.org/project/autogen-ext/0.4.0.dev8/) | [{fab}`github;pst-color-primary` Source](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-ext)

View File

@ -37,7 +37,7 @@
")\n",
"from autogen_core.components.tools import PythonCodeExecutionTool, ToolSchema\n",
"from autogen_core.tool_agent import ToolAgent, ToolException, tool_agent_caller_loop\n",
"from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
]
},

View File

@ -56,7 +56,7 @@
"\n",
"from autogen_core import CancellationToken\n",
"from autogen_core.code_executor import CodeBlock\n",
"from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"\n",
"work_dir = Path(\"coding\")\n",
"work_dir.mkdir(exist_ok=True)\n",

View File

@ -45,7 +45,7 @@
"source": [
"from autogen_core import CancellationToken\n",
"from autogen_core.components.tools import PythonCodeExecutionTool\n",
"from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"\n",
"# Create the tool.\n",
"code_executor = DockerCommandLineCodeExecutor()\n",

View File

@ -1,4 +0,0 @@
from ._azure_container_code_executor import ACADynamicSessionsCodeExecutor, TokenProvider
from ._docker_code_executor import DockerCommandLineCodeExecutor
__all__ = ["DockerCommandLineCodeExecutor", "TokenProvider", "ACADynamicSessionsCodeExecutor"]

View File

@ -0,0 +1,3 @@
from ._azure_container_code_executor import ACADynamicSessionsCodeExecutor, TokenProvider
__all__ = ["TokenProvider", "ACADynamicSessionsCodeExecutor"]

View File

@ -23,7 +23,7 @@ from autogen_core.code_executor import (
)
from typing_extensions import ParamSpec
from ._common import build_python_functions_file, get_required_packages, to_stub
from .._common import build_python_functions_file, get_required_packages, to_stub
if TYPE_CHECKING:
from azure.core.credentials import AccessToken
@ -47,7 +47,11 @@ class ACADynamicSessionsCodeExecutor(CodeExecutor):
.. note::
This class requires the :code:`azure` extra for the :code:`autogen-ext` package.
This class requires the :code:`azure` extra for the :code:`autogen-ext` package:
.. code-block:: bash
pip install 'autogen-ext[azure]==0.4.0.dev7'
**This will execute LLM generated code on an Azure dynamic code container.**

View File

@ -0,0 +1,3 @@
from ._docker_code_executor import DockerCommandLineCodeExecutor
__all__ = ["DockerCommandLineCodeExecutor"]

View File

@ -22,7 +22,7 @@ from autogen_core.code_executor import (
FunctionWithRequirementsStr,
)
from ._common import (
from .._common import (
CommandLineCodeResult,
build_python_functions_file,
get_file_name_from_content,
@ -55,7 +55,11 @@ class DockerCommandLineCodeExecutor(CodeExecutor):
.. note::
This class requires the :code:`docker` extra for the :code:`autogen-ext` package.
This class requires the :code:`docker` extra for the :code:`autogen-ext` package:
.. code-block:: bash
pip install 'autogen-ext[docker]==0.4.0.dev7'
The executor first saves each code block in a file in the working
@ -323,6 +327,7 @@ $functions"""
async def start(self) -> None:
try:
import asyncio_atexit
import docker
from docker.errors import ImageNotFound
except ImportError as e:

View File

@ -10,7 +10,7 @@ import pytest
from anyio import open_file
from autogen_core import CancellationToken
from autogen_core.code_executor import CodeBlock
from autogen_ext.code_executors import ACADynamicSessionsCodeExecutor
from autogen_ext.code_executors.azure import ACADynamicSessionsCodeExecutor
from azure.identity import DefaultAzureCredential
UNIX_SHELLS = ["bash", "sh", "shell"]

View File

@ -11,7 +11,7 @@ from autogen_core.code_executor import (
FunctionWithRequirements,
with_requirements,
)
from autogen_ext.code_executors import ACADynamicSessionsCodeExecutor
from autogen_ext.code_executors.azure import ACADynamicSessionsCodeExecutor
from azure.identity import DefaultAzureCredential
ENVIRON_KEY_AZURE_POOL_ENDPOINT = "AZURE_POOL_ENDPOINT"

View File

@ -10,7 +10,7 @@ import pytest_asyncio
from aiofiles import open
from autogen_core import CancellationToken
from autogen_core.code_executor import CodeBlock
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
def docker_tests_enabled() -> bool:

View File

@ -8,7 +8,7 @@ import os
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
from autogen_core.application.logging import EVENT_LOGGER_NAME
from autogen_core.code_executor import CodeBlock
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
from autogen_magentic_one.agents.coder import Coder, Executor
from autogen_magentic_one.agents.file_surfer import FileSurfer
from autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurfer

View File

@ -10,7 +10,7 @@ import logging
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
from autogen_core.application.logging import EVENT_LOGGER_NAME
from autogen_core.code_executor import CodeBlock
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
from autogen_magentic_one.agents.coder import Coder, Executor
from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator
from autogen_magentic_one.agents.user_proxy import UserProxy