swarms 7.5.7__py3-none-any.whl → 7.5.8__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.
- swarms/utils/str_to_dict.py +2 -26
- {swarms-7.5.7.dist-info → swarms-7.5.8.dist-info}/METADATA +1 -1
- {swarms-7.5.7.dist-info → swarms-7.5.8.dist-info}/RECORD +6 -6
- {swarms-7.5.7.dist-info → swarms-7.5.8.dist-info}/LICENSE +0 -0
- {swarms-7.5.7.dist-info → swarms-7.5.8.dist-info}/WHEEL +0 -0
- {swarms-7.5.7.dist-info → swarms-7.5.8.dist-info}/entry_points.txt +0 -0
swarms/utils/str_to_dict.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
import json
|
2
2
|
from typing import Dict
|
3
|
-
import asyncio
|
4
3
|
|
5
4
|
|
6
|
-
|
5
|
+
def str_to_dict(s: str, retries: int = 3) -> Dict:
|
7
6
|
"""
|
8
|
-
|
7
|
+
Converts a JSON string to dictionary.
|
9
8
|
|
10
9
|
Args:
|
11
10
|
s (str): The JSON string to be converted.
|
@@ -26,26 +25,3 @@ async def async_str_to_dict(s: str, retries: int = 3) -> Dict:
|
|
26
25
|
continue # Retry on failure
|
27
26
|
else:
|
28
27
|
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))
|
@@ -172,13 +172,13 @@ swarms/utils/markdown_message.py,sha256=RThHNnMf6ZLTlYK4vKn3yuewChaxWAYAWb0Xm_pT
|
|
172
172
|
swarms/utils/pandas_utils.py,sha256=AA0wNWM05CrNovW7x9aY63Zhw7CIGMERmxvjH2Q-Jjc,2567
|
173
173
|
swarms/utils/parse_code.py,sha256=XFOLymbdP3HzMZuqsj7pwUyisvUmTm0ev9iThR_ambI,1987
|
174
174
|
swarms/utils/pdf_to_text.py,sha256=nkySOS_sJ4Jf4RP5SoDpMB5WfjJ_GGc5z8gJfn2cxOM,1311
|
175
|
-
swarms/utils/str_to_dict.py,sha256=
|
175
|
+
swarms/utils/str_to_dict.py,sha256=T3Jsdjz87WIlkSo7jAW6BB80sv0Ns49WT1qXlOrdEoE,874
|
176
176
|
swarms/utils/swarm_reliability_checks.py,sha256=MsgUULt3HYg72D0HifZNmtCyJYpLA2UDA2wQixI-NbA,2562
|
177
177
|
swarms/utils/try_except_wrapper.py,sha256=appEGu9Afy3TmdkNNXUgQ9yU9lj2j0uNkIoW0JhVzzY,3917
|
178
178
|
swarms/utils/visualizer.py,sha256=0ylohEk62MAS6iPRaDOV03m9qo2k5J56tWlKJk_46p4,16927
|
179
179
|
swarms/utils/wrapper_clusterop.py,sha256=PMSCVM7ZT1vgj1D_MYAe835RR3SMLYxA-si2JS02yNQ,4220
|
180
|
-
swarms-7.5.
|
181
|
-
swarms-7.5.
|
182
|
-
swarms-7.5.
|
183
|
-
swarms-7.5.
|
184
|
-
swarms-7.5.
|
180
|
+
swarms-7.5.8.dist-info/LICENSE,sha256=jwRtEmTWjLrEsvFB6QFdYs2cEeZPRMdj-UMOFkPF8_0,11363
|
181
|
+
swarms-7.5.8.dist-info/METADATA,sha256=lJSeodACjbbgfGxL5k0FJG3aVUZXftiTfhRD7JtSnXs,103019
|
182
|
+
swarms-7.5.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
183
|
+
swarms-7.5.8.dist-info/entry_points.txt,sha256=2K0rTtfO1X1WaO-waJlXIKw5Voa_EpAL_yU0HXE2Jgc,47
|
184
|
+
swarms-7.5.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|