ag2 0.9.7__py3-none-any.whl → 0.9.8.post1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ag2 might be problematic. Click here for more details.
- {ag2-0.9.7.dist-info → ag2-0.9.8.post1.dist-info}/METADATA +102 -75
- ag2-0.9.8.post1.dist-info/RECORD +387 -0
- autogen/__init__.py +1 -2
- autogen/_website/generate_api_references.py +4 -5
- autogen/_website/generate_mkdocs.py +9 -15
- autogen/_website/notebook_processor.py +13 -14
- autogen/_website/process_notebooks.py +10 -10
- autogen/_website/utils.py +5 -4
- autogen/agentchat/agent.py +13 -13
- autogen/agentchat/assistant_agent.py +7 -6
- autogen/agentchat/contrib/agent_eval/agent_eval.py +3 -3
- autogen/agentchat/contrib/agent_eval/critic_agent.py +3 -3
- autogen/agentchat/contrib/agent_eval/quantifier_agent.py +3 -3
- autogen/agentchat/contrib/agent_eval/subcritic_agent.py +3 -3
- autogen/agentchat/contrib/agent_optimizer.py +3 -3
- autogen/agentchat/contrib/capabilities/generate_images.py +11 -11
- autogen/agentchat/contrib/capabilities/teachability.py +15 -15
- autogen/agentchat/contrib/capabilities/transforms.py +17 -18
- autogen/agentchat/contrib/capabilities/transforms_util.py +5 -5
- autogen/agentchat/contrib/capabilities/vision_capability.py +4 -3
- autogen/agentchat/contrib/captainagent/agent_builder.py +30 -30
- autogen/agentchat/contrib/captainagent/captainagent.py +22 -21
- autogen/agentchat/contrib/captainagent/tool_retriever.py +2 -3
- autogen/agentchat/contrib/gpt_assistant_agent.py +9 -9
- autogen/agentchat/contrib/graph_rag/document.py +3 -3
- autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +3 -3
- autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/graph_rag/graph_query_engine.py +3 -3
- autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py +5 -11
- autogen/agentchat/contrib/graph_rag/neo4j_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_query_engine.py +7 -7
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/img_utils.py +1 -1
- autogen/agentchat/contrib/llamaindex_conversable_agent.py +11 -11
- autogen/agentchat/contrib/llava_agent.py +18 -4
- autogen/agentchat/contrib/math_user_proxy_agent.py +11 -11
- autogen/agentchat/contrib/multimodal_conversable_agent.py +8 -8
- autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +6 -5
- autogen/agentchat/contrib/rag/chromadb_query_engine.py +22 -26
- autogen/agentchat/contrib/rag/llamaindex_query_engine.py +14 -17
- autogen/agentchat/contrib/rag/mongodb_query_engine.py +27 -37
- autogen/agentchat/contrib/rag/query_engine.py +7 -5
- autogen/agentchat/contrib/retrieve_assistant_agent.py +5 -5
- autogen/agentchat/contrib/retrieve_user_proxy_agent.py +8 -7
- autogen/agentchat/contrib/society_of_mind_agent.py +15 -14
- autogen/agentchat/contrib/swarm_agent.py +76 -98
- autogen/agentchat/contrib/text_analyzer_agent.py +7 -7
- autogen/agentchat/contrib/vectordb/base.py +10 -18
- autogen/agentchat/contrib/vectordb/chromadb.py +2 -1
- autogen/agentchat/contrib/vectordb/couchbase.py +18 -20
- autogen/agentchat/contrib/vectordb/mongodb.py +6 -5
- autogen/agentchat/contrib/vectordb/pgvectordb.py +40 -41
- autogen/agentchat/contrib/vectordb/qdrant.py +5 -5
- autogen/agentchat/contrib/web_surfer.py +20 -19
- autogen/agentchat/conversable_agent.py +292 -290
- autogen/agentchat/group/context_str.py +1 -3
- autogen/agentchat/group/context_variables.py +15 -25
- autogen/agentchat/group/group_tool_executor.py +10 -10
- autogen/agentchat/group/group_utils.py +15 -15
- autogen/agentchat/group/guardrails.py +7 -7
- autogen/agentchat/group/handoffs.py +19 -36
- autogen/agentchat/group/multi_agent_chat.py +7 -7
- autogen/agentchat/group/on_condition.py +4 -7
- autogen/agentchat/group/on_context_condition.py +4 -7
- autogen/agentchat/group/patterns/auto.py +8 -7
- autogen/agentchat/group/patterns/manual.py +7 -6
- autogen/agentchat/group/patterns/pattern.py +13 -12
- autogen/agentchat/group/patterns/random.py +3 -3
- autogen/agentchat/group/patterns/round_robin.py +3 -3
- autogen/agentchat/group/reply_result.py +2 -4
- autogen/agentchat/group/speaker_selection_result.py +5 -5
- autogen/agentchat/group/targets/group_chat_target.py +7 -6
- autogen/agentchat/group/targets/group_manager_target.py +4 -4
- autogen/agentchat/group/targets/transition_target.py +2 -1
- autogen/agentchat/groupchat.py +58 -61
- autogen/agentchat/realtime/experimental/audio_adapters/twilio_audio_adapter.py +4 -4
- autogen/agentchat/realtime/experimental/audio_adapters/websocket_audio_adapter.py +4 -4
- autogen/agentchat/realtime/experimental/clients/gemini/client.py +7 -7
- autogen/agentchat/realtime/experimental/clients/oai/base_client.py +8 -8
- autogen/agentchat/realtime/experimental/clients/oai/rtc_client.py +6 -6
- autogen/agentchat/realtime/experimental/clients/realtime_client.py +10 -9
- autogen/agentchat/realtime/experimental/realtime_agent.py +10 -9
- autogen/agentchat/realtime/experimental/realtime_observer.py +3 -3
- autogen/agentchat/realtime/experimental/realtime_swarm.py +44 -44
- autogen/agentchat/user_proxy_agent.py +10 -9
- autogen/agentchat/utils.py +3 -3
- autogen/agents/contrib/time/time_reply_agent.py +6 -5
- autogen/agents/contrib/time/time_tool_agent.py +2 -1
- autogen/agents/experimental/deep_research/deep_research.py +3 -3
- autogen/agents/experimental/discord/discord.py +2 -2
- autogen/agents/experimental/document_agent/chroma_query_engine.py +29 -44
- autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +9 -14
- autogen/agents/experimental/document_agent/document_agent.py +15 -16
- autogen/agents/experimental/document_agent/document_conditions.py +3 -3
- autogen/agents/experimental/document_agent/document_utils.py +5 -9
- autogen/agents/experimental/document_agent/inmemory_query_engine.py +14 -20
- autogen/agents/experimental/document_agent/parser_utils.py +4 -4
- autogen/agents/experimental/document_agent/url_utils.py +14 -23
- autogen/agents/experimental/reasoning/reasoning_agent.py +33 -33
- autogen/agents/experimental/slack/slack.py +2 -2
- autogen/agents/experimental/telegram/telegram.py +2 -3
- autogen/agents/experimental/websurfer/websurfer.py +4 -4
- autogen/agents/experimental/wikipedia/wikipedia.py +5 -7
- autogen/browser_utils.py +8 -8
- autogen/cache/abstract_cache_base.py +5 -5
- autogen/cache/cache.py +12 -12
- autogen/cache/cache_factory.py +4 -4
- autogen/cache/cosmos_db_cache.py +9 -9
- autogen/cache/disk_cache.py +6 -6
- autogen/cache/in_memory_cache.py +4 -4
- autogen/cache/redis_cache.py +4 -4
- autogen/code_utils.py +18 -18
- autogen/coding/base.py +6 -6
- autogen/coding/docker_commandline_code_executor.py +9 -9
- autogen/coding/func_with_reqs.py +7 -6
- autogen/coding/jupyter/base.py +3 -3
- autogen/coding/jupyter/docker_jupyter_server.py +3 -4
- autogen/coding/jupyter/import_utils.py +3 -3
- autogen/coding/jupyter/jupyter_client.py +5 -5
- autogen/coding/jupyter/jupyter_code_executor.py +3 -4
- autogen/coding/jupyter/local_jupyter_server.py +2 -6
- autogen/coding/local_commandline_code_executor.py +8 -7
- autogen/coding/markdown_code_extractor.py +1 -2
- autogen/coding/utils.py +1 -2
- autogen/doc_utils.py +3 -2
- autogen/environments/docker_python_environment.py +19 -29
- autogen/environments/python_environment.py +8 -17
- autogen/environments/system_python_environment.py +3 -4
- autogen/environments/venv_python_environment.py +8 -12
- autogen/environments/working_directory.py +1 -2
- autogen/events/agent_events.py +106 -109
- autogen/events/base_event.py +6 -5
- autogen/events/client_events.py +15 -14
- autogen/events/helpers.py +1 -1
- autogen/events/print_event.py +4 -5
- autogen/fast_depends/_compat.py +10 -15
- autogen/fast_depends/core/build.py +17 -36
- autogen/fast_depends/core/model.py +64 -113
- autogen/fast_depends/dependencies/model.py +2 -1
- autogen/fast_depends/dependencies/provider.py +3 -2
- autogen/fast_depends/library/model.py +4 -4
- autogen/fast_depends/schema.py +7 -7
- autogen/fast_depends/use.py +17 -25
- autogen/fast_depends/utils.py +10 -30
- autogen/formatting_utils.py +6 -6
- autogen/graph_utils.py +1 -4
- autogen/import_utils.py +13 -13
- autogen/interop/crewai/crewai.py +2 -2
- autogen/interop/interoperable.py +2 -2
- autogen/interop/langchain/langchain_chat_model_factory.py +3 -2
- autogen/interop/langchain/langchain_tool.py +2 -6
- autogen/interop/litellm/litellm_config_factory.py +6 -7
- autogen/interop/pydantic_ai/pydantic_ai.py +4 -7
- autogen/interop/registry.py +2 -1
- autogen/io/base.py +5 -5
- autogen/io/run_response.py +33 -32
- autogen/io/websockets.py +6 -5
- autogen/json_utils.py +1 -2
- autogen/llm_config/__init__.py +11 -0
- autogen/llm_config/client.py +58 -0
- autogen/llm_config/config.py +384 -0
- autogen/llm_config/entry.py +154 -0
- autogen/logger/base_logger.py +4 -3
- autogen/logger/file_logger.py +2 -1
- autogen/logger/logger_factory.py +2 -2
- autogen/logger/logger_utils.py +2 -2
- autogen/logger/sqlite_logger.py +2 -1
- autogen/math_utils.py +4 -5
- autogen/mcp/__main__.py +6 -6
- autogen/mcp/helpers.py +4 -4
- autogen/mcp/mcp_client.py +170 -29
- autogen/mcp/mcp_proxy/fastapi_code_generator_helpers.py +3 -4
- autogen/mcp/mcp_proxy/mcp_proxy.py +23 -26
- autogen/mcp/mcp_proxy/operation_grouping.py +4 -5
- autogen/mcp/mcp_proxy/operation_renaming.py +6 -10
- autogen/mcp/mcp_proxy/security.py +2 -3
- autogen/messages/agent_messages.py +96 -98
- autogen/messages/base_message.py +6 -5
- autogen/messages/client_messages.py +15 -14
- autogen/messages/print_message.py +4 -5
- autogen/oai/__init__.py +1 -2
- autogen/oai/anthropic.py +42 -41
- autogen/oai/bedrock.py +68 -57
- autogen/oai/cerebras.py +26 -25
- autogen/oai/client.py +113 -139
- autogen/oai/client_utils.py +3 -3
- autogen/oai/cohere.py +34 -11
- autogen/oai/gemini.py +39 -17
- autogen/oai/gemini_types.py +11 -12
- autogen/oai/groq.py +22 -10
- autogen/oai/mistral.py +17 -11
- autogen/oai/oai_models/__init__.py +14 -2
- autogen/oai/oai_models/_models.py +2 -2
- autogen/oai/oai_models/chat_completion.py +13 -14
- autogen/oai/oai_models/chat_completion_message.py +11 -9
- autogen/oai/oai_models/chat_completion_message_tool_call.py +26 -3
- autogen/oai/oai_models/chat_completion_token_logprob.py +3 -4
- autogen/oai/oai_models/completion_usage.py +8 -9
- autogen/oai/ollama.py +19 -9
- autogen/oai/openai_responses.py +40 -17
- autogen/oai/openai_utils.py +48 -38
- autogen/oai/together.py +29 -14
- autogen/retrieve_utils.py +6 -7
- autogen/runtime_logging.py +5 -4
- autogen/token_count_utils.py +7 -4
- autogen/tools/contrib/time/time.py +0 -1
- autogen/tools/dependency_injection.py +5 -6
- autogen/tools/experimental/browser_use/browser_use.py +10 -10
- autogen/tools/experimental/code_execution/python_code_execution.py +5 -7
- autogen/tools/experimental/crawl4ai/crawl4ai.py +12 -15
- autogen/tools/experimental/deep_research/deep_research.py +9 -8
- autogen/tools/experimental/duckduckgo/duckduckgo_search.py +5 -11
- autogen/tools/experimental/firecrawl/firecrawl_tool.py +98 -115
- autogen/tools/experimental/google/authentication/credentials_local_provider.py +1 -1
- autogen/tools/experimental/google/drive/drive_functions.py +4 -4
- autogen/tools/experimental/google/drive/toolkit.py +5 -5
- autogen/tools/experimental/google_search/google_search.py +5 -5
- autogen/tools/experimental/google_search/youtube_search.py +5 -5
- autogen/tools/experimental/messageplatform/discord/discord.py +8 -12
- autogen/tools/experimental/messageplatform/slack/slack.py +14 -20
- autogen/tools/experimental/messageplatform/telegram/telegram.py +8 -12
- autogen/tools/experimental/perplexity/perplexity_search.py +18 -29
- autogen/tools/experimental/reliable/reliable.py +68 -74
- autogen/tools/experimental/searxng/searxng_search.py +20 -19
- autogen/tools/experimental/tavily/tavily_search.py +12 -19
- autogen/tools/experimental/web_search_preview/web_search_preview.py +13 -7
- autogen/tools/experimental/wikipedia/wikipedia.py +7 -10
- autogen/tools/function_utils.py +7 -7
- autogen/tools/tool.py +8 -6
- autogen/types.py +2 -2
- autogen/version.py +1 -1
- ag2-0.9.7.dist-info/RECORD +0 -421
- autogen/llm_config.py +0 -385
- {ag2-0.9.7.dist-info → ag2-0.9.8.post1.dist-info}/WHEEL +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.8.post1.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.8.post1.dist-info}/licenses/NOTICE.md +0 -0
autogen/cache/redis_cache.py
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import pickle
|
|
8
8
|
import sys
|
|
9
9
|
from types import TracebackType
|
|
10
|
-
from typing import Any
|
|
10
|
+
from typing import Any
|
|
11
11
|
|
|
12
12
|
if sys.version_info >= (3, 11):
|
|
13
13
|
from typing import Self
|
|
@@ -42,7 +42,7 @@ class RedisCache(AbstractCache):
|
|
|
42
42
|
__exit__(self, exc_type, exc_value, traceback): Context management exit.
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
|
-
def __init__(self, seed:
|
|
45
|
+
def __init__(self, seed: str | int, redis_url: str):
|
|
46
46
|
"""Initialize the RedisCache instance.
|
|
47
47
|
|
|
48
48
|
Args:
|
|
@@ -64,7 +64,7 @@ class RedisCache(AbstractCache):
|
|
|
64
64
|
"""
|
|
65
65
|
return f"autogen:{self.seed}:{key}"
|
|
66
66
|
|
|
67
|
-
def get(self, key: str, default:
|
|
67
|
+
def get(self, key: str, default: Any | None = None) -> Any | None:
|
|
68
68
|
"""Retrieve an item from the Redis cache.
|
|
69
69
|
|
|
70
70
|
Args:
|
|
@@ -109,7 +109,7 @@ class RedisCache(AbstractCache):
|
|
|
109
109
|
return self
|
|
110
110
|
|
|
111
111
|
def __exit__(
|
|
112
|
-
self, exc_type:
|
|
112
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
|
113
113
|
) -> None:
|
|
114
114
|
"""Exit the runtime context related to the object.
|
|
115
115
|
|
autogen/code_utils.py
CHANGED
|
@@ -13,18 +13,18 @@ import subprocess
|
|
|
13
13
|
import sys
|
|
14
14
|
import time
|
|
15
15
|
import venv
|
|
16
|
+
from collections.abc import Callable
|
|
16
17
|
from concurrent.futures import ThreadPoolExecutor, TimeoutError
|
|
17
18
|
from hashlib import md5
|
|
18
19
|
from types import SimpleNamespace
|
|
19
|
-
from typing import Callable, Optional, Union
|
|
20
20
|
|
|
21
21
|
import docker
|
|
22
22
|
|
|
23
23
|
from .types import UserMessageImageContentPart, UserMessageTextContentPart
|
|
24
24
|
|
|
25
25
|
SENTINEL = object()
|
|
26
|
-
DEFAULT_MODEL = "gpt-
|
|
27
|
-
FAST_MODEL = "gpt-
|
|
26
|
+
DEFAULT_MODEL = "gpt-5"
|
|
27
|
+
FAST_MODEL = "gpt-5-nano"
|
|
28
28
|
# Regular expression for finding a code block
|
|
29
29
|
# ```[ \t]*(\w+)?[ \t]*\r?\n(.*?)[ \t]*\r?\n``` Matches multi-line code blocks.
|
|
30
30
|
# The [ \t]* matches the potential spaces before language name.
|
|
@@ -46,7 +46,7 @@ PYTHON_VARIANTS = ["python", "Python", "py"]
|
|
|
46
46
|
logger = logging.getLogger(__name__)
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
def content_str(content:
|
|
49
|
+
def content_str(content: str | list[UserMessageTextContentPart | UserMessageImageContentPart] | None) -> str:
|
|
50
50
|
"""Converts the `content` field of an OpenAI message into a string format.
|
|
51
51
|
|
|
52
52
|
This function processes content that may be a string, a list of mixed text and image URLs, or None,
|
|
@@ -107,7 +107,7 @@ def infer_lang(code: str) -> str:
|
|
|
107
107
|
# TODO: In the future move, to better support https://spec.commonmark.org/0.30/#fenced-code-blocks
|
|
108
108
|
# perhaps by using a full Markdown parser.
|
|
109
109
|
def extract_code(
|
|
110
|
-
text:
|
|
110
|
+
text: str | list, pattern: str = CODE_BLOCK_PATTERN, detect_single_line_code: bool = False
|
|
111
111
|
) -> list[tuple[str, str]]:
|
|
112
112
|
"""Extract code from a text.
|
|
113
113
|
|
|
@@ -216,7 +216,7 @@ def in_docker_container() -> bool:
|
|
|
216
216
|
return os.path.exists("/.dockerenv")
|
|
217
217
|
|
|
218
218
|
|
|
219
|
-
def decide_use_docker(use_docker:
|
|
219
|
+
def decide_use_docker(use_docker: bool | None) -> bool | None:
|
|
220
220
|
if use_docker is None:
|
|
221
221
|
env_var_use_docker = os.environ.get("AUTOGEN_USE_DOCKER", "True")
|
|
222
222
|
|
|
@@ -279,13 +279,13 @@ def _sanitize_filename_for_docker_tag(filename: str) -> str:
|
|
|
279
279
|
|
|
280
280
|
|
|
281
281
|
def execute_code(
|
|
282
|
-
code:
|
|
283
|
-
timeout:
|
|
284
|
-
filename:
|
|
285
|
-
work_dir:
|
|
286
|
-
use_docker:
|
|
287
|
-
lang:
|
|
288
|
-
) -> tuple[int, str,
|
|
282
|
+
code: str | None = None,
|
|
283
|
+
timeout: int | None = None,
|
|
284
|
+
filename: str | None = None,
|
|
285
|
+
work_dir: str | None = None,
|
|
286
|
+
use_docker: list[str] | str | bool = SENTINEL,
|
|
287
|
+
lang: str | None = "python",
|
|
288
|
+
) -> tuple[int, str, str | None]:
|
|
289
289
|
"""Execute code in a docker container.
|
|
290
290
|
This function is not tested on MacOS.
|
|
291
291
|
|
|
@@ -491,11 +491,11 @@ def _remove_check(response):
|
|
|
491
491
|
def eval_function_completions(
|
|
492
492
|
responses: list[str],
|
|
493
493
|
definition: str,
|
|
494
|
-
test:
|
|
495
|
-
entry_point:
|
|
496
|
-
assertions:
|
|
497
|
-
timeout:
|
|
498
|
-
use_docker:
|
|
494
|
+
test: str | None = None,
|
|
495
|
+
entry_point: str | None = None,
|
|
496
|
+
assertions: str | Callable[[str], tuple[str, float]] | None = None,
|
|
497
|
+
timeout: float | None = 3,
|
|
498
|
+
use_docker: bool | None = True,
|
|
499
499
|
) -> dict:
|
|
500
500
|
"""`(openai<1)` Select a response from a list of responses for the function completion task (using generated assertions), and/or evaluate if the task is successful using a gold test.
|
|
501
501
|
|
autogen/coding/base.py
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
from collections.abc import Mapping
|
|
10
|
-
from typing import Any, Literal,
|
|
10
|
+
from typing import Any, Literal, Protocol, TypedDict, runtime_checkable
|
|
11
11
|
|
|
12
12
|
from pydantic import BaseModel, Field
|
|
13
13
|
|
|
@@ -40,7 +40,7 @@ class CodeExtractor(Protocol):
|
|
|
40
40
|
"""(Experimental) A code extractor class that extracts code blocks from a message."""
|
|
41
41
|
|
|
42
42
|
def extract_code_blocks(
|
|
43
|
-
self, message:
|
|
43
|
+
self, message: str | list[UserMessageTextContentPart | UserMessageImageContentPart] | None
|
|
44
44
|
) -> list[CodeBlock]:
|
|
45
45
|
"""(Experimental) Extract code blocks from a message.
|
|
46
46
|
|
|
@@ -98,10 +98,10 @@ class IPythonCodeResult(CodeResult):
|
|
|
98
98
|
CodeExecutionConfig = TypedDict(
|
|
99
99
|
"CodeExecutionConfig",
|
|
100
100
|
{
|
|
101
|
-
"executor":
|
|
102
|
-
"last_n_messages":
|
|
101
|
+
"executor": Literal["ipython-embedded", "commandline-local"] | CodeExecutor,
|
|
102
|
+
"last_n_messages": int | Literal["auto"],
|
|
103
103
|
"timeout": int,
|
|
104
|
-
"use_docker":
|
|
104
|
+
"use_docker": bool | str | list[str],
|
|
105
105
|
"work_dir": str,
|
|
106
106
|
"ipython-embedded": Mapping[str, Any],
|
|
107
107
|
"commandline-local": Mapping[str, Any],
|
|
@@ -113,7 +113,7 @@ CodeExecutionConfig = TypedDict(
|
|
|
113
113
|
class CommandLineCodeResult(CodeResult):
|
|
114
114
|
"""(Experimental) A code result class for command line code executor."""
|
|
115
115
|
|
|
116
|
-
code_file:
|
|
116
|
+
code_file: str | None = Field(
|
|
117
117
|
default=None,
|
|
118
118
|
description="The file that the executed code block was saved to.",
|
|
119
119
|
)
|
|
@@ -14,7 +14,7 @@ from hashlib import md5
|
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
from time import sleep
|
|
16
16
|
from types import TracebackType
|
|
17
|
-
from typing import Any, ClassVar
|
|
17
|
+
from typing import Any, ClassVar
|
|
18
18
|
|
|
19
19
|
import docker
|
|
20
20
|
from docker.errors import ImageNotFound
|
|
@@ -64,15 +64,15 @@ class DockerCommandLineCodeExecutor(CodeExecutor):
|
|
|
64
64
|
def __init__(
|
|
65
65
|
self,
|
|
66
66
|
image: str = "python:3-slim",
|
|
67
|
-
container_name:
|
|
67
|
+
container_name: str | None = None,
|
|
68
68
|
timeout: int = 60,
|
|
69
|
-
work_dir:
|
|
70
|
-
bind_dir:
|
|
69
|
+
work_dir: Path | str | None = None,
|
|
70
|
+
bind_dir: Path | str | None = None,
|
|
71
71
|
auto_remove: bool = True,
|
|
72
72
|
stop_container: bool = True,
|
|
73
|
-
execution_policies:
|
|
73
|
+
execution_policies: dict[str, bool] | None = None,
|
|
74
74
|
*,
|
|
75
|
-
container_create_kwargs:
|
|
75
|
+
container_create_kwargs: dict[str, Any] | None = None,
|
|
76
76
|
):
|
|
77
77
|
"""(Experimental) A code executor class that executes code through
|
|
78
78
|
a command line environment in a Docker container.
|
|
@@ -281,8 +281,8 @@ class DockerCommandLineCodeExecutor(CodeExecutor):
|
|
|
281
281
|
|
|
282
282
|
def __exit__(
|
|
283
283
|
self,
|
|
284
|
-
exc_type:
|
|
285
|
-
exc_val:
|
|
286
|
-
exc_tb:
|
|
284
|
+
exc_type: type[BaseException] | None,
|
|
285
|
+
exc_val: BaseException | None,
|
|
286
|
+
exc_tb: TracebackType | None,
|
|
287
287
|
) -> None:
|
|
288
288
|
self.stop()
|
autogen/coding/func_with_reqs.py
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
import functools
|
|
9
9
|
import importlib
|
|
10
10
|
import inspect
|
|
11
|
+
from collections.abc import Callable
|
|
11
12
|
from dataclasses import dataclass, field
|
|
12
13
|
from importlib.abc import SourceLoader
|
|
13
14
|
from textwrap import dedent, indent
|
|
14
|
-
from typing import Any,
|
|
15
|
+
from typing import Any, Generic, TypeVar, Union
|
|
15
16
|
|
|
16
17
|
from typing_extensions import ParamSpec
|
|
17
18
|
|
|
@@ -39,10 +40,10 @@ class Alias:
|
|
|
39
40
|
@dataclass
|
|
40
41
|
class ImportFromModule:
|
|
41
42
|
module: str
|
|
42
|
-
imports: list[
|
|
43
|
+
imports: list[str | Alias]
|
|
43
44
|
|
|
44
45
|
|
|
45
|
-
Import =
|
|
46
|
+
Import = str | ImportFromModule | Alias
|
|
46
47
|
|
|
47
48
|
|
|
48
49
|
def _import_to_str(im: Import) -> str:
|
|
@@ -52,7 +53,7 @@ def _import_to_str(im: Import) -> str:
|
|
|
52
53
|
return f"import {im.name} as {im.alias}"
|
|
53
54
|
else:
|
|
54
55
|
|
|
55
|
-
def to_str(i:
|
|
56
|
+
def to_str(i: str | Alias) -> str:
|
|
56
57
|
if isinstance(i, str):
|
|
57
58
|
return i
|
|
58
59
|
else:
|
|
@@ -161,7 +162,7 @@ def with_requirements(
|
|
|
161
162
|
|
|
162
163
|
|
|
163
164
|
def _build_python_functions_file(
|
|
164
|
-
funcs: list[
|
|
165
|
+
funcs: list[FunctionWithRequirements[Any, P] | Callable[..., Any] | FunctionWithRequirementsStr],
|
|
165
166
|
) -> str:
|
|
166
167
|
# First collect all global imports
|
|
167
168
|
global_imports: set[str] = set()
|
|
@@ -177,7 +178,7 @@ def _build_python_functions_file(
|
|
|
177
178
|
return content
|
|
178
179
|
|
|
179
180
|
|
|
180
|
-
def to_stub(func:
|
|
181
|
+
def to_stub(func: Callable[..., Any] | FunctionWithRequirementsStr) -> str:
|
|
181
182
|
"""Generate a stub for a function as a string
|
|
182
183
|
|
|
183
184
|
Args:
|
autogen/coding/jupyter/base.py
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
from dataclasses import dataclass
|
|
8
|
-
from typing import
|
|
8
|
+
from typing import Protocol, runtime_checkable
|
|
9
9
|
|
|
10
10
|
from ...doc_utils import export_module
|
|
11
11
|
|
|
@@ -19,9 +19,9 @@ class JupyterConnectionInfo:
|
|
|
19
19
|
"""`str` - Host of the Jupyter gateway server"""
|
|
20
20
|
use_https: bool
|
|
21
21
|
"""`bool` - Whether to use HTTPS"""
|
|
22
|
-
port:
|
|
22
|
+
port: int | None = None
|
|
23
23
|
"""`Optional[int]` - Port of the Jupyter gateway server. If None, the default port is used"""
|
|
24
|
-
token:
|
|
24
|
+
token: str | None = None
|
|
25
25
|
"""`Optional[str]` - Token for authentication. If None, no token is used"""
|
|
26
26
|
|
|
27
27
|
|
|
@@ -14,7 +14,6 @@ import sys
|
|
|
14
14
|
import uuid
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
from types import TracebackType
|
|
17
|
-
from typing import Optional
|
|
18
17
|
|
|
19
18
|
import docker
|
|
20
19
|
|
|
@@ -62,8 +61,8 @@ WORKDIR "${HOME}"
|
|
|
62
61
|
def __init__(
|
|
63
62
|
self,
|
|
64
63
|
*,
|
|
65
|
-
custom_image_name:
|
|
66
|
-
container_name:
|
|
64
|
+
custom_image_name: str | None = None,
|
|
65
|
+
container_name: str | None = None,
|
|
67
66
|
auto_remove: bool = True,
|
|
68
67
|
stop_container: bool = True,
|
|
69
68
|
docker_env: dict[str, str] = {},
|
|
@@ -162,6 +161,6 @@ WORKDIR "${HOME}"
|
|
|
162
161
|
return self
|
|
163
162
|
|
|
164
163
|
def __exit__(
|
|
165
|
-
self, exc_type:
|
|
164
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
|
166
165
|
) -> None:
|
|
167
166
|
self.stop()
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
import subprocess
|
|
6
|
+
from collections.abc import Callable
|
|
6
7
|
from functools import lru_cache
|
|
7
8
|
from logging import getLogger
|
|
8
|
-
from typing import
|
|
9
|
+
from typing import TypeVar
|
|
9
10
|
|
|
10
11
|
from ...import_utils import patch_object
|
|
11
12
|
|
|
@@ -20,8 +21,7 @@ def is_jupyter_kernel_gateway_installed() -> bool:
|
|
|
20
21
|
try:
|
|
21
22
|
subprocess.run(
|
|
22
23
|
["jupyter", "kernelgateway", "--version"],
|
|
23
|
-
|
|
24
|
-
stderr=subprocess.PIPE,
|
|
24
|
+
capture_output=True,
|
|
25
25
|
check=True,
|
|
26
26
|
)
|
|
27
27
|
return True
|
|
@@ -12,7 +12,7 @@ import sys
|
|
|
12
12
|
import uuid
|
|
13
13
|
from dataclasses import dataclass
|
|
14
14
|
from types import TracebackType
|
|
15
|
-
from typing import Any,
|
|
15
|
+
from typing import Any, cast
|
|
16
16
|
|
|
17
17
|
from ...doc_utils import export_module
|
|
18
18
|
|
|
@@ -126,7 +126,7 @@ class JupyterKernelClient:
|
|
|
126
126
|
return self
|
|
127
127
|
|
|
128
128
|
def __exit__(
|
|
129
|
-
self, exc_type:
|
|
129
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
|
130
130
|
) -> None:
|
|
131
131
|
self.stop()
|
|
132
132
|
|
|
@@ -154,7 +154,7 @@ class JupyterKernelClient:
|
|
|
154
154
|
self._websocket.send_text(json.dumps(message))
|
|
155
155
|
return message_id
|
|
156
156
|
|
|
157
|
-
def _receive_message(self, timeout_seconds:
|
|
157
|
+
def _receive_message(self, timeout_seconds: float | None) -> dict[str, Any] | None:
|
|
158
158
|
self._websocket.settimeout(timeout_seconds)
|
|
159
159
|
try:
|
|
160
160
|
data = self._websocket.recv()
|
|
@@ -164,7 +164,7 @@ class JupyterKernelClient:
|
|
|
164
164
|
except websocket.WebSocketTimeoutException:
|
|
165
165
|
return None
|
|
166
166
|
|
|
167
|
-
def wait_for_ready(self, timeout_seconds:
|
|
167
|
+
def wait_for_ready(self, timeout_seconds: float | None = None) -> bool:
|
|
168
168
|
message_id = self._send_message(content={}, channel="shell", message_type="kernel_info_request")
|
|
169
169
|
while True:
|
|
170
170
|
message = self._receive_message(timeout_seconds)
|
|
@@ -177,7 +177,7 @@ class JupyterKernelClient:
|
|
|
177
177
|
):
|
|
178
178
|
return True
|
|
179
179
|
|
|
180
|
-
def execute(self, code: str, timeout_seconds:
|
|
180
|
+
def execute(self, code: str, timeout_seconds: float | None = None) -> ExecutionResult:
|
|
181
181
|
message_id = self._send_message(
|
|
182
182
|
content={
|
|
183
183
|
"code": code,
|
|
@@ -11,7 +11,6 @@ import sys
|
|
|
11
11
|
import uuid
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
from types import TracebackType
|
|
14
|
-
from typing import Optional, Union
|
|
15
14
|
|
|
16
15
|
from ...doc_utils import export_module
|
|
17
16
|
|
|
@@ -31,10 +30,10 @@ from .jupyter_client import JupyterClient
|
|
|
31
30
|
class JupyterCodeExecutor(CodeExecutor):
|
|
32
31
|
def __init__(
|
|
33
32
|
self,
|
|
34
|
-
jupyter_server:
|
|
33
|
+
jupyter_server: JupyterConnectable | JupyterConnectionInfo,
|
|
35
34
|
kernel_name: str = "python3",
|
|
36
35
|
timeout: int = 60,
|
|
37
|
-
output_dir:
|
|
36
|
+
output_dir: Path | str = Path(),
|
|
38
37
|
):
|
|
39
38
|
"""(Experimental) A code executor class that executes code statefully using
|
|
40
39
|
a Jupyter server supplied to this class.
|
|
@@ -155,6 +154,6 @@ class JupyterCodeExecutor(CodeExecutor):
|
|
|
155
154
|
return self
|
|
156
155
|
|
|
157
156
|
def __exit__(
|
|
158
|
-
self, exc_type:
|
|
157
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
|
159
158
|
) -> None:
|
|
160
159
|
self.stop()
|
|
@@ -13,7 +13,6 @@ import signal
|
|
|
13
13
|
import subprocess
|
|
14
14
|
import sys
|
|
15
15
|
from types import TracebackType
|
|
16
|
-
from typing import Optional
|
|
17
16
|
|
|
18
17
|
from ...doc_utils import export_module
|
|
19
18
|
|
|
@@ -36,7 +35,7 @@ class LocalJupyterServer(JupyterConnectable):
|
|
|
36
35
|
def __init__(
|
|
37
36
|
self,
|
|
38
37
|
ip: str = "127.0.0.1",
|
|
39
|
-
port:
|
|
38
|
+
port: int | None = None,
|
|
40
39
|
token: str | GenerateToken = GenerateToken(),
|
|
41
40
|
log_file: str = "jupyter_gateway.log",
|
|
42
41
|
log_level: str = "INFO",
|
|
@@ -54,9 +53,6 @@ class LocalJupyterServer(JupyterConnectable):
|
|
|
54
53
|
log_max_bytes (int, optional): Max logfile size. Defaults to 1048576.
|
|
55
54
|
log_backup_count (int, optional): Number of backups for rotating log. Defaults to 3.
|
|
56
55
|
"""
|
|
57
|
-
# Remove as soon as https://github.com/jupyter-server/kernel_gateway/issues/398 is fixed
|
|
58
|
-
if sys.platform == "win32":
|
|
59
|
-
raise ValueError("LocalJupyterServer is not supported on Windows due to kernelgateway bug.")
|
|
60
56
|
|
|
61
57
|
# Check Jupyter gateway server is installed
|
|
62
58
|
try:
|
|
@@ -167,6 +163,6 @@ class LocalJupyterServer(JupyterConnectable):
|
|
|
167
163
|
return self
|
|
168
164
|
|
|
169
165
|
def __exit__(
|
|
170
|
-
self, exc_type:
|
|
166
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
|
171
167
|
) -> None:
|
|
172
168
|
self.stop()
|
|
@@ -10,11 +10,12 @@ import re
|
|
|
10
10
|
import subprocess
|
|
11
11
|
import sys
|
|
12
12
|
import warnings
|
|
13
|
+
from collections.abc import Callable
|
|
13
14
|
from hashlib import md5
|
|
14
15
|
from pathlib import Path
|
|
15
16
|
from string import Template
|
|
16
17
|
from types import SimpleNamespace
|
|
17
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, ClassVar
|
|
18
19
|
|
|
19
20
|
from typing_extensions import ParamSpec
|
|
20
21
|
|
|
@@ -73,11 +74,11 @@ $functions"""
|
|
|
73
74
|
def __init__(
|
|
74
75
|
self,
|
|
75
76
|
timeout: int = 60,
|
|
76
|
-
virtual_env_context:
|
|
77
|
-
work_dir:
|
|
78
|
-
functions: list[
|
|
77
|
+
virtual_env_context: SimpleNamespace | None = None,
|
|
78
|
+
work_dir: Path | str = Path(),
|
|
79
|
+
functions: list[FunctionWithRequirements[Any, A] | Callable[..., Any] | FunctionWithRequirementsStr] = [],
|
|
79
80
|
functions_module: str = "functions",
|
|
80
|
-
execution_policies:
|
|
81
|
+
execution_policies: dict[str, bool] | None = None,
|
|
81
82
|
):
|
|
82
83
|
"""(Experimental) A code executor class that executes or saves LLM generated code a local command line
|
|
83
84
|
environment.
|
|
@@ -128,7 +129,7 @@ $functions"""
|
|
|
128
129
|
|
|
129
130
|
self._timeout = timeout
|
|
130
131
|
self._work_dir: Path = work_dir
|
|
131
|
-
self._virtual_env_context:
|
|
132
|
+
self._virtual_env_context: SimpleNamespace | None = virtual_env_context
|
|
132
133
|
|
|
133
134
|
self._functions = functions
|
|
134
135
|
# Setup could take some time so we intentionally wait for the first code block to do it.
|
|
@@ -168,7 +169,7 @@ $functions"""
|
|
|
168
169
|
@property
|
|
169
170
|
def functions(
|
|
170
171
|
self,
|
|
171
|
-
) -> list[
|
|
172
|
+
) -> list[FunctionWithRequirements[Any, A] | Callable[..., Any] | FunctionWithRequirementsStr]:
|
|
172
173
|
"""(Experimental) The functions that are available to the code executor."""
|
|
173
174
|
return self._functions
|
|
174
175
|
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import re
|
|
8
|
-
from typing import Union
|
|
9
8
|
|
|
10
9
|
from ..code_utils import CODE_BLOCK_PATTERN, UNKNOWN, content_str, infer_lang
|
|
11
10
|
from ..doc_utils import export_module
|
|
@@ -20,7 +19,7 @@ class MarkdownCodeExtractor(CodeExtractor):
|
|
|
20
19
|
"""(Experimental) A class that extracts code blocks from a message using Markdown syntax."""
|
|
21
20
|
|
|
22
21
|
def extract_code_blocks(
|
|
23
|
-
self, message:
|
|
22
|
+
self, message: str | list[UserMessageTextContentPart | UserMessageImageContentPart] | None
|
|
24
23
|
) -> list[CodeBlock]:
|
|
25
24
|
"""(Experimental) Extract code blocks from a message. If no code blocks are found,
|
|
26
25
|
return an empty list.
|
autogen/coding/utils.py
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
# Will return the filename relative to the workspace path
|
|
8
8
|
import re
|
|
9
9
|
from pathlib import Path
|
|
10
|
-
from typing import Optional
|
|
11
10
|
|
|
12
11
|
filename_patterns = [
|
|
13
12
|
re.compile(r"^<!-- (filename:)?(.+?) -->", re.DOTALL),
|
|
@@ -18,7 +17,7 @@ filename_patterns = [
|
|
|
18
17
|
|
|
19
18
|
|
|
20
19
|
# Raises ValueError if the file is not in the workspace
|
|
21
|
-
def _get_file_name_from_content(code: str, workspace_path: Path) ->
|
|
20
|
+
def _get_file_name_from_content(code: str, workspace_path: Path) -> str | None:
|
|
22
21
|
first_line = code.split("\n")[0].strip()
|
|
23
22
|
# TODO - support other languages
|
|
24
23
|
for pattern in filename_patterns:
|
autogen/doc_utils.py
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
__all__ = ["export_module"]
|
|
6
6
|
|
|
7
|
-
from
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
from typing import TypeVar
|
|
8
9
|
|
|
9
10
|
T = TypeVar("T")
|
|
10
11
|
|
|
@@ -25,7 +26,7 @@ def export_module(module: str) -> Callable[[T], T]:
|
|
|
25
26
|
return decorator
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
def get_target_module(obj: object) ->
|
|
29
|
+
def get_target_module(obj: object) -> str | None:
|
|
29
30
|
"""Get the target module where an object should be documented."""
|
|
30
31
|
if not hasattr(obj, "__module__"):
|
|
31
32
|
return None
|
|
@@ -8,7 +8,7 @@ import shutil
|
|
|
8
8
|
import subprocess
|
|
9
9
|
import tempfile
|
|
10
10
|
import uuid
|
|
11
|
-
from typing import Any
|
|
11
|
+
from typing import Any
|
|
12
12
|
|
|
13
13
|
from asyncer import asyncify
|
|
14
14
|
|
|
@@ -24,19 +24,18 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
24
24
|
self,
|
|
25
25
|
image: str = "python:3.11-slim",
|
|
26
26
|
container_name_prefix: str = "ag2_docker_env_",
|
|
27
|
-
volumes:
|
|
28
|
-
environment:
|
|
29
|
-
network:
|
|
30
|
-
pip_packages:
|
|
31
|
-
requirements_file:
|
|
32
|
-
dockerfile:
|
|
33
|
-
build_args:
|
|
27
|
+
volumes: dict[str, str] | None = None,
|
|
28
|
+
environment: dict[str, str] | None = None,
|
|
29
|
+
network: str | None = None,
|
|
30
|
+
pip_packages: list[str] | None = None,
|
|
31
|
+
requirements_file: str | None = None,
|
|
32
|
+
dockerfile: str | None = None,
|
|
33
|
+
build_args: dict[str, str] | None = None,
|
|
34
34
|
cleanup_container: bool = True,
|
|
35
35
|
keep_container_running: bool = False,
|
|
36
36
|
container_startup_timeout: int = 30,
|
|
37
37
|
):
|
|
38
|
-
"""
|
|
39
|
-
Initialize a Docker Python environment.
|
|
38
|
+
"""Initialize a Docker Python environment.
|
|
40
39
|
|
|
41
40
|
Args:
|
|
42
41
|
image: Docker image to use (ignored if dockerfile is provided)
|
|
@@ -99,8 +98,7 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
99
98
|
subprocess.run(
|
|
100
99
|
["docker", "pull", self.image],
|
|
101
100
|
check=True,
|
|
102
|
-
|
|
103
|
-
stderr=subprocess.PIPE,
|
|
101
|
+
capture_output=True,
|
|
104
102
|
text=True,
|
|
105
103
|
)
|
|
106
104
|
logging.info(f"Pulled Docker image: {self.image}")
|
|
@@ -133,8 +131,7 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
133
131
|
_ = subprocess.run(
|
|
134
132
|
build_cmd,
|
|
135
133
|
check=True,
|
|
136
|
-
|
|
137
|
-
stderr=subprocess.PIPE,
|
|
134
|
+
capture_output=True,
|
|
138
135
|
text=True,
|
|
139
136
|
)
|
|
140
137
|
logging.info(f"Built custom Docker image: {self._custom_image_name}")
|
|
@@ -185,8 +182,7 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
185
182
|
result = subprocess.run(
|
|
186
183
|
run_cmd,
|
|
187
184
|
check=True,
|
|
188
|
-
|
|
189
|
-
stderr=subprocess.PIPE,
|
|
185
|
+
capture_output=True,
|
|
190
186
|
text=True,
|
|
191
187
|
)
|
|
192
188
|
|
|
@@ -211,8 +207,7 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
211
207
|
_ = subprocess.run(
|
|
212
208
|
["docker", "exec", self._container_name, "pip", "install", "--no-cache-dir"] + self.pip_packages,
|
|
213
209
|
check=True,
|
|
214
|
-
|
|
215
|
-
stderr=subprocess.PIPE,
|
|
210
|
+
capture_output=True,
|
|
216
211
|
text=True,
|
|
217
212
|
)
|
|
218
213
|
logging.info("Successfully installed pip packages")
|
|
@@ -241,8 +236,7 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
241
236
|
f"/workspace/{req_filename}",
|
|
242
237
|
],
|
|
243
238
|
check=True,
|
|
244
|
-
|
|
245
|
-
stderr=subprocess.PIPE,
|
|
239
|
+
capture_output=True,
|
|
246
240
|
text=True,
|
|
247
241
|
)
|
|
248
242
|
logging.info("Successfully installed requirements")
|
|
@@ -261,8 +255,7 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
261
255
|
subprocess.run(
|
|
262
256
|
["docker", "stop", self._container_name],
|
|
263
257
|
check=True,
|
|
264
|
-
|
|
265
|
-
stderr=subprocess.PIPE,
|
|
258
|
+
capture_output=True,
|
|
266
259
|
text=True,
|
|
267
260
|
)
|
|
268
261
|
except subprocess.CalledProcessError:
|
|
@@ -275,8 +268,7 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
275
268
|
subprocess.run(
|
|
276
269
|
["docker", "rm", "-f", self._container_name],
|
|
277
270
|
check=True,
|
|
278
|
-
|
|
279
|
-
stderr=subprocess.PIPE,
|
|
271
|
+
capture_output=True,
|
|
280
272
|
text=True,
|
|
281
273
|
)
|
|
282
274
|
except subprocess.CalledProcessError:
|
|
@@ -289,8 +281,7 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
289
281
|
subprocess.run(
|
|
290
282
|
["docker", "rmi", self._custom_image_name],
|
|
291
283
|
check=True,
|
|
292
|
-
|
|
293
|
-
stderr=subprocess.PIPE,
|
|
284
|
+
capture_output=True,
|
|
294
285
|
text=True,
|
|
295
286
|
)
|
|
296
287
|
except subprocess.CalledProcessError:
|
|
@@ -350,9 +341,8 @@ class DockerPythonEnvironment(PythonEnvironment):
|
|
|
350
341
|
except Exception as e:
|
|
351
342
|
return {"success": False, "error": f"Execution error: {str(e)}"}
|
|
352
343
|
|
|
353
|
-
def _run_subprocess_with_timeout(self, cmd: list[str], timeout: int) ->
|
|
354
|
-
"""
|
|
355
|
-
Run a subprocess with timeout and return status, stdout, stderr, and return code.
|
|
344
|
+
def _run_subprocess_with_timeout(self, cmd: list[str], timeout: int) -> tuple[bool, str, str, int]:
|
|
345
|
+
"""Run a subprocess with timeout and return status, stdout, stderr, and return code.
|
|
356
346
|
|
|
357
347
|
Args:
|
|
358
348
|
cmd: Command to run as a list of strings
|