ag2 0.9.7__py3-none-any.whl → 0.9.9__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.9.dist-info}/METADATA +102 -75
- ag2-0.9.9.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 +60 -63
- 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 +38 -27
- 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.9.dist-info}/WHEEL +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import logging
|
|
7
|
-
from typing import
|
|
7
|
+
from typing import Optional
|
|
8
8
|
|
|
9
9
|
from ....import_utils import optional_import_block, require_optional_import
|
|
10
10
|
from .document import Document, DocumentType
|
|
@@ -39,12 +39,12 @@ class Neo4jNativeGraphQueryEngine:
|
|
|
39
39
|
username: str = "neo4j",
|
|
40
40
|
password: str = "password",
|
|
41
41
|
embeddings: Optional["Embedder"] = None,
|
|
42
|
-
embedding_dimension:
|
|
42
|
+
embedding_dimension: int | None = 3072,
|
|
43
43
|
llm: Optional["LLMInterface"] = None,
|
|
44
44
|
query_llm: Optional["LLMInterface"] = None,
|
|
45
|
-
entities:
|
|
46
|
-
relations:
|
|
47
|
-
potential_schema:
|
|
45
|
+
entities: list[str] | None = None,
|
|
46
|
+
relations: list[str] | None = None,
|
|
47
|
+
potential_schema: list[tuple[str, str, str]] | None = None,
|
|
48
48
|
):
|
|
49
49
|
"""Initialize a Neo4j graph query engine.
|
|
50
50
|
|
|
@@ -74,7 +74,7 @@ class Neo4jNativeGraphQueryEngine:
|
|
|
74
74
|
self.relations = relations
|
|
75
75
|
self.potential_schema = potential_schema
|
|
76
76
|
|
|
77
|
-
def init_db(self, input_doc:
|
|
77
|
+
def init_db(self, input_doc: list[Document] | None = None) -> None:
|
|
78
78
|
"""Initialize the Neo4j graph database using the provided input doc.
|
|
79
79
|
Currently this method only supports single document input (only reads the first doc).
|
|
80
80
|
|
|
@@ -189,7 +189,7 @@ class Neo4jNativeGraphQueryEngine:
|
|
|
189
189
|
from_pdf=True,
|
|
190
190
|
)
|
|
191
191
|
|
|
192
|
-
def _build_graph(self, input_doc:
|
|
192
|
+
def _build_graph(self, input_doc: list[Document]) -> None:
|
|
193
193
|
"""Build the knowledge graph using the provided input documents.
|
|
194
194
|
|
|
195
195
|
Args:
|
|
@@ -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
|
|
6
6
|
|
|
7
7
|
from .... import Agent, ConversableAgent
|
|
8
8
|
from .graph_query_engine import GraphStoreQueryResult
|
|
@@ -41,10 +41,10 @@ class Neo4jNativeGraphCapability(GraphRagCapability):
|
|
|
41
41
|
def _reply_using_native_neo4j_query(
|
|
42
42
|
self,
|
|
43
43
|
recipient: ConversableAgent,
|
|
44
|
-
messages:
|
|
45
|
-
sender:
|
|
46
|
-
config:
|
|
47
|
-
) -> tuple[bool,
|
|
44
|
+
messages: list[dict[str, Any]] | None = None,
|
|
45
|
+
sender: Agent | None = None,
|
|
46
|
+
config: Any | None = None,
|
|
47
|
+
) -> tuple[bool, str | dict[str, Any] | None]:
|
|
48
48
|
"""Query Neo4j and return the message. Internally, it uses the Neo4jNativeGraphQueryEngine to query the graph.
|
|
49
49
|
|
|
50
50
|
The agent's system message will be incorporated into the query, if it's not blank.
|
|
@@ -66,7 +66,7 @@ class Neo4jNativeGraphCapability(GraphRagCapability):
|
|
|
66
66
|
|
|
67
67
|
return True, result.answer if result.answer else "I'm sorry, I don't have an answer for that."
|
|
68
68
|
|
|
69
|
-
def _messages_summary(self, messages:
|
|
69
|
+
def _messages_summary(self, messages: dict[str, Any] | str, system_message: str) -> str:
|
|
70
70
|
"""Summarize the messages in the conversation history. Excluding any message with 'tool_calls' and 'tool_responses'
|
|
71
71
|
Includes the 'name' (if it exists) and the 'content', with a new line between each one, like:
|
|
72
72
|
customer:
|
|
@@ -194,7 +194,7 @@ def convert_base64_to_data_uri(base64_image):
|
|
|
194
194
|
|
|
195
195
|
|
|
196
196
|
@require_optional_import("PIL", "unknown")
|
|
197
|
-
def gpt4v_formatter(prompt: str, img_format: str = "uri") -> list[
|
|
197
|
+
def gpt4v_formatter(prompt: str, img_format: str = "uri") -> list[str | dict[str, Any]]:
|
|
198
198
|
"""Formats the input prompt by replacing image tags and returns a list of text and images.
|
|
199
199
|
|
|
200
200
|
Args:
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
#
|
|
5
5
|
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
|
-
from typing import Any
|
|
7
|
+
from typing import Any
|
|
8
8
|
|
|
9
9
|
from ... import OpenAIWrapper
|
|
10
10
|
from ...import_utils import optional_import_block, require_optional_import
|
|
@@ -32,7 +32,7 @@ class LLamaIndexConversableAgent(ConversableAgent):
|
|
|
32
32
|
self,
|
|
33
33
|
name: str,
|
|
34
34
|
llama_index_agent: "AgentRunner",
|
|
35
|
-
description:
|
|
35
|
+
description: str | None = None,
|
|
36
36
|
**kwargs: Any,
|
|
37
37
|
):
|
|
38
38
|
"""Args:
|
|
@@ -65,10 +65,10 @@ class LLamaIndexConversableAgent(ConversableAgent):
|
|
|
65
65
|
|
|
66
66
|
def _generate_oai_reply(
|
|
67
67
|
self,
|
|
68
|
-
messages:
|
|
69
|
-
sender:
|
|
70
|
-
config:
|
|
71
|
-
) -> tuple[bool,
|
|
68
|
+
messages: list[dict[str, Any]] | None = None,
|
|
69
|
+
sender: Agent | None = None,
|
|
70
|
+
config: OpenAIWrapper | None = None,
|
|
71
|
+
) -> tuple[bool, str | dict[str, Any] | None]:
|
|
72
72
|
"""Generate a reply using autogen.oai."""
|
|
73
73
|
user_message, history = self._extract_message_and_history(messages=messages, sender=sender)
|
|
74
74
|
|
|
@@ -80,10 +80,10 @@ class LLamaIndexConversableAgent(ConversableAgent):
|
|
|
80
80
|
|
|
81
81
|
async def _a_generate_oai_reply(
|
|
82
82
|
self,
|
|
83
|
-
messages:
|
|
84
|
-
sender:
|
|
85
|
-
config:
|
|
86
|
-
) -> tuple[bool,
|
|
83
|
+
messages: list[dict[str, Any]] | None = None,
|
|
84
|
+
sender: Agent | None = None,
|
|
85
|
+
config: OpenAIWrapper | None = None,
|
|
86
|
+
) -> tuple[bool, str | dict[str, Any] | None]:
|
|
87
87
|
"""Generate a reply using autogen.oai."""
|
|
88
88
|
user_message, history = self._extract_message_and_history(messages=messages, sender=sender)
|
|
89
89
|
|
|
@@ -96,7 +96,7 @@ class LLamaIndexConversableAgent(ConversableAgent):
|
|
|
96
96
|
return (True, extracted_response)
|
|
97
97
|
|
|
98
98
|
def _extract_message_and_history(
|
|
99
|
-
self, messages:
|
|
99
|
+
self, messages: list[dict[str, Any]] | None = None, sender: Agent | None = None
|
|
100
100
|
) -> tuple[str, list["ChatMessage"]]:
|
|
101
101
|
"""Extract the message and history from the messages."""
|
|
102
102
|
if not messages:
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import json
|
|
8
8
|
import logging
|
|
9
|
-
|
|
9
|
+
import warnings
|
|
10
|
+
from typing import Any
|
|
10
11
|
|
|
11
12
|
import requests
|
|
12
13
|
|
|
@@ -33,7 +34,7 @@ class LLaVAAgent(MultimodalConversableAgent):
|
|
|
33
34
|
def __init__(
|
|
34
35
|
self,
|
|
35
36
|
name: str,
|
|
36
|
-
system_message:
|
|
37
|
+
system_message: tuple[str, list] | None = DEFAULT_LLAVA_SYS_MSG,
|
|
37
38
|
*args,
|
|
38
39
|
**kwargs: Any,
|
|
39
40
|
):
|
|
@@ -84,12 +85,25 @@ class LLaVAAgent(MultimodalConversableAgent):
|
|
|
84
85
|
retry = 10
|
|
85
86
|
while len(out) == 0 and retry > 0:
|
|
86
87
|
# image names will be inferred automatically from llava_call
|
|
88
|
+
if "max_new_tokens" in self.llm_config:
|
|
89
|
+
warnings.warn(
|
|
90
|
+
(
|
|
91
|
+
"`max_new_tokens` is deprecated in `llm_config` for llava agents. "
|
|
92
|
+
"Use `max_tokens` instead. "
|
|
93
|
+
"Scheduled for removal in 0.10.0 version."
|
|
94
|
+
),
|
|
95
|
+
DeprecationWarning,
|
|
96
|
+
)
|
|
97
|
+
max_tokens = self.llm_config["max_new_tokens"]
|
|
98
|
+
else:
|
|
99
|
+
max_tokens = self.llm_config.get("max_tokens")
|
|
100
|
+
|
|
87
101
|
out = llava_call_binary(
|
|
88
102
|
prompt=prompt,
|
|
89
103
|
images=images,
|
|
90
104
|
config_list=self.llm_config["config_list"],
|
|
91
105
|
temperature=self.llm_config.get("temperature", 0.5),
|
|
92
|
-
max_new_tokens=
|
|
106
|
+
max_new_tokens=max_tokens or 2000,
|
|
93
107
|
)
|
|
94
108
|
retry -= 1
|
|
95
109
|
|
|
@@ -169,7 +183,7 @@ def llava_call_binary(
|
|
|
169
183
|
continue
|
|
170
184
|
|
|
171
185
|
|
|
172
|
-
def llava_call(prompt: str, llm_config:
|
|
186
|
+
def llava_call(prompt: str, llm_config: LLMConfig | dict) -> str:
|
|
173
187
|
"""Makes a call to the LLaVA service to generate text based on a given prompt"""
|
|
174
188
|
prompt, images = llava_formatter(prompt, order_image_tokens=False)
|
|
175
189
|
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import os
|
|
8
8
|
import re
|
|
9
|
+
from collections.abc import Callable
|
|
9
10
|
from time import sleep
|
|
10
|
-
from typing import Any,
|
|
11
|
+
from typing import Any, Literal
|
|
11
12
|
|
|
12
13
|
from pydantic import BaseModel, root_validator
|
|
13
14
|
|
|
@@ -141,12 +142,11 @@ class MathUserProxyAgent(UserProxyAgent):
|
|
|
141
142
|
|
|
142
143
|
def __init__(
|
|
143
144
|
self,
|
|
144
|
-
name:
|
|
145
|
-
is_termination_msg:
|
|
146
|
-
|
|
147
|
-
] = _is_termination_msg_mathchat, # terminate if \boxed{} in message
|
|
145
|
+
name: str | None = "MathChatAgent", # default set to MathChatAgent
|
|
146
|
+
is_termination_msg: Callable[[dict[str, Any]], bool]
|
|
147
|
+
| None = _is_termination_msg_mathchat, # terminate if \boxed{} in message
|
|
148
148
|
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER", # Fully automated
|
|
149
|
-
default_auto_reply:
|
|
149
|
+
default_auto_reply: str | dict[str, Any] | None = DEFAULT_REPLY,
|
|
150
150
|
max_invalid_q_per_step=3, # a parameter needed in MathChat
|
|
151
151
|
**kwargs: Any,
|
|
152
152
|
):
|
|
@@ -294,9 +294,9 @@ class MathUserProxyAgent(UserProxyAgent):
|
|
|
294
294
|
|
|
295
295
|
def _generate_math_reply(
|
|
296
296
|
self,
|
|
297
|
-
messages:
|
|
298
|
-
sender:
|
|
299
|
-
config:
|
|
297
|
+
messages: list[dict] | None = None,
|
|
298
|
+
sender: Agent | None = None,
|
|
299
|
+
config: Any | None = None,
|
|
300
300
|
):
|
|
301
301
|
"""Generate an auto reply."""
|
|
302
302
|
if messages is None:
|
|
@@ -366,7 +366,7 @@ class MathUserProxyAgent(UserProxyAgent):
|
|
|
366
366
|
# THE SOFTWARE.
|
|
367
367
|
|
|
368
368
|
|
|
369
|
-
def get_from_dict_or_env(data: dict[str, Any], key: str, env_key: str, default:
|
|
369
|
+
def get_from_dict_or_env(data: dict[str, Any], key: str, env_key: str, default: str | None = None) -> str:
|
|
370
370
|
"""Get a value from a dictionary or an environment variable."""
|
|
371
371
|
if data.get(key):
|
|
372
372
|
return data[key]
|
|
@@ -395,7 +395,7 @@ class WolframAlphaAPIWrapper(BaseModel):
|
|
|
395
395
|
"""
|
|
396
396
|
|
|
397
397
|
wolfram_client: Any #: :meta private:
|
|
398
|
-
wolfram_alpha_appid:
|
|
398
|
+
wolfram_alpha_appid: str | None = None
|
|
399
399
|
|
|
400
400
|
@root_validator(skip_on_failure=True)
|
|
401
401
|
@classmethod
|
|
@@ -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
|
import copy
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
10
|
from ... import OpenAIWrapper
|
|
11
11
|
from ...code_utils import content_str
|
|
@@ -27,7 +27,7 @@ class MultimodalConversableAgent(ConversableAgent):
|
|
|
27
27
|
def __init__(
|
|
28
28
|
self,
|
|
29
29
|
name: str,
|
|
30
|
-
system_message:
|
|
30
|
+
system_message: str | list | None = DEFAULT_LMM_SYS_MSG,
|
|
31
31
|
is_termination_msg: str = None,
|
|
32
32
|
*args,
|
|
33
33
|
**kwargs: Any,
|
|
@@ -61,7 +61,7 @@ class MultimodalConversableAgent(ConversableAgent):
|
|
|
61
61
|
MultimodalConversableAgent.a_generate_oai_reply,
|
|
62
62
|
)
|
|
63
63
|
|
|
64
|
-
def update_system_message(self, system_message:
|
|
64
|
+
def update_system_message(self, system_message: dict[str, Any] | list[str] | str):
|
|
65
65
|
"""Update the system message.
|
|
66
66
|
|
|
67
67
|
Args:
|
|
@@ -71,7 +71,7 @@ class MultimodalConversableAgent(ConversableAgent):
|
|
|
71
71
|
self._oai_system_message[0]["role"] = "system"
|
|
72
72
|
|
|
73
73
|
@staticmethod
|
|
74
|
-
def _message_to_dict(message:
|
|
74
|
+
def _message_to_dict(message: dict[str, Any] | list[str] | str) -> dict:
|
|
75
75
|
"""Convert a message to a dictionary. This implementation
|
|
76
76
|
handles the GPT-4V formatting for easier prompts.
|
|
77
77
|
|
|
@@ -100,10 +100,10 @@ class MultimodalConversableAgent(ConversableAgent):
|
|
|
100
100
|
|
|
101
101
|
def generate_oai_reply(
|
|
102
102
|
self,
|
|
103
|
-
messages:
|
|
104
|
-
sender:
|
|
105
|
-
config:
|
|
106
|
-
) -> tuple[bool,
|
|
103
|
+
messages: list[dict[str, Any]] | None = None,
|
|
104
|
+
sender: Agent | None = None,
|
|
105
|
+
config: OpenAIWrapper | None = None,
|
|
106
|
+
) -> tuple[bool, str | dict[str, Any] | None]:
|
|
107
107
|
"""Generate a reply using autogen.oai."""
|
|
108
108
|
client = self.client if config is None else config
|
|
109
109
|
if client is None:
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
6
|
# SPDX-License-Identifier: MIT
|
|
7
7
|
import warnings
|
|
8
|
-
from
|
|
8
|
+
from collections.abc import Callable
|
|
9
|
+
from typing import Any, Literal, Optional
|
|
9
10
|
|
|
10
11
|
from ...import_utils import optional_import_block, require_optional_import
|
|
11
12
|
from ...retrieve_utils import TEXT_FORMATS, get_files_from_dir, split_files_to_chunks
|
|
@@ -30,8 +31,8 @@ class QdrantRetrieveUserProxyAgent(RetrieveUserProxyAgent):
|
|
|
30
31
|
self,
|
|
31
32
|
name="RetrieveChatAgent", # default set to RetrieveChatAgent
|
|
32
33
|
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "ALWAYS",
|
|
33
|
-
is_termination_msg:
|
|
34
|
-
retrieve_config:
|
|
34
|
+
is_termination_msg: Callable[[dict[str, Any]], bool] | None = None,
|
|
35
|
+
retrieve_config: dict[str, Any] | None = None, # config for the retrieve agent
|
|
35
36
|
**kwargs: Any,
|
|
36
37
|
):
|
|
37
38
|
"""Args:
|
|
@@ -175,7 +176,7 @@ def create_qdrant_from_dir(
|
|
|
175
176
|
quantization_config: Optional["models.QuantizationConfig"] = None,
|
|
176
177
|
hnsw_config: Optional["models.HnswConfigDiff"] = None,
|
|
177
178
|
payload_indexing: bool = False,
|
|
178
|
-
qdrant_client_options:
|
|
179
|
+
qdrant_client_options: dict[str, Any] | None = {},
|
|
179
180
|
):
|
|
180
181
|
"""Create a Qdrant collection from all the files in a given directory, the directory can also be a single file or a
|
|
181
182
|
url to a single file.
|
|
@@ -271,7 +272,7 @@ def query_qdrant(
|
|
|
271
272
|
collection_name: str = "all-my-documents",
|
|
272
273
|
search_string: str = "",
|
|
273
274
|
embedding_model: str = "BAAI/bge-small-en-v1.5",
|
|
274
|
-
qdrant_client_options:
|
|
275
|
+
qdrant_client_options: dict[str, Any] | None = {},
|
|
275
276
|
) -> list[list["QueryResponse"]]:
|
|
276
277
|
"""Perform a similarity search with filters on a Qdrant collection
|
|
277
278
|
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
6
|
import os
|
|
7
|
+
from collections.abc import Sequence
|
|
7
8
|
from pathlib import Path
|
|
8
|
-
from typing import TYPE_CHECKING, Any, Optional
|
|
9
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
9
10
|
|
|
10
11
|
from ....doc_utils import export_module
|
|
11
12
|
from ....import_utils import optional_import_block, require_optional_import
|
|
@@ -37,8 +38,7 @@ logger = logging.getLogger(__name__)
|
|
|
37
38
|
@require_optional_import(["chromadb", "llama_index"], "rag")
|
|
38
39
|
@export_module("autogen.agentchat.contrib.rag")
|
|
39
40
|
class ChromaDBQueryEngine:
|
|
40
|
-
"""
|
|
41
|
-
This engine leverages Chromadb to persist document embeddings in a named collection
|
|
41
|
+
"""This engine leverages Chromadb to persist document embeddings in a named collection
|
|
42
42
|
and LlamaIndex's VectorStoreIndex to efficiently index and retrieve documents, and generate an answer in response
|
|
43
43
|
to natural language queries. Collection can be regarded as an abstraction of group of documents in the database.
|
|
44
44
|
|
|
@@ -51,18 +51,18 @@ class ChromaDBQueryEngine:
|
|
|
51
51
|
|
|
52
52
|
def __init__( # type: ignore[no-any-unimported]
|
|
53
53
|
self,
|
|
54
|
-
host:
|
|
55
|
-
port:
|
|
54
|
+
host: str | None = "localhost",
|
|
55
|
+
port: int | None = 8000,
|
|
56
56
|
settings: Optional["Settings"] = None,
|
|
57
|
-
tenant:
|
|
58
|
-
database:
|
|
59
|
-
embedding_function: "
|
|
60
|
-
metadata:
|
|
57
|
+
tenant: str | None = None,
|
|
58
|
+
database: str | None = None,
|
|
59
|
+
embedding_function: "EmbeddingFunction[Any] | None" = None,
|
|
60
|
+
metadata: dict[str, Any] | None = None,
|
|
61
61
|
llm: Optional["LLM"] = None,
|
|
62
|
-
collection_name:
|
|
62
|
+
collection_name: str | None = None,
|
|
63
63
|
) -> None:
|
|
64
|
-
"""
|
|
65
|
-
|
|
64
|
+
"""Initializes the ChromaDBQueryEngine with db_path, metadata, and embedding function and llm.
|
|
65
|
+
|
|
66
66
|
Args:
|
|
67
67
|
host: The host address of the ChromaDB server. Default is localhost.
|
|
68
68
|
port: The port number of the ChromaDB server. Default is 8000.
|
|
@@ -101,8 +101,8 @@ class ChromaDBQueryEngine:
|
|
|
101
101
|
|
|
102
102
|
def init_db(
|
|
103
103
|
self,
|
|
104
|
-
new_doc_dir:
|
|
105
|
-
new_doc_paths_or_urls:
|
|
104
|
+
new_doc_dir: Path | str | None = None,
|
|
105
|
+
new_doc_paths_or_urls: Sequence[Path | str] | None = None,
|
|
106
106
|
*args: Any,
|
|
107
107
|
**kwargs: Any,
|
|
108
108
|
) -> bool:
|
|
@@ -125,7 +125,6 @@ class ChromaDBQueryEngine:
|
|
|
125
125
|
bool: True if initialization is successful
|
|
126
126
|
|
|
127
127
|
"""
|
|
128
|
-
|
|
129
128
|
self._set_up(overwrite=True)
|
|
130
129
|
documents = self._load_doc(input_dir=new_doc_dir, input_docs=new_doc_paths_or_urls)
|
|
131
130
|
self.index = VectorStoreIndex.from_documents(documents=documents, storage_context=self.storage_context)
|
|
@@ -155,8 +154,8 @@ class ChromaDBQueryEngine:
|
|
|
155
154
|
|
|
156
155
|
def add_docs(
|
|
157
156
|
self,
|
|
158
|
-
new_doc_dir:
|
|
159
|
-
new_doc_paths_or_urls:
|
|
157
|
+
new_doc_dir: Path | str | None = None,
|
|
158
|
+
new_doc_paths_or_urls: Sequence[Path | str] | None = None,
|
|
160
159
|
*args: Any,
|
|
161
160
|
**kwargs: Any,
|
|
162
161
|
) -> None:
|
|
@@ -174,8 +173,7 @@ class ChromaDBQueryEngine:
|
|
|
174
173
|
self.index.insert(doc)
|
|
175
174
|
|
|
176
175
|
def query(self, question: str) -> str:
|
|
177
|
-
"""
|
|
178
|
-
Retrieve information from indexed documents by processing a query using the engine's LLM.
|
|
176
|
+
"""Retrieve information from indexed documents by processing a query using the engine's LLM.
|
|
179
177
|
|
|
180
178
|
Args:
|
|
181
179
|
question: A natural language query string used to search the indexed documents.
|
|
@@ -193,8 +191,7 @@ class ChromaDBQueryEngine:
|
|
|
193
191
|
return str(response)
|
|
194
192
|
|
|
195
193
|
def get_collection_name(self) -> str:
|
|
196
|
-
"""
|
|
197
|
-
Get the name of the collection used by the query engine.
|
|
194
|
+
"""Get the name of the collection used by the query engine.
|
|
198
195
|
|
|
199
196
|
Returns:
|
|
200
197
|
The name of the collection.
|
|
@@ -210,10 +207,10 @@ class ChromaDBQueryEngine:
|
|
|
210
207
|
raise Exception("Query index is not initialized. Please call init_db or connect_db first.")
|
|
211
208
|
|
|
212
209
|
def _set_up(self, overwrite: bool) -> None:
|
|
213
|
-
"""
|
|
214
|
-
Set up ChromaDB and LlamaIndex storage by:
|
|
210
|
+
"""Set up ChromaDB and LlamaIndex storage by:
|
|
215
211
|
1. Initialize the ChromaDB using VectorDBFactory and create a collection with the given name.
|
|
216
212
|
2. Create the LlamaIndex vector store and storage context for the collection.
|
|
213
|
+
|
|
217
214
|
Args:
|
|
218
215
|
overwrite: If True, overwrite the existing collection with the same name.
|
|
219
216
|
"""
|
|
@@ -223,10 +220,9 @@ class ChromaDBQueryEngine:
|
|
|
223
220
|
self.storage_context = StorageContext.from_defaults(vector_store=self.vector_store)
|
|
224
221
|
|
|
225
222
|
def _load_doc( # type: ignore[no-any-unimported]
|
|
226
|
-
self, input_dir:
|
|
223
|
+
self, input_dir: Path | str | None, input_docs: Sequence[Path | str] | None
|
|
227
224
|
) -> Sequence["LlamaDocument"]:
|
|
228
|
-
"""
|
|
229
|
-
Load documents from a directory and/or a sequence of file paths.
|
|
225
|
+
"""Load documents from a directory and/or a sequence of file paths.
|
|
230
226
|
|
|
231
227
|
It uses LlamaIndex's SimpleDirectoryReader that supports multiple file[formats]((https://docs.llamaindex.ai/en/stable/module_guides/loading/simpledirectoryreader/#supported-file-types)).
|
|
232
228
|
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
6
|
import os
|
|
7
|
+
from collections.abc import Sequence
|
|
7
8
|
from pathlib import Path
|
|
8
|
-
from typing import TYPE_CHECKING, Any, Optional
|
|
9
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
9
10
|
|
|
10
11
|
from ....doc_utils import export_module
|
|
11
12
|
from ....import_utils import optional_import_block, require_optional_import
|
|
@@ -33,8 +34,7 @@ logger = logging.getLogger(__name__)
|
|
|
33
34
|
@require_optional_import("llama_index", "rag")
|
|
34
35
|
@export_module("autogen.agentchat.contrib.rag")
|
|
35
36
|
class LlamaIndexQueryEngine:
|
|
36
|
-
"""
|
|
37
|
-
This engine leverages LlamaIndex's VectorStoreIndex to efficiently index and retrieve documents, and generate an answer in response
|
|
37
|
+
"""This engine leverages LlamaIndex's VectorStoreIndex to efficiently index and retrieve documents, and generate an answer in response
|
|
38
38
|
to natural language queries. It use any LlamaIndex [vector store](https://docs.llamaindex.ai/en/stable/module_guides/storing/vector_stores/).
|
|
39
39
|
|
|
40
40
|
By default the engine will use OpenAI's GPT-4o model (use the `llm` parameter to change that).
|
|
@@ -44,10 +44,10 @@ class LlamaIndexQueryEngine:
|
|
|
44
44
|
self,
|
|
45
45
|
vector_store: "BasePydanticVectorStore",
|
|
46
46
|
llm: Optional["LLM"] = None,
|
|
47
|
-
file_reader_class:
|
|
47
|
+
file_reader_class: type["SimpleDirectoryReader"] | None = None,
|
|
48
48
|
) -> None:
|
|
49
|
-
"""
|
|
50
|
-
|
|
49
|
+
"""Initializes the LlamaIndexQueryEngine with the given vector store.
|
|
50
|
+
|
|
51
51
|
Args:
|
|
52
52
|
vector_store: The vector store to use for indexing and querying documents.
|
|
53
53
|
llm: LLM model used by LlamaIndex for query processing. You can find more supported LLMs at [LLM](https://docs.llamaindex.ai/en/stable/module_guides/models/llms/).
|
|
@@ -59,8 +59,8 @@ class LlamaIndexQueryEngine:
|
|
|
59
59
|
|
|
60
60
|
def init_db(
|
|
61
61
|
self,
|
|
62
|
-
new_doc_dir:
|
|
63
|
-
new_doc_paths_or_urls:
|
|
62
|
+
new_doc_dir: Path | str | None = None,
|
|
63
|
+
new_doc_paths_or_urls: Sequence[Path | str] | None = None,
|
|
64
64
|
*args: Any,
|
|
65
65
|
**kwargs: Any,
|
|
66
66
|
) -> bool:
|
|
@@ -80,7 +80,6 @@ class LlamaIndexQueryEngine:
|
|
|
80
80
|
bool: True if initialization is successful
|
|
81
81
|
|
|
82
82
|
"""
|
|
83
|
-
|
|
84
83
|
self.storage_context = StorageContext.from_defaults(vector_store=self.vector_store)
|
|
85
84
|
documents = self._load_doc(input_dir=new_doc_dir, input_docs=new_doc_paths_or_urls)
|
|
86
85
|
self.index = VectorStoreIndex.from_documents(documents=documents, storage_context=self.storage_context)
|
|
@@ -106,8 +105,8 @@ class LlamaIndexQueryEngine:
|
|
|
106
105
|
|
|
107
106
|
def add_docs(
|
|
108
107
|
self,
|
|
109
|
-
new_doc_dir:
|
|
110
|
-
new_doc_paths_or_urls:
|
|
108
|
+
new_doc_dir: Path | str | None = None,
|
|
109
|
+
new_doc_paths_or_urls: Sequence[Path | str] | None = None,
|
|
111
110
|
*args: Any,
|
|
112
111
|
**kwargs: Any,
|
|
113
112
|
) -> None:
|
|
@@ -125,8 +124,7 @@ class LlamaIndexQueryEngine:
|
|
|
125
124
|
self.index.insert(doc)
|
|
126
125
|
|
|
127
126
|
def query(self, question: str) -> str:
|
|
128
|
-
"""
|
|
129
|
-
Retrieve information from indexed documents by processing a query using the engine's LLM.
|
|
127
|
+
"""Retrieve information from indexed documents by processing a query using the engine's LLM.
|
|
130
128
|
|
|
131
129
|
Args:
|
|
132
130
|
question: A natural language query string used to search the indexed documents.
|
|
@@ -149,10 +147,9 @@ class LlamaIndexQueryEngine:
|
|
|
149
147
|
raise Exception("Query index is not initialized. Please call init_db or connect_db first.")
|
|
150
148
|
|
|
151
149
|
def _load_doc( # type: ignore[no-any-unimported]
|
|
152
|
-
self, input_dir:
|
|
150
|
+
self, input_dir: Path | str | None, input_docs: Sequence[Path | str] | None
|
|
153
151
|
) -> Sequence["LlamaDocument"]:
|
|
154
|
-
"""
|
|
155
|
-
Load documents from a directory and/or a sequence of file paths.
|
|
152
|
+
"""Load documents from a directory and/or a sequence of file paths.
|
|
156
153
|
|
|
157
154
|
Default to uses LlamaIndex's SimpleDirectoryReader that supports multiple file[formats](https://docs.llamaindex.ai/en/stable/module_guides/loading/simpledirectoryreader/#supported-file-types).
|
|
158
155
|
|
|
@@ -170,7 +167,7 @@ class LlamaIndexQueryEngine:
|
|
|
170
167
|
ValueError: If any provided file path does not exist.
|
|
171
168
|
ValueError: If neither input_dir nor input_docs is provided.
|
|
172
169
|
"""
|
|
173
|
-
loaded_documents: list[
|
|
170
|
+
loaded_documents: list[LlamaDocument] = [] # type: ignore[no-any-unimported]
|
|
174
171
|
if input_dir:
|
|
175
172
|
logger.info(f"Loading docs from directory: {input_dir}")
|
|
176
173
|
if not os.path.exists(input_dir):
|