mirror of
https://github.com/microsoft/autogen.git
synced 2026-02-11 08:15:13 -05:00
Restructure extensions, update corresponding docs (#3826)
* Restructure extensions, update corresponding docs * update tests, add deprecation messages * fix tests * update lockfile ---------
This commit is contained in:
@@ -10,7 +10,7 @@ import pytest
|
||||
from anyio import open_file
|
||||
from autogen_core.base import CancellationToken
|
||||
from autogen_core.components.code_executor import CodeBlock
|
||||
from autogen_ext.code_executor.aca_dynamic_sessions import AzureContainerCodeExecutor
|
||||
from autogen_ext.code_executors import ACADynamicSessionsCodeExecutor
|
||||
from azure.identity import DefaultAzureCredential
|
||||
|
||||
UNIX_SHELLS = ["bash", "sh", "shell"]
|
||||
@@ -30,7 +30,9 @@ POOL_ENDPOINT = os.getenv(ENVIRON_KEY_AZURE_POOL_ENDPOINT)
|
||||
async def test_execute_code() -> None:
|
||||
assert POOL_ENDPOINT is not None
|
||||
cancellation_token = CancellationToken()
|
||||
executor = AzureContainerCodeExecutor(pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential())
|
||||
executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential()
|
||||
)
|
||||
|
||||
# Test single code block.
|
||||
code_blocks = [CodeBlock(code="import sys; print('hello world!')", language="python")]
|
||||
@@ -67,7 +69,7 @@ async def test_execute_code() -> None:
|
||||
async def test_azure_container_code_executor_timeout() -> None:
|
||||
assert POOL_ENDPOINT is not None
|
||||
cancellation_token = CancellationToken()
|
||||
executor = AzureContainerCodeExecutor(
|
||||
executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), timeout=1
|
||||
)
|
||||
code_blocks = [CodeBlock(code="import time; time.sleep(10); print('hello world!')", language="python")]
|
||||
@@ -83,7 +85,9 @@ async def test_azure_container_code_executor_timeout() -> None:
|
||||
async def test_azure_container_code_executor_cancellation() -> None:
|
||||
assert POOL_ENDPOINT is not None
|
||||
cancellation_token = CancellationToken()
|
||||
executor = AzureContainerCodeExecutor(pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential())
|
||||
executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential()
|
||||
)
|
||||
code_blocks = [CodeBlock(code="import time; time.sleep(10); print('hello world!')", language="python")]
|
||||
|
||||
coro = executor.execute_code_blocks(code_blocks, cancellation_token)
|
||||
@@ -109,7 +113,7 @@ async def test_upload_files() -> None:
|
||||
cancellation_token = CancellationToken()
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
executor = AzureContainerCodeExecutor(
|
||||
executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), work_dir=temp_dir
|
||||
)
|
||||
|
||||
@@ -155,7 +159,7 @@ async def test_download_files() -> None:
|
||||
cancellation_token = CancellationToken()
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
executor = AzureContainerCodeExecutor(
|
||||
executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), work_dir=temp_dir
|
||||
)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from autogen_core.components.code_executor import (
|
||||
FunctionWithRequirements,
|
||||
with_requirements,
|
||||
)
|
||||
from autogen_ext.code_executor.aca_dynamic_sessions import AzureContainerCodeExecutor
|
||||
from autogen_ext.code_executors import ACADynamicSessionsCodeExecutor
|
||||
from azure.identity import DefaultAzureCredential
|
||||
|
||||
ENVIRON_KEY_AZURE_POOL_ENDPOINT = "AZURE_POOL_ENDPOINT"
|
||||
@@ -58,10 +58,10 @@ def function_incorrect_dep() -> "polars.DataFrame":
|
||||
async def test_azure_can_load_function_with_reqs() -> None:
|
||||
assert POOL_ENDPOINT is not None
|
||||
cancellation_token = CancellationToken()
|
||||
azure_executor = AzureContainerCodeExecutor(
|
||||
azure_executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), functions=[load_data]
|
||||
)
|
||||
# AzureContainerCodeExecutor doesn't use the functions module import
|
||||
# ACADynamicSessionsCodeExecutor doesn't use the functions module import
|
||||
code = """import polars
|
||||
|
||||
# Get first row's name
|
||||
@@ -87,10 +87,10 @@ async def test_azure_can_load_function() -> None:
|
||||
assert POOL_ENDPOINT is not None
|
||||
|
||||
cancellation_token = CancellationToken()
|
||||
azure_executor = AzureContainerCodeExecutor(
|
||||
azure_executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), functions=[add_two_numbers]
|
||||
)
|
||||
# AzureContainerCodeExecutor doesn't use the functions module import
|
||||
# ACADynamicSessionsCodeExecutor doesn't use the functions module import
|
||||
code = """print(add_two_numbers(1, 2))"""
|
||||
|
||||
azure_result = await azure_executor.execute_code_blocks(
|
||||
@@ -111,7 +111,7 @@ async def test_azure_can_load_function() -> None:
|
||||
async def test_azure_fails_for_function_incorrect_import() -> None:
|
||||
assert POOL_ENDPOINT is not None
|
||||
cancellation_token = CancellationToken()
|
||||
azure_executor = AzureContainerCodeExecutor(
|
||||
azure_executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT,
|
||||
credential=DefaultAzureCredential(),
|
||||
functions=[function_incorrect_import],
|
||||
@@ -135,7 +135,7 @@ async def test_azure_fails_for_function_incorrect_import() -> None:
|
||||
async def test_azure_fails_for_function_incorrect_dep() -> None:
|
||||
assert POOL_ENDPOINT is not None
|
||||
cancellation_token = CancellationToken()
|
||||
azure_executor = AzureContainerCodeExecutor(
|
||||
azure_executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), functions=[function_incorrect_dep]
|
||||
)
|
||||
code = """function_incorrect_dep()"""
|
||||
@@ -153,7 +153,7 @@ def test_azure_formatted_prompt() -> None:
|
||||
assert_str = '''def add_two_numbers(a: int, b: int) -> int:
|
||||
"""Add two numbers together."""
|
||||
'''
|
||||
azure_executor = AzureContainerCodeExecutor(
|
||||
azure_executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=DUMMY_POOL_ENDPOINT, credential=DefaultAzureCredential(), functions=[add_two_numbers]
|
||||
)
|
||||
|
||||
@@ -174,7 +174,7 @@ def add_two_numbers(a: int, b: int) -> int:
|
||||
"""Add two numbers together."""
|
||||
'''
|
||||
|
||||
azure_executor = AzureContainerCodeExecutor(
|
||||
azure_executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=DUMMY_POOL_ENDPOINT, credential=DefaultAzureCredential(), functions=[func]
|
||||
)
|
||||
|
||||
@@ -197,7 +197,7 @@ def add_two_numbers(a: int, b: int) -> int:
|
||||
return a + b
|
||||
'''
|
||||
)
|
||||
azure_executor = AzureContainerCodeExecutor(
|
||||
azure_executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), functions=[func]
|
||||
)
|
||||
code = """print(add_two_numbers(1, 2))"""
|
||||
@@ -228,7 +228,7 @@ def add_two_numbers(a: int, b: int) -> int:
|
||||
'''
|
||||
)
|
||||
|
||||
azure_executor = AzureContainerCodeExecutor(
|
||||
azure_executor = ACADynamicSessionsCodeExecutor(
|
||||
pool_management_endpoint=POOL_ENDPOINT, credential=DefaultAzureCredential(), functions=[func]
|
||||
)
|
||||
code = """print(add_two_numbers(object(), False))"""
|
||||
|
||||
@@ -10,7 +10,7 @@ import pytest_asyncio
|
||||
from aiofiles import open
|
||||
from autogen_core.base import CancellationToken
|
||||
from autogen_core.components.code_executor import CodeBlock
|
||||
from autogen_ext.code_executor.docker_executor import DockerCommandLineCodeExecutor
|
||||
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
|
||||
|
||||
|
||||
def docker_tests_enabled() -> bool:
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
async def test_example() -> None:
|
||||
assert True
|
||||
@@ -2,10 +2,10 @@ from typing import Optional, Type
|
||||
|
||||
import pytest
|
||||
from autogen_core.base import CancellationToken
|
||||
from autogen_ext.tools.langchain import LangChainToolAdapter # type: ignore
|
||||
from langchain.tools import BaseTool as LangChainTool # type: ignore
|
||||
from langchain.tools import tool # pyright: ignore
|
||||
from autogen_ext.tools import LangChainToolAdapter # type: ignore
|
||||
from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun, CallbackManagerForToolRun
|
||||
from langchain_core.tools import BaseTool as LangChainTool
|
||||
from langchain_core.tools import tool # pyright: ignore
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ async def test_langchain_tool_adapter() -> None:
|
||||
langchain_tool = add # type: ignore
|
||||
|
||||
# Create an adapter
|
||||
adapter = LangChainToolAdapter(langchain_tool) # pyright: ignore
|
||||
adapter = LangChainToolAdapter(langchain_tool) # type: ignore
|
||||
|
||||
# Test schema generation
|
||||
schema = adapter.schema
|
||||
@@ -75,7 +75,7 @@ async def test_langchain_tool_adapter() -> None:
|
||||
|
||||
# Test CustomCalculatorTool
|
||||
custom_langchain_tool = CustomCalculatorTool()
|
||||
custom_adapter = LangChainToolAdapter(custom_langchain_tool) # pyright: ignore
|
||||
custom_adapter = LangChainToolAdapter(custom_langchain_tool) # type: ignore
|
||||
|
||||
# Test schema generation for CustomCalculatorTool
|
||||
custom_schema = custom_adapter.schema
|
||||
|
||||
Reference in New Issue
Block a user