waldiez 0.5.2__py3-none-any.whl → 0.5.3__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 waldiez might be problematic. Click here for more details.
- waldiez/_version.py +1 -1
- waldiez/cli.py +2 -0
- waldiez/models/chat/chat_message.py +1 -1
- waldiez/runner.py +35 -2
- waldiez/running/base_runner.py +38 -8
- waldiez/running/environment.py +32 -13
- waldiez/running/import_runner.py +13 -0
- waldiez/running/post_run.py +71 -14
- waldiez/running/pre_run.py +42 -0
- waldiez/running/protocol.py +6 -0
- waldiez/running/subprocess_runner.py +4 -0
- waldiez/running/timeline_processor.py +1248 -0
- waldiez/utils/version.py +12 -1
- {waldiez-0.5.2.dist-info → waldiez-0.5.3.dist-info}/METADATA +33 -32
- {waldiez-0.5.2.dist-info → waldiez-0.5.3.dist-info}/RECORD +19 -18
- {waldiez-0.5.2.dist-info → waldiez-0.5.3.dist-info}/WHEEL +0 -0
- {waldiez-0.5.2.dist-info → waldiez-0.5.3.dist-info}/entry_points.txt +0 -0
- {waldiez-0.5.2.dist-info → waldiez-0.5.3.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.5.2.dist-info → waldiez-0.5.3.dist-info}/licenses/NOTICE.md +0 -0
waldiez/running/post_run.py
CHANGED
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
"""Utilities for running code."""
|
|
6
6
|
|
|
7
7
|
import datetime
|
|
8
|
+
import json
|
|
8
9
|
import shutil
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
from typing import Optional, Union
|
|
11
12
|
|
|
12
13
|
from .gen_seq_diagram import generate_sequence_diagram
|
|
14
|
+
from .patch_io_stream import get_printer
|
|
15
|
+
from .timeline_processor import TimelineProcessor
|
|
13
16
|
|
|
14
17
|
|
|
15
18
|
def after_run(
|
|
@@ -18,6 +21,7 @@ def after_run(
|
|
|
18
21
|
flow_name: str,
|
|
19
22
|
uploads_root: Optional[Path] = None,
|
|
20
23
|
skip_mmd: bool = False,
|
|
24
|
+
skip_timeline: bool = False,
|
|
21
25
|
) -> None:
|
|
22
26
|
"""Actions to perform after running the flow.
|
|
23
27
|
|
|
@@ -34,25 +38,21 @@ def after_run(
|
|
|
34
38
|
skip_mmd : bool, optional
|
|
35
39
|
Whether to skip the mermaid sequence diagram generation,
|
|
36
40
|
by default, False
|
|
41
|
+
skip_timeline : bool, optional
|
|
42
|
+
Whether to skip the timeline processing, by default False
|
|
37
43
|
"""
|
|
38
44
|
if isinstance(output_file, str):
|
|
39
45
|
output_file = Path(output_file)
|
|
40
46
|
mmd_dir = output_file.parent if output_file else Path.cwd()
|
|
41
47
|
if skip_mmd is False:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
and mmd_path != mmd_dir / f"{flow_name}.mmd"
|
|
51
|
-
):
|
|
52
|
-
try:
|
|
53
|
-
shutil.copyfile(mmd_path, mmd_dir / f"{flow_name}.mmd")
|
|
54
|
-
except BaseException: # pylint: disable=broad-exception-caught
|
|
55
|
-
pass
|
|
48
|
+
_make_mermaid_diagram(
|
|
49
|
+
temp_dir=temp_dir,
|
|
50
|
+
output_file=output_file,
|
|
51
|
+
flow_name=flow_name,
|
|
52
|
+
mmd_dir=mmd_dir,
|
|
53
|
+
)
|
|
54
|
+
if skip_timeline is False:
|
|
55
|
+
_make_timeline_json(temp_dir=temp_dir)
|
|
56
56
|
if output_file:
|
|
57
57
|
destination_dir = output_file.parent
|
|
58
58
|
destination_dir = (
|
|
@@ -71,6 +71,63 @@ def after_run(
|
|
|
71
71
|
shutil.rmtree(temp_dir)
|
|
72
72
|
|
|
73
73
|
|
|
74
|
+
def _make_mermaid_diagram(
|
|
75
|
+
temp_dir: Path,
|
|
76
|
+
output_file: Optional[Union[str, Path]],
|
|
77
|
+
flow_name: str,
|
|
78
|
+
mmd_dir: Path,
|
|
79
|
+
) -> None:
|
|
80
|
+
events_csv_path = temp_dir / "logs" / "events.csv"
|
|
81
|
+
if events_csv_path.exists():
|
|
82
|
+
print("Generating mermaid sequence diagram...")
|
|
83
|
+
mmd_path = temp_dir / f"{flow_name}.mmd"
|
|
84
|
+
generate_sequence_diagram(events_csv_path, mmd_path)
|
|
85
|
+
if (
|
|
86
|
+
not output_file
|
|
87
|
+
and mmd_path.exists()
|
|
88
|
+
and mmd_path != mmd_dir / f"{flow_name}.mmd"
|
|
89
|
+
):
|
|
90
|
+
try:
|
|
91
|
+
shutil.copyfile(mmd_path, mmd_dir / f"{flow_name}.mmd")
|
|
92
|
+
except BaseException: # pylint: disable=broad-exception-caught
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _make_timeline_json(
|
|
97
|
+
temp_dir: Path,
|
|
98
|
+
) -> None:
|
|
99
|
+
"""Make the timeline JSON file."""
|
|
100
|
+
events_csv_path = temp_dir / "logs" / "events.csv"
|
|
101
|
+
if events_csv_path.exists():
|
|
102
|
+
print("Processing timeline...")
|
|
103
|
+
log_files = TimelineProcessor.get_files(temp_dir / "logs")
|
|
104
|
+
if any(log_files.values()):
|
|
105
|
+
output_file = temp_dir / "timeline.json"
|
|
106
|
+
# pylint: disable=too-many-try-statements
|
|
107
|
+
try:
|
|
108
|
+
processor = TimelineProcessor()
|
|
109
|
+
processor.load_csv_files(
|
|
110
|
+
agents_file=log_files["agents"],
|
|
111
|
+
chat_file=log_files["chat"],
|
|
112
|
+
events_file=log_files["events"],
|
|
113
|
+
functions_file=log_files["functions"],
|
|
114
|
+
)
|
|
115
|
+
results = processor.process_timeline()
|
|
116
|
+
with open(output_file, "w", encoding="utf-8") as f:
|
|
117
|
+
json.dump(results, f, indent=2, default=str)
|
|
118
|
+
short_results = TimelineProcessor.get_short_results(results)
|
|
119
|
+
printer = get_printer()
|
|
120
|
+
printer(
|
|
121
|
+
json.dumps(
|
|
122
|
+
{"type": "timeline", "content": short_results},
|
|
123
|
+
default=str,
|
|
124
|
+
),
|
|
125
|
+
flush=True,
|
|
126
|
+
)
|
|
127
|
+
except BaseException: # pylint: disable=broad-exception-caught
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
|
|
74
131
|
def copy_results(
|
|
75
132
|
temp_dir: Path,
|
|
76
133
|
output_file: Path,
|
waldiez/running/pre_run.py
CHANGED
|
@@ -15,6 +15,7 @@ from .utils import strip_ansi
|
|
|
15
15
|
|
|
16
16
|
def install_requirements(
|
|
17
17
|
extra_requirements: set[str],
|
|
18
|
+
upgrade: bool = False,
|
|
18
19
|
printer: Callable[..., None] = print,
|
|
19
20
|
) -> None:
|
|
20
21
|
"""Install the requirements.
|
|
@@ -23,6 +24,8 @@ def install_requirements(
|
|
|
23
24
|
----------
|
|
24
25
|
extra_requirements : set[str]
|
|
25
26
|
The extra requirements.
|
|
27
|
+
upgrade : bool, optional
|
|
28
|
+
Whether to upgrade the requirements, by default False.
|
|
26
29
|
printer : Callable[..., None]
|
|
27
30
|
The printer function to use, defaults to print.
|
|
28
31
|
"""
|
|
@@ -38,6 +41,8 @@ def install_requirements(
|
|
|
38
41
|
os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = "1"
|
|
39
42
|
if not is_root():
|
|
40
43
|
pip_install.append("--user")
|
|
44
|
+
if upgrade:
|
|
45
|
+
pip_install.append("--upgrade")
|
|
41
46
|
pip_install.extend(extra_requirements)
|
|
42
47
|
# pylint: disable=too-many-try-statements
|
|
43
48
|
try:
|
|
@@ -63,6 +68,7 @@ def install_requirements(
|
|
|
63
68
|
|
|
64
69
|
async def a_install_requirements(
|
|
65
70
|
extra_requirements: set[str],
|
|
71
|
+
upgrade: bool = False,
|
|
66
72
|
printer: Callable[..., None] = print,
|
|
67
73
|
) -> None:
|
|
68
74
|
"""Install the requirements asynchronously.
|
|
@@ -71,6 +77,8 @@ async def a_install_requirements(
|
|
|
71
77
|
----------
|
|
72
78
|
extra_requirements : set[str]
|
|
73
79
|
The extra requirements.
|
|
80
|
+
upgrade : bool, optional
|
|
81
|
+
Whether to upgrade the requirements, by default False.
|
|
74
82
|
printer : Callable[..., None]
|
|
75
83
|
The printer function to use, defaults to print.
|
|
76
84
|
"""
|
|
@@ -83,6 +91,8 @@ async def a_install_requirements(
|
|
|
83
91
|
os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = "1"
|
|
84
92
|
if not is_root():
|
|
85
93
|
pip_install.extend(["--user"])
|
|
94
|
+
if upgrade:
|
|
95
|
+
pip_install.append("--upgrade")
|
|
86
96
|
pip_install.extend(extra_requirements)
|
|
87
97
|
# pylint: disable=too-many-try-statements
|
|
88
98
|
try:
|
|
@@ -103,3 +113,35 @@ async def a_install_requirements(
|
|
|
103
113
|
os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = break_system_packages
|
|
104
114
|
else:
|
|
105
115
|
del os.environ["PIP_BREAK_SYSTEM_PACKAGES"]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def install_waldiez(
|
|
119
|
+
upgrade: bool = True,
|
|
120
|
+
printer: Callable[..., None] = print,
|
|
121
|
+
) -> None:
|
|
122
|
+
"""Install Waldiez.
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
upgrade : bool, optional
|
|
127
|
+
Whether to upgrade Waldiez, by default True.
|
|
128
|
+
printer : Callable[..., None]
|
|
129
|
+
The printer function to use, defaults to print.
|
|
130
|
+
"""
|
|
131
|
+
install_requirements({"waldiez"}, upgrade, printer)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
async def a_install_waldiez(
|
|
135
|
+
upgrade: bool = True,
|
|
136
|
+
printer: Callable[..., None] = print,
|
|
137
|
+
) -> None:
|
|
138
|
+
"""Install Waldiez asynchronously.
|
|
139
|
+
|
|
140
|
+
Parameters
|
|
141
|
+
----------
|
|
142
|
+
upgrade : bool, optional
|
|
143
|
+
Whether to upgrade Waldiez, by default True.
|
|
144
|
+
printer : Callable[..., None]
|
|
145
|
+
The printer function to use, defaults to print.
|
|
146
|
+
"""
|
|
147
|
+
await a_install_requirements({"waldiez"}, upgrade, printer)
|
waldiez/running/protocol.py
CHANGED
|
@@ -204,6 +204,7 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
204
204
|
uploads_root: Path | None,
|
|
205
205
|
temp_dir: Path,
|
|
206
206
|
skip_mmd: bool,
|
|
207
|
+
skip_timeline: bool,
|
|
207
208
|
) -> None:
|
|
208
209
|
"""Actions to perform after running the flow.
|
|
209
210
|
|
|
@@ -221,6 +222,8 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
221
222
|
The path to the temporary directory.
|
|
222
223
|
skip_mmd : bool
|
|
223
224
|
Whether to skip generating the mermaid diagram.
|
|
225
|
+
skip_timeline : bool
|
|
226
|
+
Whether to skip generating the timeline JSON.
|
|
224
227
|
"""
|
|
225
228
|
|
|
226
229
|
async def a_after_run(
|
|
@@ -234,6 +237,7 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
234
237
|
uploads_root: Path | None,
|
|
235
238
|
temp_dir: Path,
|
|
236
239
|
skip_mmd: bool,
|
|
240
|
+
skip_timeline: bool,
|
|
237
241
|
) -> None:
|
|
238
242
|
"""Asynchronously perform actions after running the flow.
|
|
239
243
|
|
|
@@ -251,6 +255,8 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
251
255
|
The path to the temporary directory.
|
|
252
256
|
skip_mmd : bool
|
|
253
257
|
Whether to skip generating the mermaid diagram.
|
|
258
|
+
skip_timeline : bool
|
|
259
|
+
Whether to skip generating the timeline JSON.
|
|
254
260
|
"""
|
|
255
261
|
|
|
256
262
|
def is_running(self) -> bool: # pyright: ignore
|
|
@@ -49,6 +49,7 @@ class WaldiezSubprocessRunner(WaldiezBaseRunner):
|
|
|
49
49
|
output_file: Path,
|
|
50
50
|
uploads_root: Path | None,
|
|
51
51
|
skip_mmd: bool,
|
|
52
|
+
skip_timeline: bool,
|
|
52
53
|
) -> Union[
|
|
53
54
|
"ChatResult",
|
|
54
55
|
list["ChatResult"],
|
|
@@ -63,6 +64,7 @@ class WaldiezSubprocessRunner(WaldiezBaseRunner):
|
|
|
63
64
|
output_file: Path,
|
|
64
65
|
uploads_root: Path | None,
|
|
65
66
|
skip_mmd: bool,
|
|
67
|
+
skip_timeline: bool,
|
|
66
68
|
) -> Union[
|
|
67
69
|
"ChatResult",
|
|
68
70
|
list["ChatResult"],
|
|
@@ -77,6 +79,7 @@ class WaldiezSubprocessRunner(WaldiezBaseRunner):
|
|
|
77
79
|
output_file: Path,
|
|
78
80
|
uploads_root: Path | None,
|
|
79
81
|
skip_mmd: bool,
|
|
82
|
+
skip_timeline: bool,
|
|
80
83
|
) -> None:
|
|
81
84
|
"""Start the Waldiez workflow."""
|
|
82
85
|
# This method should be implemented to start the workflow
|
|
@@ -88,6 +91,7 @@ class WaldiezSubprocessRunner(WaldiezBaseRunner):
|
|
|
88
91
|
output_file: Path,
|
|
89
92
|
uploads_root: Path | None,
|
|
90
93
|
skip_mmd: bool,
|
|
94
|
+
skip_timeline: bool,
|
|
91
95
|
) -> None:
|
|
92
96
|
"""Start the Waldiez workflow asynchronously."""
|
|
93
97
|
# This method should be implemented to start the workflow asynchronously
|