waldiez 0.1.2__py3-none-any.whl → 0.1.4__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/exporting/flow/flow.py +9 -4
- waldiez/exporting/models/__init__.py +69 -20
- waldiez/exporting/utils/importing.py +9 -11
- waldiez/models/agents/agent/termination_message.py +2 -1
- {waldiez-0.1.2.dist-info → waldiez-0.1.4.dist-info}/METADATA +2 -2
- {waldiez-0.1.2.dist-info → waldiez-0.1.4.dist-info}/RECORD +10 -10
- {waldiez-0.1.2.dist-info → waldiez-0.1.4.dist-info}/WHEEL +0 -0
- {waldiez-0.1.2.dist-info → waldiez-0.1.4.dist-info}/entry_points.txt +0 -0
- {waldiez-0.1.2.dist-info → waldiez-0.1.4.dist-info}/licenses/LICENSE +0 -0
waldiez/_version.py
CHANGED
waldiez/exporting/flow/flow.py
CHANGED
|
@@ -80,19 +80,22 @@ def export_flow(
|
|
|
80
80
|
"import os",
|
|
81
81
|
"import sqlite3",
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
common_imports: Set[str] = {
|
|
84
84
|
"from autogen import Agent",
|
|
85
85
|
"from autogen import ConversableAgent",
|
|
86
86
|
"from autogen import ChatResult",
|
|
87
87
|
"from autogen import runtime_logging",
|
|
88
88
|
}
|
|
89
|
+
local_imports: Set[str] = {
|
|
90
|
+
"from waldiez_api_keys import get_model_api_key",
|
|
91
|
+
}
|
|
89
92
|
skill_imports, _ = export_skills(
|
|
90
93
|
skills=all_skills,
|
|
91
94
|
skill_names=skill_names,
|
|
92
95
|
output_dir=output_dir,
|
|
93
96
|
)
|
|
94
97
|
if len(waldiez.chats) > 1:
|
|
95
|
-
|
|
98
|
+
common_imports.add("from autogen import initiate_chats")
|
|
96
99
|
for agent in all_agents:
|
|
97
100
|
agent_string, after_agent, agent_imports = export_agent(
|
|
98
101
|
agent=agent,
|
|
@@ -103,7 +106,7 @@ def export_flow(
|
|
|
103
106
|
all_skills=all_skills,
|
|
104
107
|
group_chat_members=waldiez.flow.get_group_chat_members(agent.id),
|
|
105
108
|
)
|
|
106
|
-
|
|
109
|
+
common_imports.update(agent_imports)
|
|
107
110
|
if after_agent:
|
|
108
111
|
skipped_agent_strings += after_agent
|
|
109
112
|
if agent.agent_type == "manager":
|
|
@@ -123,11 +126,13 @@ def export_flow(
|
|
|
123
126
|
all_models=all_models,
|
|
124
127
|
model_names=model_names,
|
|
125
128
|
notebook=notebook,
|
|
129
|
+
output_dir=output_dir,
|
|
126
130
|
)
|
|
127
131
|
all_imports_string = get_imports_string(
|
|
128
|
-
imports=
|
|
132
|
+
imports=common_imports,
|
|
129
133
|
builtin_imports=builtin_imports,
|
|
130
134
|
skill_imports=skill_imports,
|
|
135
|
+
local_imports=local_imports,
|
|
131
136
|
)
|
|
132
137
|
return _combine_strings(
|
|
133
138
|
waldiez=waldiez,
|
|
@@ -6,7 +6,8 @@ export_models
|
|
|
6
6
|
Get the string representations of the LLM configs.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
from
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Dict, List, Optional
|
|
10
11
|
|
|
11
12
|
from waldiez.models import WaldiezModel
|
|
12
13
|
|
|
@@ -17,6 +18,7 @@ def export_models(
|
|
|
17
18
|
all_models: List[WaldiezModel],
|
|
18
19
|
model_names: Dict[str, str],
|
|
19
20
|
notebook: bool,
|
|
21
|
+
output_dir: Optional[Path] = None,
|
|
20
22
|
) -> str:
|
|
21
23
|
"""Get the string representations of the LLM configs.
|
|
22
24
|
|
|
@@ -28,7 +30,8 @@ def export_models(
|
|
|
28
30
|
A mapping of model ids to model names.
|
|
29
31
|
notebook : bool
|
|
30
32
|
Whether to export the string for a jupyter notebook.
|
|
31
|
-
|
|
33
|
+
output_dir : Optional[Path]
|
|
34
|
+
The output directory to write the api keys.
|
|
32
35
|
Returns
|
|
33
36
|
-------
|
|
34
37
|
str
|
|
@@ -38,7 +41,8 @@ def export_models(
|
|
|
38
41
|
-------
|
|
39
42
|
```python
|
|
40
43
|
>>> from waldiez.models import WaldiezModel, WaldiezModelData
|
|
41
|
-
>>>
|
|
44
|
+
>>> api_key = "1234567890"
|
|
45
|
+
... model = WaldiezModel(
|
|
42
46
|
... id="wm-1",
|
|
43
47
|
... name="llama3.1" ,
|
|
44
48
|
... description="A model for llamas :P.",
|
|
@@ -46,7 +50,7 @@ def export_models(
|
|
|
46
50
|
... requirements=[],
|
|
47
51
|
... data=WaldiezModelData(
|
|
48
52
|
... base_url="https://example.com/v1",
|
|
49
|
-
... api_key=
|
|
53
|
+
... api_key=api_key,
|
|
50
54
|
... api_type="openai",
|
|
51
55
|
... temperature=0.5,
|
|
52
56
|
... price={
|
|
@@ -61,9 +65,9 @@ def export_models(
|
|
|
61
65
|
# # Models
|
|
62
66
|
llama3_1_llm_config = {
|
|
63
67
|
"config_list": [{
|
|
64
|
-
"model": "
|
|
68
|
+
"model": "llama3_1",
|
|
65
69
|
"base_url": "https://example.com/v1",
|
|
66
|
-
"api_key": "
|
|
70
|
+
"api_key": get_model_api_key("llama3_1"),
|
|
67
71
|
"api_type": "openai",
|
|
68
72
|
"temperature": 0.5,
|
|
69
73
|
"price": [0.0001, 0.0002],
|
|
@@ -72,26 +76,22 @@ def export_models(
|
|
|
72
76
|
```
|
|
73
77
|
"""
|
|
74
78
|
content = get_comment("models", notebook) + "\n"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
llm_config =
|
|
79
|
+
for model in all_models:
|
|
80
|
+
model_name = model_names[model.id]
|
|
81
|
+
llm_config = model.get_llm_config()
|
|
82
|
+
llm_config["api_key"] = f'get_model_api_key("{model_name}")'
|
|
79
83
|
model_dict_str = get_object_string(llm_config, tabs=2)
|
|
84
|
+
model_dict_str = model_dict_str.replace(
|
|
85
|
+
f'"get_model_api_key("{model_name}")"',
|
|
86
|
+
f'get_model_api_key("{model_name}")',
|
|
87
|
+
)
|
|
80
88
|
content += f"{model_name}_llm_config = " + "{\n"
|
|
81
89
|
content += ' "config_list": [\n'
|
|
82
90
|
content += f" {model_dict_str}\n"
|
|
83
91
|
content += " ]\n"
|
|
84
92
|
content += "}\n"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
model_name = model_names[model.id]
|
|
88
|
-
llm_config = model.get_llm_config()
|
|
89
|
-
model_dict_str = get_object_string(llm_config, tabs=2)
|
|
90
|
-
content += f"{model_name}_llm_config = " + "{\n"
|
|
91
|
-
content += ' "config_list": [\n'
|
|
92
|
-
content += f" {model_dict_str}\n"
|
|
93
|
-
content += " ]\n"
|
|
94
|
-
content += "}\n"
|
|
93
|
+
if output_dir:
|
|
94
|
+
write_api_keys(all_models, model_names, output_dir)
|
|
95
95
|
return content
|
|
96
96
|
|
|
97
97
|
|
|
@@ -191,3 +191,52 @@ def export_agent_models(
|
|
|
191
191
|
content += " ]\n"
|
|
192
192
|
content += "}\n"
|
|
193
193
|
return content
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def write_api_keys(
|
|
197
|
+
all_models: List[WaldiezModel],
|
|
198
|
+
model_names: Dict[str, str],
|
|
199
|
+
output_dir: Path,
|
|
200
|
+
) -> None:
|
|
201
|
+
"""Write the api keys to a separate file.
|
|
202
|
+
|
|
203
|
+
Parameters
|
|
204
|
+
----------
|
|
205
|
+
all_models : List[WaldiezModel]
|
|
206
|
+
All the models in the flow.
|
|
207
|
+
model_names : Dict[str, str]
|
|
208
|
+
A mapping of model ids to model names.
|
|
209
|
+
output_dir : Path
|
|
210
|
+
The output directory to write the api keys.
|
|
211
|
+
"""
|
|
212
|
+
# example call: llama3_1_api_key = get_model_api_key("llama3_1")
|
|
213
|
+
api_keys_content = '''
|
|
214
|
+
"""API keys for the models."""
|
|
215
|
+
|
|
216
|
+
__ALL_MODEL_API_KEYS__ = {
|
|
217
|
+
'''
|
|
218
|
+
for model in all_models:
|
|
219
|
+
model_name = model_names[model.id]
|
|
220
|
+
api_keys_content += f' "{model_name}": "{model.api_key}",\n'
|
|
221
|
+
api_keys_content += "}\n"
|
|
222
|
+
|
|
223
|
+
api_keys_content += '''
|
|
224
|
+
|
|
225
|
+
def get_model_api_key(model_name: str) -> str:
|
|
226
|
+
"""Get the api key for the model.
|
|
227
|
+
|
|
228
|
+
Parameters
|
|
229
|
+
----------
|
|
230
|
+
model_name : str
|
|
231
|
+
The name of the model.
|
|
232
|
+
|
|
233
|
+
Returns
|
|
234
|
+
-------
|
|
235
|
+
str
|
|
236
|
+
The api key for the model.
|
|
237
|
+
"""
|
|
238
|
+
return __ALL_MODEL_API_KEYS__.get(model_name, "")
|
|
239
|
+
'''
|
|
240
|
+
|
|
241
|
+
with open(output_dir / "waldiez_api_keys.py", "w", encoding="utf-8") as f:
|
|
242
|
+
f.write(api_keys_content)
|
|
@@ -65,7 +65,7 @@ def get_imports_string(
|
|
|
65
65
|
skill_imports: Set[str],
|
|
66
66
|
typing_imports: Optional[Set[str]] = None,
|
|
67
67
|
builtin_imports: Optional[Set[str]] = None,
|
|
68
|
-
|
|
68
|
+
local_imports: Optional[Set[str]] = None,
|
|
69
69
|
) -> str:
|
|
70
70
|
"""Get the imports.
|
|
71
71
|
|
|
@@ -79,8 +79,8 @@ def get_imports_string(
|
|
|
79
79
|
The typing imports, by default None.
|
|
80
80
|
builtin_imports : Set[str], optional
|
|
81
81
|
The builtin imports, by default None.
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
local_imports : Set[str], optional
|
|
83
|
+
The local imports (like for getting model api keys), by default None.
|
|
84
84
|
|
|
85
85
|
Returns
|
|
86
86
|
-------
|
|
@@ -107,10 +107,12 @@ def get_imports_string(
|
|
|
107
107
|
typing_imports = DEFAULT_TYPING_IMPORTS
|
|
108
108
|
if not builtin_imports:
|
|
109
109
|
builtin_imports = set()
|
|
110
|
-
if not
|
|
111
|
-
|
|
110
|
+
if not local_imports:
|
|
111
|
+
local_imports = set()
|
|
112
112
|
string = _get_builtin_imports_string(builtin_imports, typing_imports)
|
|
113
|
-
string += _get_third_party_imports_string(imports
|
|
113
|
+
string += _get_third_party_imports_string(imports)
|
|
114
|
+
if local_imports:
|
|
115
|
+
string += "\n\n" + "\n".join(sorted(local_imports)) + "\n"
|
|
114
116
|
string += _get_skill_imports_string(skill_imports)
|
|
115
117
|
string = "\n\n".join([line for line in string.split("\n\n") if line])
|
|
116
118
|
while not string.endswith("\n\n"):
|
|
@@ -234,13 +236,9 @@ def _get_autogen_imports(
|
|
|
234
236
|
return autogen_imports, autogen_dot_imports, remaining_imports
|
|
235
237
|
|
|
236
238
|
|
|
237
|
-
def _get_third_party_imports_string(
|
|
238
|
-
imports: Set[str],
|
|
239
|
-
other_imports: Set[str],
|
|
240
|
-
) -> str:
|
|
239
|
+
def _get_third_party_imports_string(imports: Set[str]) -> str:
|
|
241
240
|
"""Get the third party imports."""
|
|
242
241
|
autogen_imports, autogen_dot_imports, rest = _get_autogen_imports(imports)
|
|
243
|
-
rest.update(other_imports)
|
|
244
242
|
plain_imports, from_imports_dict = _prepare_imports(
|
|
245
243
|
autogen_imports=autogen_imports,
|
|
246
244
|
autogen_dot_imports=autogen_dot_imports,
|
|
@@ -136,7 +136,8 @@ class WaldiezAgentTerminationMessage(WaldiezBase):
|
|
|
136
136
|
)
|
|
137
137
|
if self.criterion == "ending":
|
|
138
138
|
self._string = (
|
|
139
|
-
'lambda x: any(x.get("content", "")
|
|
139
|
+
'lambda x: any(x.get("content", "") and '
|
|
140
|
+
'x.get("content", "").endswith(keyword) '
|
|
140
141
|
f"for keyword in [{keywords_str}])"
|
|
141
142
|
)
|
|
142
143
|
if self.criterion == "exact":
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: waldiez
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: waldiez
|
|
5
5
|
Project-URL: homepage, https://waldiez.github.io/py/
|
|
6
6
|
Project-URL: repository, https://github.com/waldiez/py.git
|
|
@@ -177,4 +177,4 @@ io_stream.close()
|
|
|
177
177
|
|
|
178
178
|
## License
|
|
179
179
|
|
|
180
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
180
|
+
This project is licensed under the MIT License - see the [LICENSE](https://github.com/waldiez/py/blob/main/LICENSE) file for details.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
waldiez/__init__.py,sha256=pX6lHj8fNlfqCpHEfF6MNQBCR6qRjFYjwBSOCoxrlwk,313
|
|
2
2
|
waldiez/__main__.py,sha256=9xR-F2ohZcRPDG6KrM7cJpXciKX-u6WdL221ckyJ04k,112
|
|
3
|
-
waldiez/_version.py,sha256=
|
|
3
|
+
waldiez/_version.py,sha256=N-ZsihH4RZovpgrN6mkwtpRExfYJUp8a4NSA9bZB5WA,62
|
|
4
4
|
waldiez/cli.py,sha256=vIQDqs9XBOlDpshq7rNgvoTcnnkeZrsXa_51gMWs6H4,4690
|
|
5
5
|
waldiez/exporter.py,sha256=iKe-l_Me8NRWsXHIdBcrOrnLT9XIyp4iYi4HLuuj2jA,9342
|
|
6
6
|
waldiez/io_stream.py,sha256=YczhIw0PKEsxCSY6tAqElCqOUh8b-aEkSIGC1JjXxAs,5877
|
|
@@ -28,12 +28,12 @@ waldiez/exporting/chats/helpers.py,sha256=LmbOKXxMMSf2D1up8CNxxitUDvZ-Z_8NNxJFcP
|
|
|
28
28
|
waldiez/exporting/chats/nested.py,sha256=39qodz8Lct2SDjIjEHSxNUls9T4UtfLBEeiBcmqydbA,8254
|
|
29
29
|
waldiez/exporting/flow/__init__.py,sha256=WhdPrjXQAcihrS1KUtPNgbx0y1tqD5HtGykzpEAcsBM,98
|
|
30
30
|
waldiez/exporting/flow/def_main.py,sha256=YpdhqO4iFng3r7if69ZPMJAibPVNDqnrOrWvGw7CJq8,1052
|
|
31
|
-
waldiez/exporting/flow/flow.py,sha256=
|
|
32
|
-
waldiez/exporting/models/__init__.py,sha256=
|
|
31
|
+
waldiez/exporting/flow/flow.py,sha256=x2AlXr7aJJfrPMeuXQYfT9sG5GycMwf0kRkovZWKGag,6206
|
|
32
|
+
waldiez/exporting/models/__init__.py,sha256=_Yt6sBAyRrN3LSAg4Nrh4dP7pmtIzGzWu4G1AutxK-Q,7078
|
|
33
33
|
waldiez/exporting/skills/__init__.py,sha256=oIA9f5ABtYSbS0kMY_4ovU3-m6meVk5blEu_xViZsRU,3536
|
|
34
34
|
waldiez/exporting/utils/__init__.py,sha256=tP1V4g9-MyARlfOEL_1YWMJNW7UivUrrukq7DIwdq6k,1018
|
|
35
35
|
waldiez/exporting/utils/comments.py,sha256=X9j8w48rh3DfFDjiMverU9DBSuE9yuMMbbStxBbN1sE,3190
|
|
36
|
-
waldiez/exporting/utils/importing.py,sha256=
|
|
36
|
+
waldiez/exporting/utils/importing.py,sha256=dA4HCQ-OxmodUjovgXyLI9IwNvLwbY67P41969XoZ7g,8649
|
|
37
37
|
waldiez/exporting/utils/logging_utils.py,sha256=uoV6O23lfB5ztOYEZiYu8Mn-2xEUwp_Qx404Mr62i7M,5822
|
|
38
38
|
waldiez/exporting/utils/method_utils.py,sha256=7-RUMTylNM2W0iM1bPX2_Gn3553XZSl2s2VGEijxNp4,891
|
|
39
39
|
waldiez/exporting/utils/naming.py,sha256=VdoVODQduhXIs9hQFWUVEVqTaSyNDt7rkECsuIgXYwI,3196
|
|
@@ -50,7 +50,7 @@ waldiez/models/agents/agent/code_execution.py,sha256=kgL3pbEEyuMvJid0sIbfe4os7SW
|
|
|
50
50
|
waldiez/models/agents/agent/linked_skill.py,sha256=8RHWHkHXqFuv7lEe1PuQoK1hTO3kBQ7ILKm9kCEWqNs,667
|
|
51
51
|
waldiez/models/agents/agent/nested_chat.py,sha256=DAF3TCbTwyDvg6PGbeETtBLCQ4Xz5Saw5a4Xi-jr6jA,1929
|
|
52
52
|
waldiez/models/agents/agent/teachability.py,sha256=IIR4LY9dwx3T7Ok17RYN2g6zGiga2gGizGteaeI3eGs,1703
|
|
53
|
-
waldiez/models/agents/agent/termination_message.py,sha256=
|
|
53
|
+
waldiez/models/agents/agent/termination_message.py,sha256=aGsIdwGs42BxDktkxoqHGEWM1wzhXr-zh_MlETsbycA,5674
|
|
54
54
|
waldiez/models/agents/assistant/__init__.py,sha256=Zlf-4EI9HXl-LrqGosL7UucoyqIl74GZzohZlRLx2QI,175
|
|
55
55
|
waldiez/models/agents/assistant/assistant.py,sha256=OFh5nr8HrOLg2KXnwzFUU7_JBWrYfM7lRtTRQT1E_gI,1095
|
|
56
56
|
waldiez/models/agents/assistant/assistant_data.py,sha256=VGdF1IZBBqBvZwe6BP2s4LinmkQ2IjesaDvs9Me9iHY,823
|
|
@@ -88,8 +88,8 @@ waldiez/stream/__init__.py,sha256=6qst5j2iXmV-wDTnhgCna3llqUfJ6tkR0HBq7Vx9x-Q,19
|
|
|
88
88
|
waldiez/stream/consumer.py,sha256=VQDJEomYpGjmAtOoFBJrpCyoYzwykJUIOrdiLn08Uj4,4049
|
|
89
89
|
waldiez/stream/provider.py,sha256=JqnnR1yAimfK4HxW4gr4HIoJ15Ly71kXn75mv7FZBmw,9478
|
|
90
90
|
waldiez/stream/server.py,sha256=Ya4AKP5Wr_xAsbG3Q-qShqHmfIyamj9LGXizJsL-N4Y,11815
|
|
91
|
-
waldiez-0.1.
|
|
92
|
-
waldiez-0.1.
|
|
93
|
-
waldiez-0.1.
|
|
94
|
-
waldiez-0.1.
|
|
95
|
-
waldiez-0.1.
|
|
91
|
+
waldiez-0.1.4.dist-info/METADATA,sha256=ppqb9brA_gfW5p5aiiMNCgH9AS02k4gf1OVoyZLQXo0,6785
|
|
92
|
+
waldiez-0.1.4.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
93
|
+
waldiez-0.1.4.dist-info/entry_points.txt,sha256=5Po4yQXPa_QEdtTevpEBgr3rGoIvDMeQuJR2zqwBLBo,45
|
|
94
|
+
waldiez-0.1.4.dist-info/licenses/LICENSE,sha256=VQEHM6WMQLRu1qaGl3GWsoOknDwro-69eGo4NLIJPIM,1064
|
|
95
|
+
waldiez-0.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|