ag2 0.9.1a1__py3-none-any.whl → 0.9.2__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.1a1.dist-info → ag2-0.9.2.dist-info}/METADATA +272 -75
- ag2-0.9.2.dist-info/RECORD +406 -0
- {ag2-0.9.1a1.dist-info → ag2-0.9.2.dist-info}/WHEEL +1 -2
- autogen/__init__.py +89 -0
- autogen/_website/__init__.py +3 -0
- autogen/_website/generate_api_references.py +427 -0
- autogen/_website/generate_mkdocs.py +1174 -0
- autogen/_website/notebook_processor.py +476 -0
- autogen/_website/process_notebooks.py +656 -0
- autogen/_website/utils.py +412 -0
- autogen/agentchat/__init__.py +44 -0
- autogen/agentchat/agent.py +182 -0
- autogen/agentchat/assistant_agent.py +85 -0
- autogen/agentchat/chat.py +309 -0
- autogen/agentchat/contrib/__init__.py +5 -0
- autogen/agentchat/contrib/agent_eval/README.md +7 -0
- autogen/agentchat/contrib/agent_eval/agent_eval.py +108 -0
- autogen/agentchat/contrib/agent_eval/criterion.py +43 -0
- autogen/agentchat/contrib/agent_eval/critic_agent.py +44 -0
- autogen/agentchat/contrib/agent_eval/quantifier_agent.py +39 -0
- autogen/agentchat/contrib/agent_eval/subcritic_agent.py +45 -0
- autogen/agentchat/contrib/agent_eval/task.py +42 -0
- autogen/agentchat/contrib/agent_optimizer.py +429 -0
- autogen/agentchat/contrib/capabilities/__init__.py +5 -0
- autogen/agentchat/contrib/capabilities/agent_capability.py +20 -0
- autogen/agentchat/contrib/capabilities/generate_images.py +301 -0
- autogen/agentchat/contrib/capabilities/teachability.py +393 -0
- autogen/agentchat/contrib/capabilities/text_compressors.py +66 -0
- autogen/agentchat/contrib/capabilities/tools_capability.py +22 -0
- autogen/agentchat/contrib/capabilities/transform_messages.py +93 -0
- autogen/agentchat/contrib/capabilities/transforms.py +566 -0
- autogen/agentchat/contrib/capabilities/transforms_util.py +122 -0
- autogen/agentchat/contrib/capabilities/vision_capability.py +214 -0
- autogen/agentchat/contrib/captainagent/__init__.py +9 -0
- autogen/agentchat/contrib/captainagent/agent_builder.py +790 -0
- autogen/agentchat/contrib/captainagent/captainagent.py +512 -0
- autogen/agentchat/contrib/captainagent/tool_retriever.py +335 -0
- autogen/agentchat/contrib/captainagent/tools/README.md +44 -0
- autogen/agentchat/contrib/captainagent/tools/__init__.py +5 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_correlation.py +40 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_skewness_and_kurtosis.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_iqr.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_zscore.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/explore_csv.py +21 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/shapiro_wilk_test.py +30 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_download.py +27 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_search.py +53 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_image.py +53 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_text.py +38 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_wikipedia_text.py +21 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_youtube_caption.py +34 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/image_qa.py +60 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/optical_character_recognition.py +61 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/perform_web_search.py +47 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/scrape_wikipedia_tables.py +33 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/transcribe_audio_file.py +21 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/youtube_download.py +35 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_circle_area_from_diameter.py +21 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_day_of_the_week.py +18 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_fraction_sum.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_matrix_power.py +31 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_reflected_point.py +16 -0
- autogen/agentchat/contrib/captainagent/tools/math/complex_numbers_product.py +25 -0
- autogen/agentchat/contrib/captainagent/tools/math/compute_currency_conversion.py +23 -0
- autogen/agentchat/contrib/captainagent/tools/math/count_distinct_permutations.py +27 -0
- autogen/agentchat/contrib/captainagent/tools/math/evaluate_expression.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/math/find_continuity_point.py +34 -0
- autogen/agentchat/contrib/captainagent/tools/math/fraction_to_mixed_numbers.py +39 -0
- autogen/agentchat/contrib/captainagent/tools/math/modular_inverse_sum.py +23 -0
- autogen/agentchat/contrib/captainagent/tools/math/simplify_mixed_numbers.py +36 -0
- autogen/agentchat/contrib/captainagent/tools/math/sum_of_digit_factorials.py +15 -0
- autogen/agentchat/contrib/captainagent/tools/math/sum_of_primes_below.py +15 -0
- autogen/agentchat/contrib/captainagent/tools/requirements.txt +10 -0
- autogen/agentchat/contrib/captainagent/tools/tool_description.tsv +34 -0
- autogen/agentchat/contrib/gpt_assistant_agent.py +526 -0
- autogen/agentchat/contrib/graph_rag/__init__.py +9 -0
- autogen/agentchat/contrib/graph_rag/document.py +29 -0
- autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +170 -0
- autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +103 -0
- autogen/agentchat/contrib/graph_rag/graph_query_engine.py +53 -0
- autogen/agentchat/contrib/graph_rag/graph_rag_capability.py +63 -0
- autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py +268 -0
- autogen/agentchat/contrib/graph_rag/neo4j_graph_rag_capability.py +83 -0
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_query_engine.py +210 -0
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_rag_capability.py +93 -0
- autogen/agentchat/contrib/img_utils.py +397 -0
- autogen/agentchat/contrib/llamaindex_conversable_agent.py +117 -0
- autogen/agentchat/contrib/llava_agent.py +187 -0
- autogen/agentchat/contrib/math_user_proxy_agent.py +464 -0
- autogen/agentchat/contrib/multimodal_conversable_agent.py +125 -0
- autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +324 -0
- autogen/agentchat/contrib/rag/__init__.py +10 -0
- autogen/agentchat/contrib/rag/chromadb_query_engine.py +272 -0
- autogen/agentchat/contrib/rag/llamaindex_query_engine.py +198 -0
- autogen/agentchat/contrib/rag/mongodb_query_engine.py +329 -0
- autogen/agentchat/contrib/rag/query_engine.py +74 -0
- autogen/agentchat/contrib/retrieve_assistant_agent.py +56 -0
- autogen/agentchat/contrib/retrieve_user_proxy_agent.py +703 -0
- autogen/agentchat/contrib/society_of_mind_agent.py +199 -0
- autogen/agentchat/contrib/swarm_agent.py +1425 -0
- autogen/agentchat/contrib/text_analyzer_agent.py +79 -0
- autogen/agentchat/contrib/vectordb/__init__.py +5 -0
- autogen/agentchat/contrib/vectordb/base.py +232 -0
- autogen/agentchat/contrib/vectordb/chromadb.py +315 -0
- autogen/agentchat/contrib/vectordb/couchbase.py +407 -0
- autogen/agentchat/contrib/vectordb/mongodb.py +550 -0
- autogen/agentchat/contrib/vectordb/pgvectordb.py +928 -0
- autogen/agentchat/contrib/vectordb/qdrant.py +320 -0
- autogen/agentchat/contrib/vectordb/utils.py +126 -0
- autogen/agentchat/contrib/web_surfer.py +303 -0
- autogen/agentchat/conversable_agent.py +4023 -0
- autogen/agentchat/group/__init__.py +64 -0
- autogen/agentchat/group/available_condition.py +91 -0
- autogen/agentchat/group/context_condition.py +77 -0
- autogen/agentchat/group/context_expression.py +238 -0
- autogen/agentchat/group/context_str.py +41 -0
- autogen/agentchat/group/context_variables.py +192 -0
- autogen/agentchat/group/group_tool_executor.py +202 -0
- autogen/agentchat/group/group_utils.py +591 -0
- autogen/agentchat/group/handoffs.py +244 -0
- autogen/agentchat/group/llm_condition.py +93 -0
- autogen/agentchat/group/multi_agent_chat.py +237 -0
- autogen/agentchat/group/on_condition.py +58 -0
- autogen/agentchat/group/on_context_condition.py +54 -0
- autogen/agentchat/group/patterns/__init__.py +18 -0
- autogen/agentchat/group/patterns/auto.py +159 -0
- autogen/agentchat/group/patterns/manual.py +176 -0
- autogen/agentchat/group/patterns/pattern.py +288 -0
- autogen/agentchat/group/patterns/random.py +106 -0
- autogen/agentchat/group/patterns/round_robin.py +117 -0
- autogen/agentchat/group/reply_result.py +26 -0
- autogen/agentchat/group/speaker_selection_result.py +41 -0
- autogen/agentchat/group/targets/__init__.py +4 -0
- autogen/agentchat/group/targets/group_chat_target.py +132 -0
- autogen/agentchat/group/targets/group_manager_target.py +151 -0
- autogen/agentchat/group/targets/transition_target.py +413 -0
- autogen/agentchat/group/targets/transition_utils.py +6 -0
- autogen/agentchat/groupchat.py +1694 -0
- autogen/agentchat/realtime/__init__.py +3 -0
- autogen/agentchat/realtime/experimental/__init__.py +20 -0
- autogen/agentchat/realtime/experimental/audio_adapters/__init__.py +8 -0
- autogen/agentchat/realtime/experimental/audio_adapters/twilio_audio_adapter.py +148 -0
- autogen/agentchat/realtime/experimental/audio_adapters/websocket_audio_adapter.py +139 -0
- autogen/agentchat/realtime/experimental/audio_observer.py +42 -0
- autogen/agentchat/realtime/experimental/clients/__init__.py +15 -0
- autogen/agentchat/realtime/experimental/clients/gemini/__init__.py +7 -0
- autogen/agentchat/realtime/experimental/clients/gemini/client.py +274 -0
- autogen/agentchat/realtime/experimental/clients/oai/__init__.py +8 -0
- autogen/agentchat/realtime/experimental/clients/oai/base_client.py +220 -0
- autogen/agentchat/realtime/experimental/clients/oai/rtc_client.py +243 -0
- autogen/agentchat/realtime/experimental/clients/oai/utils.py +48 -0
- autogen/agentchat/realtime/experimental/clients/realtime_client.py +190 -0
- autogen/agentchat/realtime/experimental/function_observer.py +85 -0
- autogen/agentchat/realtime/experimental/realtime_agent.py +158 -0
- autogen/agentchat/realtime/experimental/realtime_events.py +42 -0
- autogen/agentchat/realtime/experimental/realtime_observer.py +100 -0
- autogen/agentchat/realtime/experimental/realtime_swarm.py +475 -0
- autogen/agentchat/realtime/experimental/websockets.py +21 -0
- autogen/agentchat/realtime_agent/__init__.py +21 -0
- autogen/agentchat/user_proxy_agent.py +111 -0
- autogen/agentchat/utils.py +206 -0
- autogen/agents/__init__.py +3 -0
- autogen/agents/contrib/__init__.py +10 -0
- autogen/agents/contrib/time/__init__.py +8 -0
- autogen/agents/contrib/time/time_reply_agent.py +73 -0
- autogen/agents/contrib/time/time_tool_agent.py +51 -0
- autogen/agents/experimental/__init__.py +27 -0
- autogen/agents/experimental/deep_research/__init__.py +7 -0
- autogen/agents/experimental/deep_research/deep_research.py +52 -0
- autogen/agents/experimental/discord/__init__.py +7 -0
- autogen/agents/experimental/discord/discord.py +66 -0
- autogen/agents/experimental/document_agent/__init__.py +19 -0
- autogen/agents/experimental/document_agent/chroma_query_engine.py +316 -0
- autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +118 -0
- autogen/agents/experimental/document_agent/document_agent.py +461 -0
- autogen/agents/experimental/document_agent/document_conditions.py +50 -0
- autogen/agents/experimental/document_agent/document_utils.py +380 -0
- autogen/agents/experimental/document_agent/inmemory_query_engine.py +220 -0
- autogen/agents/experimental/document_agent/parser_utils.py +130 -0
- autogen/agents/experimental/document_agent/url_utils.py +426 -0
- autogen/agents/experimental/reasoning/__init__.py +7 -0
- autogen/agents/experimental/reasoning/reasoning_agent.py +1178 -0
- autogen/agents/experimental/slack/__init__.py +7 -0
- autogen/agents/experimental/slack/slack.py +73 -0
- autogen/agents/experimental/telegram/__init__.py +7 -0
- autogen/agents/experimental/telegram/telegram.py +77 -0
- autogen/agents/experimental/websurfer/__init__.py +7 -0
- autogen/agents/experimental/websurfer/websurfer.py +62 -0
- autogen/agents/experimental/wikipedia/__init__.py +7 -0
- autogen/agents/experimental/wikipedia/wikipedia.py +90 -0
- autogen/browser_utils.py +309 -0
- autogen/cache/__init__.py +10 -0
- autogen/cache/abstract_cache_base.py +75 -0
- autogen/cache/cache.py +203 -0
- autogen/cache/cache_factory.py +88 -0
- autogen/cache/cosmos_db_cache.py +144 -0
- autogen/cache/disk_cache.py +102 -0
- autogen/cache/in_memory_cache.py +58 -0
- autogen/cache/redis_cache.py +123 -0
- autogen/code_utils.py +596 -0
- autogen/coding/__init__.py +22 -0
- autogen/coding/base.py +119 -0
- autogen/coding/docker_commandline_code_executor.py +268 -0
- autogen/coding/factory.py +47 -0
- autogen/coding/func_with_reqs.py +202 -0
- autogen/coding/jupyter/__init__.py +23 -0
- autogen/coding/jupyter/base.py +36 -0
- autogen/coding/jupyter/docker_jupyter_server.py +167 -0
- autogen/coding/jupyter/embedded_ipython_code_executor.py +182 -0
- autogen/coding/jupyter/import_utils.py +82 -0
- autogen/coding/jupyter/jupyter_client.py +231 -0
- autogen/coding/jupyter/jupyter_code_executor.py +160 -0
- autogen/coding/jupyter/local_jupyter_server.py +172 -0
- autogen/coding/local_commandline_code_executor.py +405 -0
- autogen/coding/markdown_code_extractor.py +45 -0
- autogen/coding/utils.py +56 -0
- autogen/doc_utils.py +34 -0
- autogen/events/__init__.py +7 -0
- autogen/events/agent_events.py +1013 -0
- autogen/events/base_event.py +99 -0
- autogen/events/client_events.py +167 -0
- autogen/events/helpers.py +36 -0
- autogen/events/print_event.py +46 -0
- autogen/exception_utils.py +73 -0
- autogen/extensions/__init__.py +5 -0
- autogen/fast_depends/__init__.py +16 -0
- autogen/fast_depends/_compat.py +80 -0
- autogen/fast_depends/core/__init__.py +14 -0
- autogen/fast_depends/core/build.py +225 -0
- autogen/fast_depends/core/model.py +576 -0
- autogen/fast_depends/dependencies/__init__.py +15 -0
- autogen/fast_depends/dependencies/model.py +29 -0
- autogen/fast_depends/dependencies/provider.py +39 -0
- autogen/fast_depends/library/__init__.py +10 -0
- autogen/fast_depends/library/model.py +46 -0
- autogen/fast_depends/py.typed +6 -0
- autogen/fast_depends/schema.py +66 -0
- autogen/fast_depends/use.py +280 -0
- autogen/fast_depends/utils.py +187 -0
- autogen/formatting_utils.py +83 -0
- autogen/function_utils.py +13 -0
- autogen/graph_utils.py +178 -0
- autogen/import_utils.py +526 -0
- autogen/interop/__init__.py +22 -0
- autogen/interop/crewai/__init__.py +7 -0
- autogen/interop/crewai/crewai.py +88 -0
- autogen/interop/interoperability.py +71 -0
- autogen/interop/interoperable.py +46 -0
- autogen/interop/langchain/__init__.py +8 -0
- autogen/interop/langchain/langchain_chat_model_factory.py +155 -0
- autogen/interop/langchain/langchain_tool.py +82 -0
- autogen/interop/litellm/__init__.py +7 -0
- autogen/interop/litellm/litellm_config_factory.py +179 -0
- autogen/interop/pydantic_ai/__init__.py +7 -0
- autogen/interop/pydantic_ai/pydantic_ai.py +168 -0
- autogen/interop/registry.py +69 -0
- autogen/io/__init__.py +15 -0
- autogen/io/base.py +151 -0
- autogen/io/console.py +56 -0
- autogen/io/processors/__init__.py +12 -0
- autogen/io/processors/base.py +21 -0
- autogen/io/processors/console_event_processor.py +56 -0
- autogen/io/run_response.py +293 -0
- autogen/io/thread_io_stream.py +63 -0
- autogen/io/websockets.py +213 -0
- autogen/json_utils.py +43 -0
- autogen/llm_config.py +382 -0
- autogen/logger/__init__.py +11 -0
- autogen/logger/base_logger.py +128 -0
- autogen/logger/file_logger.py +261 -0
- autogen/logger/logger_factory.py +42 -0
- autogen/logger/logger_utils.py +57 -0
- autogen/logger/sqlite_logger.py +523 -0
- autogen/math_utils.py +339 -0
- autogen/mcp/__init__.py +7 -0
- autogen/mcp/__main__.py +78 -0
- autogen/mcp/mcp_client.py +208 -0
- autogen/mcp/mcp_proxy/__init__.py +19 -0
- autogen/mcp/mcp_proxy/fastapi_code_generator_helpers.py +63 -0
- autogen/mcp/mcp_proxy/mcp_proxy.py +581 -0
- autogen/mcp/mcp_proxy/operation_grouping.py +158 -0
- autogen/mcp/mcp_proxy/operation_renaming.py +114 -0
- autogen/mcp/mcp_proxy/patch_fastapi_code_generator.py +98 -0
- autogen/mcp/mcp_proxy/security.py +400 -0
- autogen/mcp/mcp_proxy/security_schema_visitor.py +37 -0
- autogen/messages/__init__.py +7 -0
- autogen/messages/agent_messages.py +948 -0
- autogen/messages/base_message.py +107 -0
- autogen/messages/client_messages.py +171 -0
- autogen/messages/print_message.py +49 -0
- autogen/oai/__init__.py +53 -0
- autogen/oai/anthropic.py +714 -0
- autogen/oai/bedrock.py +628 -0
- autogen/oai/cerebras.py +299 -0
- autogen/oai/client.py +1444 -0
- autogen/oai/client_utils.py +169 -0
- autogen/oai/cohere.py +479 -0
- autogen/oai/gemini.py +998 -0
- autogen/oai/gemini_types.py +155 -0
- autogen/oai/groq.py +305 -0
- autogen/oai/mistral.py +303 -0
- autogen/oai/oai_models/__init__.py +11 -0
- autogen/oai/oai_models/_models.py +16 -0
- autogen/oai/oai_models/chat_completion.py +87 -0
- autogen/oai/oai_models/chat_completion_audio.py +32 -0
- autogen/oai/oai_models/chat_completion_message.py +86 -0
- autogen/oai/oai_models/chat_completion_message_tool_call.py +37 -0
- autogen/oai/oai_models/chat_completion_token_logprob.py +63 -0
- autogen/oai/oai_models/completion_usage.py +60 -0
- autogen/oai/ollama.py +643 -0
- autogen/oai/openai_utils.py +881 -0
- autogen/oai/together.py +370 -0
- autogen/retrieve_utils.py +491 -0
- autogen/runtime_logging.py +160 -0
- autogen/token_count_utils.py +267 -0
- autogen/tools/__init__.py +20 -0
- autogen/tools/contrib/__init__.py +9 -0
- autogen/tools/contrib/time/__init__.py +7 -0
- autogen/tools/contrib/time/time.py +41 -0
- autogen/tools/dependency_injection.py +254 -0
- autogen/tools/experimental/__init__.py +48 -0
- autogen/tools/experimental/browser_use/__init__.py +7 -0
- autogen/tools/experimental/browser_use/browser_use.py +161 -0
- autogen/tools/experimental/crawl4ai/__init__.py +7 -0
- autogen/tools/experimental/crawl4ai/crawl4ai.py +153 -0
- autogen/tools/experimental/deep_research/__init__.py +7 -0
- autogen/tools/experimental/deep_research/deep_research.py +328 -0
- autogen/tools/experimental/duckduckgo/__init__.py +7 -0
- autogen/tools/experimental/duckduckgo/duckduckgo_search.py +109 -0
- autogen/tools/experimental/google/__init__.py +14 -0
- autogen/tools/experimental/google/authentication/__init__.py +11 -0
- autogen/tools/experimental/google/authentication/credentials_hosted_provider.py +43 -0
- autogen/tools/experimental/google/authentication/credentials_local_provider.py +91 -0
- autogen/tools/experimental/google/authentication/credentials_provider.py +35 -0
- autogen/tools/experimental/google/drive/__init__.py +9 -0
- autogen/tools/experimental/google/drive/drive_functions.py +124 -0
- autogen/tools/experimental/google/drive/toolkit.py +88 -0
- autogen/tools/experimental/google/model.py +17 -0
- autogen/tools/experimental/google/toolkit_protocol.py +19 -0
- autogen/tools/experimental/google_search/__init__.py +8 -0
- autogen/tools/experimental/google_search/google_search.py +93 -0
- autogen/tools/experimental/google_search/youtube_search.py +181 -0
- autogen/tools/experimental/messageplatform/__init__.py +17 -0
- autogen/tools/experimental/messageplatform/discord/__init__.py +7 -0
- autogen/tools/experimental/messageplatform/discord/discord.py +288 -0
- autogen/tools/experimental/messageplatform/slack/__init__.py +7 -0
- autogen/tools/experimental/messageplatform/slack/slack.py +391 -0
- autogen/tools/experimental/messageplatform/telegram/__init__.py +7 -0
- autogen/tools/experimental/messageplatform/telegram/telegram.py +275 -0
- autogen/tools/experimental/perplexity/__init__.py +7 -0
- autogen/tools/experimental/perplexity/perplexity_search.py +260 -0
- autogen/tools/experimental/reliable/__init__.py +10 -0
- autogen/tools/experimental/reliable/reliable.py +1316 -0
- autogen/tools/experimental/tavily/__init__.py +7 -0
- autogen/tools/experimental/tavily/tavily_search.py +183 -0
- autogen/tools/experimental/web_search_preview/__init__.py +7 -0
- autogen/tools/experimental/web_search_preview/web_search_preview.py +114 -0
- autogen/tools/experimental/wikipedia/__init__.py +7 -0
- autogen/tools/experimental/wikipedia/wikipedia.py +287 -0
- autogen/tools/function_utils.py +411 -0
- autogen/tools/tool.py +187 -0
- autogen/tools/toolkit.py +86 -0
- autogen/types.py +29 -0
- autogen/version.py +7 -0
- templates/client_template/main.jinja2 +69 -0
- templates/config_template/config.jinja2 +7 -0
- templates/main.jinja2 +61 -0
- ag2-0.9.1a1.dist-info/RECORD +0 -6
- ag2-0.9.1a1.dist-info/top_level.txt +0 -1
- {ag2-0.9.1a1.dist-info → ag2-0.9.2.dist-info/licenses}/LICENSE +0 -0
- {ag2-0.9.1a1.dist-info → ag2-0.9.2.dist-info/licenses}/NOTICE.md +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@with_requirements(["PyMuPDF"], ["os"])
|
|
10
|
+
def extract_pdf_image(pdf_path: str, output_dir: str, page_number=None):
|
|
11
|
+
"""Extracts images from a PDF file and saves them to the specified output directory.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
pdf_path (str): The path to the PDF file.
|
|
15
|
+
output_dir (str): The directory to save the extracted images.
|
|
16
|
+
page_number (int, optional): The page number to extract images from. If not provided, extract images from all pages.
|
|
17
|
+
"""
|
|
18
|
+
import fitz # PyMuPDF library
|
|
19
|
+
|
|
20
|
+
# Open the PDF file
|
|
21
|
+
doc = fitz.open(pdf_path)
|
|
22
|
+
|
|
23
|
+
# Create the output directory if it doesn't exist
|
|
24
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
25
|
+
|
|
26
|
+
# Extract images from the PDF file
|
|
27
|
+
images = []
|
|
28
|
+
if page_number is not None:
|
|
29
|
+
page = doc[page_number - 1] # Adjust page number to 0-based index
|
|
30
|
+
for img in page.get_images():
|
|
31
|
+
xref = img[0]
|
|
32
|
+
base_image = doc.extract_image(xref)
|
|
33
|
+
image_bytes = base_image["image"]
|
|
34
|
+
images.append(image_bytes)
|
|
35
|
+
else:
|
|
36
|
+
for page in doc:
|
|
37
|
+
for img in page.get_images():
|
|
38
|
+
xref = img[0]
|
|
39
|
+
base_image = doc.extract_image(xref)
|
|
40
|
+
image_bytes = base_image["image"]
|
|
41
|
+
images.append(image_bytes)
|
|
42
|
+
|
|
43
|
+
# Save the extracted images
|
|
44
|
+
for i, image_bytes in enumerate(images):
|
|
45
|
+
image_path = os.path.join(output_dir, f"image_{i}.png")
|
|
46
|
+
with open(image_path, "wb") as f:
|
|
47
|
+
f.write(image_bytes)
|
|
48
|
+
|
|
49
|
+
# Print the total number of images saved
|
|
50
|
+
print(f"Saved a total of {len(images)} images")
|
|
51
|
+
|
|
52
|
+
# Close the PDF file
|
|
53
|
+
doc.close()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@with_requirements(["PyMuPDF"])
|
|
8
|
+
def extract_pdf_text(pdf_path, page_number=None):
|
|
9
|
+
"""Extracts text from a specified page or the entire PDF file.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
pdf_path (str): The path to the PDF file.
|
|
13
|
+
page_number (int, optional): The page number to extract (starting from 0). If not provided,
|
|
14
|
+
the function will extract text from the entire PDF file.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
str: The extracted text.
|
|
18
|
+
"""
|
|
19
|
+
import fitz
|
|
20
|
+
|
|
21
|
+
# Open the PDF file
|
|
22
|
+
doc = fitz.open(pdf_path)
|
|
23
|
+
|
|
24
|
+
# Extract text from the entire PDF file or a specific page
|
|
25
|
+
text = ""
|
|
26
|
+
if page_number is None:
|
|
27
|
+
# Extract content from the entire PDF file
|
|
28
|
+
for page in doc:
|
|
29
|
+
text += page.get_text()
|
|
30
|
+
else:
|
|
31
|
+
# Extract content from a specific page
|
|
32
|
+
page = doc[page_number]
|
|
33
|
+
text = page.get_text()
|
|
34
|
+
|
|
35
|
+
# Close the PDF file
|
|
36
|
+
doc.close()
|
|
37
|
+
|
|
38
|
+
return text
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def get_wikipedia_text(title):
|
|
5
|
+
"""Retrieves the text content of a Wikipedia page. It does not support tables and other complex formatting.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
title (str): The title of the Wikipedia page.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
str or None: The text content of the Wikipedia page if it exists, None otherwise.
|
|
12
|
+
"""
|
|
13
|
+
import wikipediaapi
|
|
14
|
+
|
|
15
|
+
wiki_wiki = wikipediaapi.Wikipedia("Mozilla/5.0 (merlin@example.com)", "en")
|
|
16
|
+
page = wiki_wiki.page(title)
|
|
17
|
+
|
|
18
|
+
if page.exists():
|
|
19
|
+
return page.text
|
|
20
|
+
else:
|
|
21
|
+
return None
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
# alternative api: https://rapidapi.com/omarmhaimdat/api/youtube-v2
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_youtube_caption(video_id: str) -> str:
|
|
8
|
+
"""Retrieves the captions for a YouTube video.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
video_id (str): The ID of the YouTube video.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
str: The captions of the YouTube video in text format.
|
|
15
|
+
|
|
16
|
+
Raises:
|
|
17
|
+
KeyError: If the RAPID_API_KEY environment variable is not set.
|
|
18
|
+
"""
|
|
19
|
+
import os
|
|
20
|
+
|
|
21
|
+
import requests
|
|
22
|
+
|
|
23
|
+
rapid_api_key = os.environ["RAPID_API_KEY"]
|
|
24
|
+
video_url = f"https://www.youtube.com/watch?v={video_id}"
|
|
25
|
+
url = "https://youtube-transcript3.p.rapidapi.com/api/transcript-with-url"
|
|
26
|
+
|
|
27
|
+
querystring = {"url": video_url, "lang": "en", "flat_text": "true"}
|
|
28
|
+
|
|
29
|
+
headers = {"X-RapidAPI-Key": rapid_api_key, "X-RapidAPI-Host": "youtube-transcript3.p.rapidapi.com"}
|
|
30
|
+
|
|
31
|
+
response = requests.get(url, headers=headers, params=querystring)
|
|
32
|
+
response = response.json()
|
|
33
|
+
print(response)
|
|
34
|
+
return response["transcript"]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@with_requirements(["transformers", "torch", "pillow"], ["transformers", "torch", "os"])
|
|
10
|
+
def image_qa(image, question, ckpt="Salesforce/blip-vqa-base"):
|
|
11
|
+
"""Perform question answering on an image using a pre-trained VQA model.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
image (Union[str, Image.Image]): The image to perform question answering on. It can be either file path to the image or a PIL Image object.
|
|
15
|
+
question: The question to ask about the image.
|
|
16
|
+
ckpt: The checkpoint name to use. Default is "Salesforce/blip-vqa-base".
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
dict: The generated answer text.
|
|
20
|
+
"""
|
|
21
|
+
import torch
|
|
22
|
+
from PIL import Image
|
|
23
|
+
from transformers import BlipForQuestionAnswering, BlipProcessor
|
|
24
|
+
|
|
25
|
+
def image_processing(img):
|
|
26
|
+
if isinstance(img, Image.Image):
|
|
27
|
+
return img.convert("RGB")
|
|
28
|
+
elif isinstance(img, str):
|
|
29
|
+
if os.path.exists(img):
|
|
30
|
+
return Image.open(img).convert("RGB")
|
|
31
|
+
else:
|
|
32
|
+
full_path = img
|
|
33
|
+
if os.path.exists(full_path):
|
|
34
|
+
return Image.open(full_path).convert("RGB")
|
|
35
|
+
else:
|
|
36
|
+
raise FileNotFoundError
|
|
37
|
+
|
|
38
|
+
def text_processing(file_path):
|
|
39
|
+
# Check the file extension
|
|
40
|
+
if file_path.endswith(".txt"):
|
|
41
|
+
with open(file_path) as file:
|
|
42
|
+
content = file.read()
|
|
43
|
+
else:
|
|
44
|
+
# if the file is not .txt, then it is a string, directly return the string
|
|
45
|
+
return file_path
|
|
46
|
+
return content
|
|
47
|
+
|
|
48
|
+
image = image_processing(image)
|
|
49
|
+
question = text_processing(question)
|
|
50
|
+
|
|
51
|
+
processor = BlipProcessor.from_pretrained(ckpt)
|
|
52
|
+
model = BlipForQuestionAnswering.from_pretrained(ckpt, torch_dtype=torch.float16).to("cuda")
|
|
53
|
+
|
|
54
|
+
raw_image = image
|
|
55
|
+
|
|
56
|
+
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16)
|
|
57
|
+
out = model.generate(**inputs)
|
|
58
|
+
result_formatted = processor.decode(out[0], skip_special_tokens=True)
|
|
59
|
+
|
|
60
|
+
return result_formatted
|
autogen/agentchat/contrib/captainagent/tools/information_retrieval/optical_character_recognition.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@with_requirements(["easyocr"], ["os"])
|
|
10
|
+
def optical_character_recognition(image):
|
|
11
|
+
"""Perform optical character recognition (OCR) on the given image.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
image (Union[str, Image.Image]): The image to perform OCR on. It can be either a file path or an Image object.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
str: The extracted text from the image.
|
|
18
|
+
|
|
19
|
+
Raises:
|
|
20
|
+
FileNotFoundError: If the image file path does not exist.
|
|
21
|
+
"""
|
|
22
|
+
import io
|
|
23
|
+
|
|
24
|
+
import easyocr
|
|
25
|
+
from PIL import Image
|
|
26
|
+
|
|
27
|
+
def image_processing(img):
|
|
28
|
+
if isinstance(img, Image.Image):
|
|
29
|
+
return img.convert("RGB")
|
|
30
|
+
elif isinstance(img, str):
|
|
31
|
+
if os.path.exists(img):
|
|
32
|
+
return Image.open(img).convert("RGB")
|
|
33
|
+
else:
|
|
34
|
+
full_path = img
|
|
35
|
+
if os.path.exists(full_path):
|
|
36
|
+
return Image.open(full_path).convert("RGB")
|
|
37
|
+
else:
|
|
38
|
+
raise FileNotFoundError
|
|
39
|
+
|
|
40
|
+
reader = easyocr.Reader(["en"]) # Load the OCR model into memory
|
|
41
|
+
|
|
42
|
+
if isinstance(image, str):
|
|
43
|
+
# If image is a path, use it directly
|
|
44
|
+
if not os.path.exists(image):
|
|
45
|
+
raise FileNotFoundError
|
|
46
|
+
image_path_or_bytes = image
|
|
47
|
+
else:
|
|
48
|
+
# If image is an Image object, convert it to a bytes stream
|
|
49
|
+
buffer = io.BytesIO()
|
|
50
|
+
image = image_processing(image) # Process the image if needed
|
|
51
|
+
image.save(buffer, format="JPEG")
|
|
52
|
+
buffer.seek(0)
|
|
53
|
+
image_path_or_bytes = buffer
|
|
54
|
+
|
|
55
|
+
# Read text from the image or image path
|
|
56
|
+
result = reader.readtext(image_path_or_bytes)
|
|
57
|
+
|
|
58
|
+
# Extract only the text from the result
|
|
59
|
+
result_text = [text for _, text, _ in result]
|
|
60
|
+
|
|
61
|
+
return ", ".join(result_text)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def perform_web_search(query, count=10, offset=0):
|
|
5
|
+
"""Perform a web search using Bing API.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
query (str): The search query.
|
|
9
|
+
count (int, optional): Number of search results to retrieve. Defaults to 10.
|
|
10
|
+
offset (int, optional): Offset of the first search result. Defaults to 0.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
The name, URL and snippet of each search result.
|
|
14
|
+
"""
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
import requests
|
|
18
|
+
|
|
19
|
+
# Get the Bing API key from the environment variable
|
|
20
|
+
bing_api_key = os.getenv("BING_API_KEY")
|
|
21
|
+
|
|
22
|
+
# Check if the API key is available
|
|
23
|
+
if not bing_api_key:
|
|
24
|
+
raise ValueError("Bing API key not found in environment variable")
|
|
25
|
+
|
|
26
|
+
# Set up the API request
|
|
27
|
+
url = "https://api.bing.microsoft.com/v7.0/search"
|
|
28
|
+
headers = {
|
|
29
|
+
"Ocp-Apim-Subscription-Key": bing_api_key,
|
|
30
|
+
}
|
|
31
|
+
params = {
|
|
32
|
+
"q": query,
|
|
33
|
+
"count": count, # Number of search results to retrieve
|
|
34
|
+
"offset": offset, # Offset of the first search result
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Send the API request
|
|
38
|
+
response = requests.get(url, headers=headers, params=params)
|
|
39
|
+
response.raise_for_status()
|
|
40
|
+
|
|
41
|
+
# Process the search results
|
|
42
|
+
search_results = response.json()
|
|
43
|
+
for index, result in enumerate(search_results["webPages"]["value"]):
|
|
44
|
+
print(f"Search Result {index + 1}:")
|
|
45
|
+
print(result["name"])
|
|
46
|
+
print(result["url"])
|
|
47
|
+
print(result["snippet"])
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def scrape_wikipedia_tables(url: str, header_keyword: str):
|
|
5
|
+
"""Scrapes Wikipedia tables based on a given URL and header keyword.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
url: The URL of the Wikipedia page to scrape.
|
|
9
|
+
header_keyword: The keyword to search for in the headers of the page.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
list: A list of lists representing the scraped table data. Each inner list represents a row in the table,
|
|
13
|
+
with each element representing a cell value.
|
|
14
|
+
"""
|
|
15
|
+
import requests
|
|
16
|
+
from bs4 import BeautifulSoup
|
|
17
|
+
|
|
18
|
+
response = requests.get(url)
|
|
19
|
+
response.raise_for_status()
|
|
20
|
+
soup = BeautifulSoup(response.content, "html.parser")
|
|
21
|
+
headers = soup.find_all(["h1", "h2", "h3", "h4", "h5", "h6"])
|
|
22
|
+
data = []
|
|
23
|
+
for header in headers:
|
|
24
|
+
if header_keyword.lower() in header.text.lower():
|
|
25
|
+
table = header.find_next_sibling("table", class_="wikitable")
|
|
26
|
+
if table:
|
|
27
|
+
rows = table.find_all("tr")
|
|
28
|
+
for row in rows:
|
|
29
|
+
cols = row.find_all(["th", "td"])
|
|
30
|
+
cols = [ele.text.strip() for ele in cols]
|
|
31
|
+
data.append([ele for ele in cols if ele])
|
|
32
|
+
break
|
|
33
|
+
return data
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@with_requirements(["openai-whisper"])
|
|
8
|
+
def transcribe_audio_file(file_path):
|
|
9
|
+
"""Transcribes the audio file located at the given file path.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
file_path (str): The path to the audio file.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
str: The transcribed text from the audio file.
|
|
16
|
+
"""
|
|
17
|
+
import whisper
|
|
18
|
+
|
|
19
|
+
model = whisper.load_model("base")
|
|
20
|
+
result = model.transcribe(file_path)
|
|
21
|
+
return result["text"]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def youtube_download(url: str):
|
|
5
|
+
"""Downloads a YouTube video and returns the download link.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
url: The URL of the YouTube video.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
str: The download link for the audio.
|
|
12
|
+
"""
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
import requests
|
|
16
|
+
|
|
17
|
+
endpoint = "https://youtube-mp3-downloader2.p.rapidapi.com/ytmp3/ytmp3/"
|
|
18
|
+
|
|
19
|
+
querystring = {"url": url}
|
|
20
|
+
|
|
21
|
+
headers = {
|
|
22
|
+
"X-RapidAPI-Key": os.environ.get("RAPIDAPI_KEY"),
|
|
23
|
+
"X-RapidAPI-Host": "youtube-mp3-downloader2.p.rapidapi.com",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
response = requests.get(endpoint, headers=headers, params=querystring)
|
|
27
|
+
response = response.json()
|
|
28
|
+
|
|
29
|
+
if "link" in response:
|
|
30
|
+
return response["link"]
|
|
31
|
+
else:
|
|
32
|
+
print("Error: Unable to retrieve download link.")
|
|
33
|
+
print(response)
|
|
34
|
+
# or you can return an error message
|
|
35
|
+
# return "Error: Unable to retrieve download link."
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@with_requirements(["sympy"])
|
|
8
|
+
def calculate_circle_area_from_diameter(diameter):
|
|
9
|
+
"""Calculate the area of a circle given its diameter.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
diameter (float): The diameter of the circle.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
float: The area of the circle.
|
|
16
|
+
"""
|
|
17
|
+
from sympy import pi
|
|
18
|
+
|
|
19
|
+
radius = diameter / 2
|
|
20
|
+
area = pi * radius**2
|
|
21
|
+
return area
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def calculate_day_of_the_week(total_days: int, starting_day: str):
|
|
5
|
+
"""Calculates the day of the week after a given number of days starting from a specified day.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
total_days: The number of days to calculate.
|
|
9
|
+
starting_day: The starting day of the week, should be one of 'Monday', 'Tuesday', 'Wednesday', etc.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
str: The day of the week after the specified number of days.
|
|
13
|
+
"""
|
|
14
|
+
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
|
15
|
+
|
|
16
|
+
start_index = days_of_week.index(starting_day)
|
|
17
|
+
end_index = (start_index + total_days) % 7
|
|
18
|
+
return days_of_week[end_index]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def calculate_fraction_sum(
|
|
5
|
+
fraction1_numerator: int, fraction1_denominator: int, fraction2_numerator: int, fraction2_denominator: int
|
|
6
|
+
):
|
|
7
|
+
"""Calculates the sum of two fractions and returns the result as a mixed number.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
fraction1_numerator: The numerator of the first fraction.
|
|
11
|
+
fraction1_denominator: The denominator of the first fraction.
|
|
12
|
+
fraction2_numerator: The numerator of the second fraction.
|
|
13
|
+
fraction2_denominator: The denominator of the second fraction.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
str: The sum of the two fractions as a mixed number in the format 'a b/c'
|
|
17
|
+
"""
|
|
18
|
+
from fractions import Fraction
|
|
19
|
+
|
|
20
|
+
fraction1 = Fraction(fraction1_numerator, fraction1_denominator)
|
|
21
|
+
fraction2 = Fraction(fraction2_numerator, fraction2_denominator)
|
|
22
|
+
result = fraction1 + fraction2
|
|
23
|
+
mixed_number = result.numerator // result.denominator
|
|
24
|
+
mixed_fraction_numerator = result.numerator % result.denominator
|
|
25
|
+
if mixed_fraction_numerator > 0:
|
|
26
|
+
return f"{mixed_number} {Fraction(mixed_fraction_numerator, result.denominator)}"
|
|
27
|
+
else:
|
|
28
|
+
return str(mixed_number)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@with_requirements(["sympy"])
|
|
8
|
+
def calculate_matrix_power(matrix, power):
|
|
9
|
+
"""Calculate the power of a given matrix.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
matrix (list): An array of numbers that represents the matrix.
|
|
13
|
+
power (int): The power to which the matrix is raised.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
Matrix: The resulting matrix after raising to power.
|
|
17
|
+
|
|
18
|
+
Raises:
|
|
19
|
+
ValueError: If the power is negative and the matrix is not invertible.
|
|
20
|
+
"""
|
|
21
|
+
from sympy import Matrix, eye
|
|
22
|
+
|
|
23
|
+
m = Matrix(matrix)
|
|
24
|
+
if power == 0:
|
|
25
|
+
return eye(m.shape[0])
|
|
26
|
+
elif power < 0:
|
|
27
|
+
if not m.is_invertible():
|
|
28
|
+
raise ValueError("Matrix is not invertible.")
|
|
29
|
+
return m.inverse() ** (-power)
|
|
30
|
+
elif power > 0:
|
|
31
|
+
return m**power
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def calculate_reflected_point(point):
|
|
5
|
+
"""Calculates the reflection point of a given point about the line y=x.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
point (dict): A dictionary representing the coordinates of the point.
|
|
9
|
+
The dictionary should have keys 'x' and 'y' representing the x and y coordinates respectively.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
dict: A dictionary representing the coordinates of the reflected point. Its keys are 'x' and 'y'.
|
|
13
|
+
"""
|
|
14
|
+
# Swap x and y for reflection about y=x
|
|
15
|
+
reflected_point = {"x": point["y"], "y": point["x"]}
|
|
16
|
+
return reflected_point
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@with_requirements(["sympy"])
|
|
8
|
+
def complex_numbers_product(complex_numbers):
|
|
9
|
+
"""Calculates the product of a list of complex numbers.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
complex_numbers (list): A list of dictionaries representing complex numbers.
|
|
13
|
+
Each dictionary should have 'real' and 'imag' keys representing the real
|
|
14
|
+
and imaginary parts of the complex number.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
complex: The simplified product of the complex numbers.
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
from sympy import I, simplify
|
|
21
|
+
|
|
22
|
+
result = 1
|
|
23
|
+
for c in complex_numbers:
|
|
24
|
+
result *= c["real"] + I * c["imag"]
|
|
25
|
+
return simplify(result)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@with_requirements(["sympy"])
|
|
8
|
+
def compute_currency_conversion(amount, exchange_rate):
|
|
9
|
+
"""Compute the currency conversion of the given amount using the provided exchange rate.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
amount (float): The amount to be converted.
|
|
13
|
+
exchange_rate (float): The exchange rate to use for the conversion, represented as the amount of second currency equivalent to one unit of the first currency.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
float: The converted amount.
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
from sympy import Rational
|
|
20
|
+
|
|
21
|
+
# Calculate the converted amount using the given exchange rate
|
|
22
|
+
converted_amount = Rational(amount, exchange_rate)
|
|
23
|
+
return float(converted_amount)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def count_distinct_permutations(sequence):
|
|
5
|
+
"""Counts the number of distinct permutations of a sequence where items may be indistinguishable.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
sequence (iterable): The sequence for which to count the distinct permutations.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
int: The number of distinct permutations.
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
>>> count_distinct_permutations("aab")
|
|
15
|
+
3
|
|
16
|
+
>>> count_distinct_permutations([1, 2, 2])
|
|
17
|
+
3
|
|
18
|
+
"""
|
|
19
|
+
from collections import Counter
|
|
20
|
+
from math import factorial
|
|
21
|
+
|
|
22
|
+
counts = Counter(sequence)
|
|
23
|
+
total_length = sum(counts.values())
|
|
24
|
+
permutations = factorial(total_length)
|
|
25
|
+
for count in counts.values():
|
|
26
|
+
permutations //= factorial(count)
|
|
27
|
+
return permutations
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def evaluate_expression(expression):
|
|
5
|
+
"""Evaluates a mathematical expression with support for floor function notation and power notation.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
expression (str): The mathematical expression to evaluate. It can only contain one symbol 'x'.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
Union[sympy.Expr, str]: The evaluated result as a sympy expression if successful,
|
|
12
|
+
otherwise an error message as a string.
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
from sympy import symbols, sympify
|
|
16
|
+
|
|
17
|
+
# Replace power with ** for sympy
|
|
18
|
+
expression = expression.replace("^", "**")
|
|
19
|
+
# Replace the floor function notation
|
|
20
|
+
expression = expression.replace("\\lfloor", "floor(").replace("\\rfloor", ")")
|
|
21
|
+
try:
|
|
22
|
+
# Create a symbol 'x' for use in case it is in the expression
|
|
23
|
+
symbols("x")
|
|
24
|
+
# Evaluate the expression
|
|
25
|
+
result = sympify(expression)
|
|
26
|
+
return result
|
|
27
|
+
except Exception as e:
|
|
28
|
+
return str(e)
|