swarms 7.5.7__tar.gz → 7.5.9__tar.gz
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.
- {swarms-7.5.7 → swarms-7.5.9}/PKG-INFO +1 -1
- {swarms-7.5.7 → swarms-7.5.9}/pyproject.toml +1 -1
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_builder.py +32 -18
- swarms-7.5.9/swarms/utils/str_to_dict.py +27 -0
- swarms-7.5.7/swarms/utils/str_to_dict.py +0 -51
- {swarms-7.5.7 → swarms-7.5.9}/LICENSE +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/README.md +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/agent_print.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/ape_agent.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/auto_generate_swarm_config.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/consistency_agent.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/create_agents_from_yaml.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/i_agent.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/openai_assistant.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/reasoning_agents.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/reasoning_duo.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/agents/tool_agent.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/artifacts/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/artifacts/main_artifact.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/cli/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/cli/create_agent.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/cli/main.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/cli/onboarding_process.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/accountant_swarm_prompts.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/ag_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/aga.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/agent_prompts.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/agent_system_prompts.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/ai_research_team.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/aot_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/autobloggen.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/autoswarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/chat_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/code_interpreter.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/code_spawner.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/debate.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/documentation.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/education.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/finance_agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/finance_agent_sys_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/growth_agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/idea2img.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/legal_agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/logistics.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/meta_system_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/multi_modal_autonomous_instruction_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/multi_modal_prompts.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/multi_modal_visual_prompts.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/operations_agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/personal_stylist.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/product_agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/programming.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/project_manager.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/prompt_generator.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/prompt_generator_optimizer.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/python.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/react.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/reasoning_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/refiner_agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/sales.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/sales_prompts.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/security_team.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/self_operating_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/sop_generator_agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/summaries_prompts.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/support_agent_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/swarm_manager_agent.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/task_assignment_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/tests.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/tools.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/urban_planning.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/visual_cot.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/worker_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/prompts/xray_swarm_prompt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/schemas/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/schemas/agent_input_schema.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/schemas/agent_step_schemas.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/schemas/base_schemas.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_registry.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_roles.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_router.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agent_security.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/agents_available.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/airflow_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/async_workflow.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/auto_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/auto_swarm_builder.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/base_structure.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/base_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/base_workflow.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/concat.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/concurrent_workflow.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/conversation.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/csv_to_agent.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/de_hallucination_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/graph_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/graph_workflow.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/groupchat.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/hiearchical_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/majority_voting.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/malt.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/matrix_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/meme_agent_persona_generator.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/mixture_of_agents.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/model_router.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/multi_agent_collab.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/multi_agent_exec.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/multi_agent_orchestrator.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/octotools.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/omni_agent_types.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/output_type.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/output_types.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/pulsar_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/queue_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/rearrange.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/round_robin.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/safe_loading.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/sequential_workflow.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/spreadsheet_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/stopping_conditions.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_arange.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_builder.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_eval.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_id_generator.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_load_balancer.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_matcher.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_output_type.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_registry.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarm_router.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarming_architectures.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/swarms_api.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/talk_hier.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/tree_swarm.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/utils.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/various_alt_swarms.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/structs/workspace_manager.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/telemetry/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/telemetry/bootup.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/telemetry/main.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/base_tool.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/cohere_func_call_schema.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/func_calling_utils.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/func_to_str.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/function_util.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/json_former.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/json_utils.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/logits_processor.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/openai_func_calling_schema_pydantic.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/openai_tool_creator_decorator.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/py_func_to_openai_func_str.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/pydantic_to_json.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/tool_parse_exec.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/tool_registry.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/tools/tool_utils.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/__init__.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/agent_ops_check.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/any_to_str.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/auto_download_check_packages.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/calculate_func_metrics.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/data_to_text.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/disable_logging.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/file_processing.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/formatter.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/function_caller_model.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/history_output_formatter.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/litellm_tokenizer.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/litellm_wrapper.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/loguru_logger.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/markdown_message.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/pandas_utils.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/parse_code.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/pdf_to_text.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/swarm_reliability_checks.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/try_except_wrapper.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/visualizer.py +0 -0
- {swarms-7.5.7 → swarms-7.5.9}/swarms/utils/wrapper_clusterop.py +0 -0
@@ -1,13 +1,11 @@
|
|
1
1
|
import os
|
2
|
-
from typing import List, Optional, Tuple
|
2
|
+
from typing import Any, List, Optional, Tuple
|
3
3
|
|
4
4
|
from loguru import logger
|
5
5
|
from pydantic import BaseModel, Field
|
6
6
|
|
7
7
|
from swarms.structs.agent import Agent
|
8
|
-
from swarms.utils.any_to_str import any_to_str
|
9
8
|
from swarms.utils.function_caller_model import OpenAIFunctionCaller
|
10
|
-
from swarms.utils.litellm_tokenizer import count_tokens
|
11
9
|
|
12
10
|
BOSS_SYSTEM_PROMPT = """
|
13
11
|
# Swarm Intelligence Orchestrator
|
@@ -148,13 +146,17 @@ class AgentsBuilder:
|
|
148
146
|
description: str = "This is a swarm that creates swarms",
|
149
147
|
verbose: bool = True,
|
150
148
|
max_loops: int = 1,
|
149
|
+
model_name: str = "gpt-4o",
|
150
|
+
return_dictionary: bool = True,
|
151
151
|
):
|
152
152
|
self.name = name
|
153
153
|
self.description = description
|
154
154
|
self.verbose = verbose
|
155
155
|
self.max_loops = max_loops
|
156
156
|
self.agents_pool = []
|
157
|
-
|
157
|
+
self.model_name = model_name
|
158
|
+
self.return_dictionary = return_dictionary
|
159
|
+
|
158
160
|
logger.info(
|
159
161
|
f"Initialized AutoSwarmBuilder: {name} {description}"
|
160
162
|
)
|
@@ -174,11 +176,11 @@ class AgentsBuilder:
|
|
174
176
|
The output from the swarm's execution
|
175
177
|
"""
|
176
178
|
logger.info(f"Running swarm on task: {task}")
|
177
|
-
agents
|
179
|
+
agents = self._create_agents(
|
178
180
|
task, image_url, *args, **kwargs
|
179
181
|
)
|
180
182
|
|
181
|
-
return agents
|
183
|
+
return agents
|
182
184
|
|
183
185
|
def _create_agents(self, task: str, *args, **kwargs):
|
184
186
|
"""Create the necessary agents for a task.
|
@@ -197,23 +199,28 @@ class AgentsBuilder:
|
|
197
199
|
api_key=os.getenv("OPENAI_API_KEY"),
|
198
200
|
temperature=0.1,
|
199
201
|
base_model=Agents,
|
200
|
-
model_name=
|
202
|
+
model_name=self.model_name,
|
203
|
+
max_tokens = 8192,
|
201
204
|
)
|
202
205
|
|
203
206
|
agents_dictionary = model.run(task)
|
204
|
-
|
207
|
+
print(agents_dictionary)
|
208
|
+
|
209
|
+
print(type(agents_dictionary))
|
205
210
|
logger.info("Agents successfully created")
|
206
211
|
logger.info(f"Agents: {len(agents_dictionary.agents)}")
|
207
212
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
213
|
+
if self.return_dictionary:
|
214
|
+
logger.info("Returning dictionary")
|
215
|
+
|
216
|
+
# Convert swarm config to dictionary
|
217
|
+
agents_dictionary = agents_dictionary.model_dump()
|
218
|
+
return agents_dictionary
|
219
|
+
else:
|
220
|
+
logger.info("Returning agents")
|
221
|
+
return self.create_agents(agents_dictionary)
|
222
|
+
|
223
|
+
def create_agents(self, agents_dictionary: Any):
|
217
224
|
# Create agents from config
|
218
225
|
agents = []
|
219
226
|
for agent_config in agents_dictionary.agents:
|
@@ -235,7 +242,7 @@ class AgentsBuilder:
|
|
235
242
|
)
|
236
243
|
agents.append(agent)
|
237
244
|
|
238
|
-
return agents
|
245
|
+
return agents
|
239
246
|
|
240
247
|
def build_agent(
|
241
248
|
self,
|
@@ -278,3 +285,10 @@ class AgentsBuilder:
|
|
278
285
|
)
|
279
286
|
|
280
287
|
return agent
|
288
|
+
|
289
|
+
|
290
|
+
# if __name__ == "__main__":
|
291
|
+
# builder = AgentsBuilder(model_name="gpt-4o")
|
292
|
+
# agents = builder.run("Create a swarm that can write a book about the history of the world")
|
293
|
+
# print(agents)
|
294
|
+
# print(type(agents))
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import json
|
2
|
+
from typing import Dict
|
3
|
+
|
4
|
+
|
5
|
+
def str_to_dict(s: str, retries: int = 3) -> Dict:
|
6
|
+
"""
|
7
|
+
Converts a JSON string to dictionary.
|
8
|
+
|
9
|
+
Args:
|
10
|
+
s (str): The JSON string to be converted.
|
11
|
+
retries (int): The number of times to retry parsing the string in case of a JSONDecodeError. Default is 3.
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
Dict: The parsed dictionary from the JSON string.
|
15
|
+
|
16
|
+
Raises:
|
17
|
+
json.JSONDecodeError: If the string cannot be parsed into a dictionary after the specified number of retries.
|
18
|
+
"""
|
19
|
+
for attempt in range(retries):
|
20
|
+
try:
|
21
|
+
# Run json.loads directly since it's fast enough
|
22
|
+
return json.loads(s)
|
23
|
+
except json.JSONDecodeError as e:
|
24
|
+
if attempt < retries - 1:
|
25
|
+
continue # Retry on failure
|
26
|
+
else:
|
27
|
+
raise e # Raise the error if all retries fail
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
from typing import Dict
|
3
|
-
import asyncio
|
4
|
-
|
5
|
-
|
6
|
-
async def async_str_to_dict(s: str, retries: int = 3) -> Dict:
|
7
|
-
"""
|
8
|
-
Asynchronously converts a JSON-formatted string to a dictionary.
|
9
|
-
|
10
|
-
Args:
|
11
|
-
s (str): The JSON string to be converted.
|
12
|
-
retries (int): The number of times to retry parsing the string in case of a JSONDecodeError. Default is 3.
|
13
|
-
|
14
|
-
Returns:
|
15
|
-
Dict: The parsed dictionary from the JSON string.
|
16
|
-
|
17
|
-
Raises:
|
18
|
-
json.JSONDecodeError: If the string cannot be parsed into a dictionary after the specified number of retries.
|
19
|
-
"""
|
20
|
-
for attempt in range(retries):
|
21
|
-
try:
|
22
|
-
# Run json.loads directly since it's fast enough
|
23
|
-
return json.loads(s)
|
24
|
-
except json.JSONDecodeError as e:
|
25
|
-
if attempt < retries - 1:
|
26
|
-
continue # Retry on failure
|
27
|
-
else:
|
28
|
-
raise e # Raise the error if all retries fail
|
29
|
-
|
30
|
-
|
31
|
-
def str_to_dict(s: str, retries: int = 3) -> Dict:
|
32
|
-
"""
|
33
|
-
Converts a JSON string to dictionary, handling both sync and async contexts.
|
34
|
-
|
35
|
-
Args:
|
36
|
-
s (str): The JSON string to be converted.
|
37
|
-
retries (int): The number of times to retry parsing the string in case of a JSONDecodeError. Default is 3.
|
38
|
-
|
39
|
-
Returns:
|
40
|
-
Dict: The parsed dictionary from the JSON string.
|
41
|
-
"""
|
42
|
-
# For simplicity and reliability, just try to parse the JSON directly first
|
43
|
-
try:
|
44
|
-
return json.loads(s)
|
45
|
-
except json.JSONDecodeError:
|
46
|
-
# If direct parsing fails, try the async path
|
47
|
-
try:
|
48
|
-
return async_str_to_dict(s, retries).__await__()
|
49
|
-
except (AttributeError, RuntimeError):
|
50
|
-
# If we can't await (not in async context), use run
|
51
|
-
return asyncio.run(async_str_to_dict(s, retries))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|