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
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
|
|
8
8
|
from abc import ABC
|
|
9
|
-
from typing import Any,
|
|
9
|
+
from typing import Any, TypeVar
|
|
10
10
|
|
|
11
11
|
Cls = TypeVar("Cls", bound="CustomField")
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class CustomField(ABC):
|
|
15
|
-
param_name:
|
|
15
|
+
param_name: str | None
|
|
16
16
|
cast: bool
|
|
17
17
|
required: bool
|
|
18
18
|
|
|
@@ -38,9 +38,9 @@ class CustomField(ABC):
|
|
|
38
38
|
self.param_name = name
|
|
39
39
|
return self
|
|
40
40
|
|
|
41
|
-
def use(self, /, **kwargs: Any) ->
|
|
41
|
+
def use(self, /, **kwargs: Any) -> dict[str, Any]:
|
|
42
42
|
assert self.param_name, "You should specify `param_name` before using"
|
|
43
43
|
return kwargs
|
|
44
44
|
|
|
45
|
-
def use_field(self, kwargs:
|
|
45
|
+
def use_field(self, kwargs: dict[str, Any]) -> None:
|
|
46
46
|
raise NotImplementedError("You should implement `use_field` method.")
|
autogen/fast_depends/schema.py
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Portions derived from https://github.com/https://github.com/Lancetnik/FastDepends are under the MIT License.
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
10
|
from ._compat import PYDANTIC_V2, create_model, model_schema
|
|
11
11
|
from .core import CallModel
|
|
@@ -15,13 +15,13 @@ def get_schema(
|
|
|
15
15
|
call: CallModel[Any, Any],
|
|
16
16
|
embed: bool = False,
|
|
17
17
|
resolve_refs: bool = False,
|
|
18
|
-
) ->
|
|
18
|
+
) -> dict[str, Any]:
|
|
19
19
|
assert call.model, "Call should has a model"
|
|
20
20
|
params_model = create_model( # type: ignore[call-overload]
|
|
21
21
|
call.model.__name__, **call.flat_params
|
|
22
22
|
)
|
|
23
23
|
|
|
24
|
-
body:
|
|
24
|
+
body: dict[str, Any] = model_schema(params_model)
|
|
25
25
|
|
|
26
26
|
if not call.flat_params:
|
|
27
27
|
body = {"title": body["title"], "type": "null"}
|
|
@@ -37,8 +37,8 @@ def get_schema(
|
|
|
37
37
|
return body
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
def _move_pydantic_refs(original: Any, key: str, refs:
|
|
41
|
-
if not isinstance(original,
|
|
40
|
+
def _move_pydantic_refs(original: Any, key: str, refs: dict[str, Any] | None = None) -> Any:
|
|
41
|
+
if not isinstance(original, dict):
|
|
42
42
|
return original
|
|
43
43
|
|
|
44
44
|
data = original.copy()
|
|
@@ -47,7 +47,7 @@ def _move_pydantic_refs(original: Any, key: str, refs: Optional[Dict[str, Any]]
|
|
|
47
47
|
raw_refs = data.get(key, {})
|
|
48
48
|
refs = _move_pydantic_refs(raw_refs, key, raw_refs)
|
|
49
49
|
|
|
50
|
-
name:
|
|
50
|
+
name: str | None = None
|
|
51
51
|
for k in data:
|
|
52
52
|
if k == "$ref":
|
|
53
53
|
name = data[k].replace(f"#/{key}/", "")
|
|
@@ -55,7 +55,7 @@ def _move_pydantic_refs(original: Any, key: str, refs: Optional[Dict[str, Any]]
|
|
|
55
55
|
elif isinstance(data[k], dict):
|
|
56
56
|
data[k] = _move_pydantic_refs(data[k], key, refs)
|
|
57
57
|
|
|
58
|
-
elif isinstance(data[k],
|
|
58
|
+
elif isinstance(data[k], list):
|
|
59
59
|
for i in range(len(data[k])):
|
|
60
60
|
data[k][i] = _move_pydantic_refs(data[k][i], key, refs)
|
|
61
61
|
|
autogen/fast_depends/use.py
CHANGED
|
@@ -5,18 +5,13 @@
|
|
|
5
5
|
# Portions derived from https://github.com/https://github.com/Lancetnik/FastDepends are under the MIT License.
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
|
|
8
|
+
from collections.abc import AsyncIterator, Callable, Iterator, Sequence
|
|
8
9
|
from contextlib import AsyncExitStack, ExitStack
|
|
9
10
|
from functools import partial, wraps
|
|
10
11
|
from typing import (
|
|
11
12
|
Any,
|
|
12
|
-
AsyncIterator,
|
|
13
|
-
Callable,
|
|
14
|
-
Iterator,
|
|
15
|
-
Optional,
|
|
16
13
|
Protocol,
|
|
17
|
-
Sequence,
|
|
18
14
|
TypeVar,
|
|
19
|
-
Union,
|
|
20
15
|
cast,
|
|
21
16
|
overload,
|
|
22
17
|
)
|
|
@@ -48,7 +43,7 @@ class _InjectWrapper(Protocol[P, T]):
|
|
|
48
43
|
def __call__(
|
|
49
44
|
self,
|
|
50
45
|
func: Callable[P, T],
|
|
51
|
-
model:
|
|
46
|
+
model: CallModel[P, T] | None = None,
|
|
52
47
|
) -> Callable[P, T]: ...
|
|
53
48
|
|
|
54
49
|
|
|
@@ -58,8 +53,8 @@ def inject( # pragma: no cover
|
|
|
58
53
|
*,
|
|
59
54
|
cast: bool = True,
|
|
60
55
|
extra_dependencies: Sequence[model.Depends] = (),
|
|
61
|
-
pydantic_config:
|
|
62
|
-
dependency_overrides_provider:
|
|
56
|
+
pydantic_config: ConfigDict | None = None,
|
|
57
|
+
dependency_overrides_provider: Any | None = dependency_provider,
|
|
63
58
|
wrap_model: Callable[[CallModel[P, T]], CallModel[P, T]] = lambda x: x,
|
|
64
59
|
) -> _InjectWrapper[P, T]: ...
|
|
65
60
|
|
|
@@ -70,24 +65,21 @@ def inject( # pragma: no cover
|
|
|
70
65
|
*,
|
|
71
66
|
cast: bool = True,
|
|
72
67
|
extra_dependencies: Sequence[model.Depends] = (),
|
|
73
|
-
pydantic_config:
|
|
74
|
-
dependency_overrides_provider:
|
|
68
|
+
pydantic_config: ConfigDict | None = None,
|
|
69
|
+
dependency_overrides_provider: Any | None = dependency_provider,
|
|
75
70
|
wrap_model: Callable[[CallModel[P, T]], CallModel[P, T]] = lambda x: x,
|
|
76
71
|
) -> Callable[P, T]: ...
|
|
77
72
|
|
|
78
73
|
|
|
79
74
|
def inject(
|
|
80
|
-
func:
|
|
75
|
+
func: Callable[P, T] | None = None,
|
|
81
76
|
*,
|
|
82
77
|
cast: bool = True,
|
|
83
78
|
extra_dependencies: Sequence[model.Depends] = (),
|
|
84
|
-
pydantic_config:
|
|
85
|
-
dependency_overrides_provider:
|
|
79
|
+
pydantic_config: ConfigDict | None = None,
|
|
80
|
+
dependency_overrides_provider: Any | None = dependency_provider,
|
|
86
81
|
wrap_model: Callable[[CallModel[P, T]], CallModel[P, T]] = lambda x: x,
|
|
87
|
-
) ->
|
|
88
|
-
Callable[P, T],
|
|
89
|
-
_InjectWrapper[P, T],
|
|
90
|
-
]:
|
|
82
|
+
) -> Callable[P, T] | _InjectWrapper[P, T]:
|
|
91
83
|
decorator = _wrap_inject(
|
|
92
84
|
dependency_overrides_provider=dependency_overrides_provider,
|
|
93
85
|
wrap_model=wrap_model,
|
|
@@ -104,14 +96,14 @@ def inject(
|
|
|
104
96
|
|
|
105
97
|
|
|
106
98
|
def _wrap_inject(
|
|
107
|
-
dependency_overrides_provider:
|
|
99
|
+
dependency_overrides_provider: Any | None,
|
|
108
100
|
wrap_model: Callable[
|
|
109
101
|
[CallModel[P, T]],
|
|
110
102
|
CallModel[P, T],
|
|
111
103
|
],
|
|
112
104
|
extra_dependencies: Sequence[model.Depends],
|
|
113
105
|
cast: bool,
|
|
114
|
-
pydantic_config:
|
|
106
|
+
pydantic_config: ConfigDict | None,
|
|
115
107
|
) -> _InjectWrapper[P, T]:
|
|
116
108
|
if (
|
|
117
109
|
dependency_overrides_provider
|
|
@@ -123,7 +115,7 @@ def _wrap_inject(
|
|
|
123
115
|
|
|
124
116
|
def func_wrapper(
|
|
125
117
|
func: Callable[P, T],
|
|
126
|
-
model:
|
|
118
|
+
model: CallModel[P, T] | None = None,
|
|
127
119
|
) -> Callable[P, T]:
|
|
128
120
|
if model is None:
|
|
129
121
|
real_model = wrap_model(
|
|
@@ -187,12 +179,12 @@ def _wrap_inject(
|
|
|
187
179
|
|
|
188
180
|
|
|
189
181
|
class solve_async_gen: # noqa: N801
|
|
190
|
-
_iter:
|
|
182
|
+
_iter: AsyncIterator[Any] | None = None
|
|
191
183
|
|
|
192
184
|
def __init__(
|
|
193
185
|
self,
|
|
194
186
|
model: "CallModel[..., Any]",
|
|
195
|
-
overrides:
|
|
187
|
+
overrides: Any | None,
|
|
196
188
|
*args: Any,
|
|
197
189
|
**kwargs: Any,
|
|
198
190
|
):
|
|
@@ -234,12 +226,12 @@ class solve_async_gen: # noqa: N801
|
|
|
234
226
|
|
|
235
227
|
|
|
236
228
|
class solve_gen: # noqa: N801
|
|
237
|
-
_iter:
|
|
229
|
+
_iter: Iterator[Any] | None = None
|
|
238
230
|
|
|
239
231
|
def __init__(
|
|
240
232
|
self,
|
|
241
233
|
model: "CallModel[..., Any]",
|
|
242
|
-
overrides:
|
|
234
|
+
overrides: Any | None,
|
|
243
235
|
*args: Any,
|
|
244
236
|
**kwargs: Any,
|
|
245
237
|
):
|
autogen/fast_depends/utils.py
CHANGED
|
@@ -8,30 +8,13 @@
|
|
|
8
8
|
import asyncio
|
|
9
9
|
import functools
|
|
10
10
|
import inspect
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
|
|
14
|
-
Any,
|
|
15
|
-
AsyncGenerator,
|
|
16
|
-
AsyncIterable,
|
|
17
|
-
Awaitable,
|
|
18
|
-
Callable,
|
|
19
|
-
ContextManager,
|
|
20
|
-
Dict,
|
|
21
|
-
ForwardRef,
|
|
22
|
-
List,
|
|
23
|
-
Tuple,
|
|
24
|
-
TypeVar,
|
|
25
|
-
Union,
|
|
26
|
-
cast,
|
|
27
|
-
)
|
|
11
|
+
from collections.abc import AsyncGenerator, AsyncIterable, Awaitable, Callable
|
|
12
|
+
from contextlib import AbstractContextManager, AsyncExitStack, ExitStack, asynccontextmanager, contextmanager
|
|
13
|
+
from typing import TYPE_CHECKING, Annotated, Any, ForwardRef, TypeVar, cast, get_args, get_origin
|
|
28
14
|
|
|
29
15
|
import anyio
|
|
30
16
|
from typing_extensions import (
|
|
31
|
-
Annotated,
|
|
32
17
|
ParamSpec,
|
|
33
|
-
get_args,
|
|
34
|
-
get_origin,
|
|
35
18
|
)
|
|
36
19
|
|
|
37
20
|
from ._compat import evaluate_forwardref
|
|
@@ -44,10 +27,7 @@ T = TypeVar("T")
|
|
|
44
27
|
|
|
45
28
|
|
|
46
29
|
async def run_async(
|
|
47
|
-
func:
|
|
48
|
-
Callable[P, T],
|
|
49
|
-
Callable[P, Awaitable[T]],
|
|
50
|
-
],
|
|
30
|
+
func: Callable[P, T] | Callable[P, Awaitable[T]],
|
|
51
31
|
*args: P.args,
|
|
52
32
|
**kwargs: P.kwargs,
|
|
53
33
|
) -> T:
|
|
@@ -78,7 +58,7 @@ def solve_generator_sync(*sub_args: Any, call: Callable[..., Any], stack: ExitSt
|
|
|
78
58
|
return stack.enter_context(cm)
|
|
79
59
|
|
|
80
60
|
|
|
81
|
-
def get_typed_signature(call: Callable[..., Any]) ->
|
|
61
|
+
def get_typed_signature(call: Callable[..., Any]) -> tuple[inspect.Signature, Any]:
|
|
82
62
|
signature = inspect.signature(call)
|
|
83
63
|
|
|
84
64
|
locals = collect_outer_stack_locals()
|
|
@@ -108,10 +88,10 @@ def get_typed_signature(call: Callable[..., Any]) -> Tuple[inspect.Signature, An
|
|
|
108
88
|
)
|
|
109
89
|
|
|
110
90
|
|
|
111
|
-
def collect_outer_stack_locals() ->
|
|
91
|
+
def collect_outer_stack_locals() -> dict[str, Any]:
|
|
112
92
|
frame = inspect.currentframe()
|
|
113
93
|
|
|
114
|
-
frames:
|
|
94
|
+
frames: list[FrameType] = []
|
|
115
95
|
while frame is not None:
|
|
116
96
|
if "fast_depends" not in frame.f_code.co_filename:
|
|
117
97
|
frames.append(frame)
|
|
@@ -126,8 +106,8 @@ def collect_outer_stack_locals() -> Dict[str, Any]:
|
|
|
126
106
|
|
|
127
107
|
def get_typed_annotation(
|
|
128
108
|
annotation: Any,
|
|
129
|
-
globalns:
|
|
130
|
-
locals:
|
|
109
|
+
globalns: dict[str, Any],
|
|
110
|
+
locals: dict[str, Any],
|
|
131
111
|
) -> Any:
|
|
132
112
|
if isinstance(annotation, str):
|
|
133
113
|
annotation = ForwardRef(annotation)
|
|
@@ -144,7 +124,7 @@ def get_typed_annotation(
|
|
|
144
124
|
|
|
145
125
|
@asynccontextmanager
|
|
146
126
|
async def contextmanager_in_threadpool(
|
|
147
|
-
cm:
|
|
127
|
+
cm: AbstractContextManager[T],
|
|
148
128
|
) -> AsyncGenerator[T, None]:
|
|
149
129
|
exit_limiter = anyio.CapacityLimiter(1)
|
|
150
130
|
try:
|
autogen/formatting_utils.py
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
from collections.abc import Iterable
|
|
10
|
-
from typing import Literal
|
|
10
|
+
from typing import Literal
|
|
11
11
|
|
|
12
12
|
from .import_utils import optional_import_block
|
|
13
13
|
|
|
@@ -70,12 +70,12 @@ if not result.is_successful:
|
|
|
70
70
|
|
|
71
71
|
def colored(
|
|
72
72
|
text: object,
|
|
73
|
-
color:
|
|
74
|
-
on_color:
|
|
75
|
-
attrs:
|
|
73
|
+
color: Color | None = None,
|
|
74
|
+
on_color: Highlight | None = None,
|
|
75
|
+
attrs: Iterable[Attribute] | None = None,
|
|
76
76
|
*,
|
|
77
|
-
no_color:
|
|
78
|
-
force_color:
|
|
77
|
+
no_color: bool | None = None,
|
|
78
|
+
force_color: bool | None = None,
|
|
79
79
|
) -> str:
|
|
80
80
|
return str(text)
|
|
81
81
|
|
autogen/graph_utils.py
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
|
|
8
8
|
import logging
|
|
9
|
-
from typing import Optional
|
|
10
9
|
|
|
11
10
|
from .agentchat import Agent
|
|
12
11
|
from .import_utils import optional_import_block, require_optional_import
|
|
@@ -25,7 +24,6 @@ def has_self_loops(allowed_speaker_transitions: dict[str, list[Agent]]) -> bool:
|
|
|
25
24
|
Returns:
|
|
26
25
|
True if there are self loops in the allowed_speaker_transitions_Dict.
|
|
27
26
|
"""
|
|
28
|
-
|
|
29
27
|
return any([key in value for key, value in allowed_speaker_transitions.items()])
|
|
30
28
|
|
|
31
29
|
|
|
@@ -144,7 +142,7 @@ def invert_disallowed_to_allowed(
|
|
|
144
142
|
|
|
145
143
|
@require_optional_import(["matplotlib", "networkx"], "graph")
|
|
146
144
|
def visualize_speaker_transitions_dict(
|
|
147
|
-
speaker_transitions_dict: dict[str, list[Agent]], agents: list[Agent], export_path:
|
|
145
|
+
speaker_transitions_dict: dict[str, list[Agent]], agents: list[Agent], export_path: str | None = None
|
|
148
146
|
) -> None:
|
|
149
147
|
"""Visualize the speaker_transitions_dict using networkx.
|
|
150
148
|
|
|
@@ -158,7 +156,6 @@ def visualize_speaker_transitions_dict(
|
|
|
158
156
|
|
|
159
157
|
|
|
160
158
|
"""
|
|
161
|
-
|
|
162
159
|
g = nx.DiGraph()
|
|
163
160
|
|
|
164
161
|
# Add nodes
|
autogen/import_utils.py
CHANGED
|
@@ -6,12 +6,13 @@ import inspect
|
|
|
6
6
|
import re
|
|
7
7
|
import sys
|
|
8
8
|
from abc import ABC, abstractmethod
|
|
9
|
+
from collections.abc import Callable, Generator, Iterable
|
|
9
10
|
from contextlib import contextmanager, suppress
|
|
10
11
|
from dataclasses import dataclass
|
|
11
12
|
from functools import wraps
|
|
12
13
|
from logging import getLogger
|
|
13
14
|
from pathlib import Path
|
|
14
|
-
from typing import Any,
|
|
15
|
+
from typing import Any, Generic, Optional, TypeVar
|
|
15
16
|
|
|
16
17
|
__all__ = [
|
|
17
18
|
"optional_import_block",
|
|
@@ -27,12 +28,12 @@ logger = getLogger(__name__)
|
|
|
27
28
|
@dataclass
|
|
28
29
|
class ModuleInfo:
|
|
29
30
|
name: str
|
|
30
|
-
min_version:
|
|
31
|
-
max_version:
|
|
31
|
+
min_version: str | None = None
|
|
32
|
+
max_version: str | None = None
|
|
32
33
|
min_inclusive: bool = False
|
|
33
34
|
max_inclusive: bool = False
|
|
34
35
|
|
|
35
|
-
def is_in_sys_modules(self) ->
|
|
36
|
+
def is_in_sys_modules(self) -> str | None:
|
|
36
37
|
"""Check if the module is installed and satisfies the version constraints
|
|
37
38
|
|
|
38
39
|
Returns:
|
|
@@ -95,7 +96,6 @@ class ModuleInfo:
|
|
|
95
96
|
Raises:
|
|
96
97
|
ValueError: If the module information is invalid
|
|
97
98
|
"""
|
|
98
|
-
|
|
99
99
|
pattern = re.compile(r"^(?P<name>[a-zA-Z0-9-_]+)(?P<constraint>.*)$")
|
|
100
100
|
match = pattern.match(module_info.strip())
|
|
101
101
|
|
|
@@ -140,7 +140,7 @@ class ModuleInfo:
|
|
|
140
140
|
|
|
141
141
|
class Result:
|
|
142
142
|
def __init__(self) -> None:
|
|
143
|
-
self._failed:
|
|
143
|
+
self._failed: bool | None = None
|
|
144
144
|
|
|
145
145
|
@property
|
|
146
146
|
def is_successful(self) -> bool:
|
|
@@ -173,7 +173,7 @@ def optional_import_block() -> Generator[Result, None, None]:
|
|
|
173
173
|
result._failed = True
|
|
174
174
|
|
|
175
175
|
|
|
176
|
-
def get_missing_imports(modules:
|
|
176
|
+
def get_missing_imports(modules: str | Iterable[str]) -> dict[str, str]:
|
|
177
177
|
"""Get missing modules from a list of module names
|
|
178
178
|
|
|
179
179
|
Args:
|
|
@@ -191,7 +191,7 @@ def get_missing_imports(modules: Union[str, Iterable[str]]) -> dict[str, str]:
|
|
|
191
191
|
|
|
192
192
|
|
|
193
193
|
T = TypeVar("T")
|
|
194
|
-
G = TypeVar("G", bound=
|
|
194
|
+
G = TypeVar("G", bound=Callable[..., Any] | type)
|
|
195
195
|
F = TypeVar("F", bound=Callable[..., Any])
|
|
196
196
|
|
|
197
197
|
|
|
@@ -401,7 +401,7 @@ def patch_object(
|
|
|
401
401
|
missing_modules: dict[str, str],
|
|
402
402
|
dep_target: str,
|
|
403
403
|
fail_if_not_patchable: bool = True,
|
|
404
|
-
except_for:
|
|
404
|
+
except_for: str | Iterable[str] | None = None,
|
|
405
405
|
) -> T:
|
|
406
406
|
patcher = PatchObject.create(o, missing_modules=missing_modules, dep_target=dep_target)
|
|
407
407
|
if fail_if_not_patchable and patcher is None:
|
|
@@ -414,10 +414,10 @@ def patch_object(
|
|
|
414
414
|
|
|
415
415
|
|
|
416
416
|
def require_optional_import(
|
|
417
|
-
modules:
|
|
417
|
+
modules: str | Iterable[str],
|
|
418
418
|
dep_target: str,
|
|
419
419
|
*,
|
|
420
|
-
except_for:
|
|
420
|
+
except_for: str | Iterable[str] | None = None,
|
|
421
421
|
) -> Callable[[T], T]:
|
|
422
422
|
"""Decorator to handle optional module dependencies
|
|
423
423
|
|
|
@@ -453,7 +453,7 @@ def _mark_object(o: T, dep_target: str) -> T:
|
|
|
453
453
|
return pytest_mark_o # type: ignore[no-any-return]
|
|
454
454
|
|
|
455
455
|
|
|
456
|
-
def run_for_optional_imports(modules:
|
|
456
|
+
def run_for_optional_imports(modules: str | Iterable[str], dep_target: str) -> Callable[[G], G]:
|
|
457
457
|
"""Decorator to run a test if and only if optional modules are installed
|
|
458
458
|
|
|
459
459
|
Args:
|
|
@@ -497,7 +497,7 @@ def run_for_optional_imports(modules: Union[str, Iterable[str]], dep_target: str
|
|
|
497
497
|
return decorator
|
|
498
498
|
|
|
499
499
|
|
|
500
|
-
def skip_on_missing_imports(modules:
|
|
500
|
+
def skip_on_missing_imports(modules: str | Iterable[str], dep_target: str) -> Callable[[T], T]:
|
|
501
501
|
"""Decorator to skip a test if an optional module is missing
|
|
502
502
|
|
|
503
503
|
Args:
|
autogen/interop/crewai/crewai.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import re
|
|
6
6
|
import sys
|
|
7
|
-
from typing import Any
|
|
7
|
+
from typing import Any
|
|
8
8
|
|
|
9
9
|
from ...doc_utils import export_module
|
|
10
10
|
from ...import_utils import optional_import_block, require_optional_import
|
|
@@ -75,7 +75,7 @@ class CrewAIInteroperability:
|
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
@classmethod
|
|
78
|
-
def get_unsupported_reason(cls) ->
|
|
78
|
+
def get_unsupported_reason(cls) -> str | None:
|
|
79
79
|
if sys.version_info < (3, 10) or sys.version_info >= (3, 13):
|
|
80
80
|
return "This submodule is only supported for Python versions 3.10, 3.11, and 3.12"
|
|
81
81
|
|
autogen/interop/interoperable.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import Any,
|
|
5
|
+
from typing import Any, Protocol, runtime_checkable
|
|
6
6
|
|
|
7
7
|
from ..doc_utils import export_module
|
|
8
8
|
from ..tools import Tool
|
|
@@ -35,7 +35,7 @@ class Interoperable(Protocol):
|
|
|
35
35
|
...
|
|
36
36
|
|
|
37
37
|
@classmethod
|
|
38
|
-
def get_unsupported_reason(cls) ->
|
|
38
|
+
def get_unsupported_reason(cls) -> str | None:
|
|
39
39
|
"""Returns the reason for the tool being unsupported.
|
|
40
40
|
|
|
41
41
|
This method should be implemented by any class adhering to the `Interoperable` protocol.
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
from abc import ABC, abstractmethod
|
|
6
|
-
from
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from typing import Any, TypeVar
|
|
7
8
|
|
|
8
9
|
from ...doc_utils import export_module
|
|
9
10
|
from ...import_utils import optional_import_block, require_optional_import
|
|
@@ -33,7 +34,7 @@ class LangChainChatModelFactory(ABC):
|
|
|
33
34
|
_factories: set["LangChainChatModelFactory"] = set()
|
|
34
35
|
|
|
35
36
|
@classmethod
|
|
36
|
-
def create_base_chat_model(cls, llm_config:
|
|
37
|
+
def create_base_chat_model(cls, llm_config: LLMConfig | dict[str, Any]) -> "BaseChatModel": # type: ignore [no-any-unimported]
|
|
37
38
|
first_llm_config = get_first_llm_config(llm_config)
|
|
38
39
|
for factory in LangChainChatModelFactory._factories:
|
|
39
40
|
if factory.accepts(first_llm_config):
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
from typing import Any, Optional
|
|
5
|
+
from typing import Any
|
|
7
6
|
|
|
8
7
|
from ...doc_utils import export_module
|
|
9
8
|
from ...import_utils import optional_import_block, require_optional_import
|
|
@@ -67,10 +66,7 @@ class LangChainInteroperability:
|
|
|
67
66
|
)
|
|
68
67
|
|
|
69
68
|
@classmethod
|
|
70
|
-
def get_unsupported_reason(cls) ->
|
|
71
|
-
if sys.version_info < (3, 9):
|
|
72
|
-
return "This submodule is only supported for Python versions 3.9 and above"
|
|
73
|
-
|
|
69
|
+
def get_unsupported_reason(cls) -> str | None:
|
|
74
70
|
with optional_import_block() as result:
|
|
75
71
|
import langchain_core.tools # noqa: F401
|
|
76
72
|
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
6
|
from abc import ABC, abstractmethod
|
|
7
|
-
from
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
from typing import Any, TypeVar
|
|
8
9
|
|
|
9
10
|
from ...doc_utils import export_module
|
|
10
11
|
from ...llm_config import LLMConfig
|
|
@@ -15,7 +16,7 @@ __all__ = ["LiteLLmConfigFactory"]
|
|
|
15
16
|
T = TypeVar("T", bound="LiteLLmConfigFactory")
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
def get_crawl4ai_version() ->
|
|
19
|
+
def get_crawl4ai_version() -> str | None:
|
|
19
20
|
"""Get the installed crawl4ai version."""
|
|
20
21
|
try:
|
|
21
22
|
import crawl4ai
|
|
@@ -46,9 +47,8 @@ class LiteLLmConfigFactory(ABC):
|
|
|
46
47
|
_factories: set["LiteLLmConfigFactory"] = set()
|
|
47
48
|
|
|
48
49
|
@classmethod
|
|
49
|
-
def create_lite_llm_config(cls, llm_config:
|
|
50
|
-
"""
|
|
51
|
-
Create a lite LLM config compatible with the installed crawl4ai version.
|
|
50
|
+
def create_lite_llm_config(cls, llm_config: LLMConfig | dict[str, Any]) -> dict[str, Any]:
|
|
51
|
+
"""Create a lite LLM config compatible with the installed crawl4ai version.
|
|
52
52
|
|
|
53
53
|
For crawl4ai >=0.5: Returns config with llmConfig parameter
|
|
54
54
|
For crawl4ai <0.5: Returns config with provider parameter (legacy)
|
|
@@ -68,8 +68,7 @@ class LiteLLmConfigFactory(ABC):
|
|
|
68
68
|
|
|
69
69
|
@classmethod
|
|
70
70
|
def _adapt_for_crawl4ai_v05(cls, base_config: dict[str, Any]) -> dict[str, Any]:
|
|
71
|
-
"""
|
|
72
|
-
Adapt the config for crawl4ai >=0.5 by moving deprecated parameters
|
|
71
|
+
"""Adapt the config for crawl4ai >=0.5 by moving deprecated parameters
|
|
73
72
|
into an llmConfig object.
|
|
74
73
|
"""
|
|
75
74
|
adapted_config = base_config.copy()
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import sys
|
|
7
6
|
import warnings
|
|
7
|
+
from collections.abc import Callable
|
|
8
8
|
from functools import wraps
|
|
9
9
|
from inspect import signature
|
|
10
|
-
from typing import Any
|
|
10
|
+
from typing import Any
|
|
11
11
|
|
|
12
12
|
from ...doc_utils import export_module
|
|
13
13
|
from ...import_utils import optional_import_block, require_optional_import
|
|
@@ -55,7 +55,7 @@ class PydanticAIInteroperability:
|
|
|
55
55
|
Raises:
|
|
56
56
|
ValueError: If the tool fails after the maximum number of retries.
|
|
57
57
|
"""
|
|
58
|
-
ctx_typed:
|
|
58
|
+
ctx_typed: RunContext[Any] | None = ctx # type: ignore[no-any-unimported]
|
|
59
59
|
tool_typed: PydanticAITool[Any] = tool # type: ignore[no-any-unimported]
|
|
60
60
|
|
|
61
61
|
max_retries = tool_typed.max_retries if tool_typed.max_retries is not None else 1
|
|
@@ -155,10 +155,7 @@ class PydanticAIInteroperability:
|
|
|
155
155
|
)
|
|
156
156
|
|
|
157
157
|
@classmethod
|
|
158
|
-
def get_unsupported_reason(cls) ->
|
|
159
|
-
if sys.version_info < (3, 9):
|
|
160
|
-
return "This submodule is only supported for Python versions 3.9 and above"
|
|
161
|
-
|
|
158
|
+
def get_unsupported_reason(cls) -> str | None:
|
|
162
159
|
with optional_import_block() as result:
|
|
163
160
|
import pydantic_ai.tools # noqa: F401
|
|
164
161
|
|
autogen/interop/registry.py
CHANGED
autogen/io/base.py
CHANGED
|
@@ -8,7 +8,7 @@ import logging
|
|
|
8
8
|
from collections.abc import Iterator
|
|
9
9
|
from contextlib import contextmanager
|
|
10
10
|
from contextvars import ContextVar
|
|
11
|
-
from typing import Any,
|
|
11
|
+
from typing import Any, Protocol, runtime_checkable
|
|
12
12
|
|
|
13
13
|
from ..doc_utils import export_module
|
|
14
14
|
from ..events.base_event import BaseEvent
|
|
@@ -87,7 +87,7 @@ class AsyncIOStreamProtocol(AsyncInputStream, OutputStream, Protocol):
|
|
|
87
87
|
"""A protocol for input/output streams."""
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
iostream_union =
|
|
90
|
+
iostream_union = IOStreamProtocol | AsyncIOStreamProtocol
|
|
91
91
|
|
|
92
92
|
|
|
93
93
|
@export_module("autogen.io")
|
|
@@ -95,9 +95,9 @@ class IOStream:
|
|
|
95
95
|
"""A protocol for input/output streams."""
|
|
96
96
|
|
|
97
97
|
# ContextVar must be used in multithreaded or async environments
|
|
98
|
-
_default_io_stream: ContextVar[
|
|
98
|
+
_default_io_stream: ContextVar[iostream_union | None] = ContextVar("default_iostream", default=None)
|
|
99
99
|
_default_io_stream.set(None)
|
|
100
|
-
_global_default:
|
|
100
|
+
_global_default: iostream_union | None = None
|
|
101
101
|
|
|
102
102
|
@staticmethod
|
|
103
103
|
def set_global_default(stream: iostream_union) -> None:
|
|
@@ -135,7 +135,7 @@ class IOStream:
|
|
|
135
135
|
|
|
136
136
|
@staticmethod
|
|
137
137
|
@contextmanager
|
|
138
|
-
def set_default(stream:
|
|
138
|
+
def set_default(stream: iostream_union | None) -> Iterator[None]:
|
|
139
139
|
"""Set the default input/output stream.
|
|
140
140
|
|
|
141
141
|
Args:
|