waldiez 0.2.2__py3-none-any.whl → 0.3.0__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.

Files changed (138) hide show
  1. waldiez/__init__.py +2 -0
  2. waldiez/__main__.py +2 -0
  3. waldiez/_version.py +3 -1
  4. waldiez/cli.py +13 -3
  5. waldiez/cli_extras.py +4 -3
  6. waldiez/conflict_checker.py +4 -3
  7. waldiez/exporter.py +28 -105
  8. waldiez/exporting/__init__.py +8 -9
  9. waldiez/exporting/agent/__init__.py +7 -0
  10. waldiez/exporting/agent/agent_exporter.py +279 -0
  11. waldiez/exporting/agent/utils/__init__.py +23 -0
  12. waldiez/exporting/agent/utils/agent_class_name.py +34 -0
  13. waldiez/exporting/agent/utils/agent_imports.py +50 -0
  14. waldiez/exporting/{agents → agent/utils}/code_execution.py +9 -11
  15. waldiez/exporting/{agents → agent/utils}/group_manager.py +47 -35
  16. waldiez/exporting/{agents → agent/utils}/rag_user/__init__.py +2 -0
  17. waldiez/exporting/{agents → agent/utils}/rag_user/chroma_utils.py +22 -17
  18. waldiez/exporting/{agents → agent/utils}/rag_user/mongo_utils.py +14 -10
  19. waldiez/exporting/{agents → agent/utils}/rag_user/pgvector_utils.py +12 -8
  20. waldiez/exporting/{agents → agent/utils}/rag_user/qdrant_utils.py +11 -8
  21. waldiez/exporting/{agents → agent/utils}/rag_user/rag_user.py +78 -55
  22. waldiez/exporting/{agents → agent/utils}/rag_user/vector_db.py +10 -8
  23. waldiez/exporting/agent/utils/swarm_agent.py +463 -0
  24. waldiez/exporting/{agents → agent/utils}/teachability.py +10 -6
  25. waldiez/exporting/{agents → agent/utils}/termination_message.py +7 -8
  26. waldiez/exporting/base/__init__.py +25 -0
  27. waldiez/exporting/base/agent_position.py +75 -0
  28. waldiez/exporting/base/base_exporter.py +118 -0
  29. waldiez/exporting/base/export_position.py +48 -0
  30. waldiez/exporting/base/import_position.py +23 -0
  31. waldiez/exporting/base/mixin.py +134 -0
  32. waldiez/exporting/base/utils/__init__.py +18 -0
  33. waldiez/exporting/{utils → base/utils}/comments.py +12 -55
  34. waldiez/exporting/{utils → base/utils}/naming.py +14 -4
  35. waldiez/exporting/base/utils/path_check.py +68 -0
  36. waldiez/exporting/{utils/object_string.py → base/utils/to_string.py} +21 -20
  37. waldiez/exporting/chats/__init__.py +5 -12
  38. waldiez/exporting/chats/chats_exporter.py +240 -0
  39. waldiez/exporting/chats/utils/__init__.py +15 -0
  40. waldiez/exporting/chats/utils/common.py +81 -0
  41. waldiez/exporting/chats/{nested.py → utils/nested.py} +125 -86
  42. waldiez/exporting/chats/utils/sequential.py +244 -0
  43. waldiez/exporting/chats/utils/single_chat.py +313 -0
  44. waldiez/exporting/chats/utils/swarm.py +207 -0
  45. waldiez/exporting/flow/__init__.py +5 -3
  46. waldiez/exporting/flow/flow_exporter.py +503 -0
  47. waldiez/exporting/flow/utils/__init__.py +47 -0
  48. waldiez/exporting/flow/utils/agent_utils.py +204 -0
  49. waldiez/exporting/flow/utils/chat_utils.py +71 -0
  50. waldiez/exporting/flow/utils/def_main.py +62 -0
  51. waldiez/exporting/flow/utils/flow_content.py +112 -0
  52. waldiez/exporting/flow/utils/flow_names.py +115 -0
  53. waldiez/exporting/flow/utils/importing_utils.py +179 -0
  54. waldiez/exporting/{utils → flow/utils}/logging_utils.py +34 -31
  55. waldiez/exporting/models/__init__.py +7 -242
  56. waldiez/exporting/models/models_exporter.py +192 -0
  57. waldiez/exporting/models/utils.py +166 -0
  58. waldiez/exporting/skills/__init__.py +7 -161
  59. waldiez/exporting/skills/skills_exporter.py +169 -0
  60. waldiez/exporting/skills/utils.py +281 -0
  61. waldiez/models/__init__.py +25 -7
  62. waldiez/models/agents/__init__.py +70 -0
  63. waldiez/models/agents/agent/__init__.py +11 -1
  64. waldiez/models/agents/agent/agent.py +9 -4
  65. waldiez/models/agents/agent/agent_data.py +3 -1
  66. waldiez/models/agents/agent/code_execution.py +2 -0
  67. waldiez/models/agents/agent/linked_skill.py +2 -0
  68. waldiez/models/agents/agent/nested_chat.py +2 -0
  69. waldiez/models/agents/agent/teachability.py +2 -0
  70. waldiez/models/agents/agent/termination_message.py +49 -13
  71. waldiez/models/agents/agents.py +15 -3
  72. waldiez/models/agents/assistant/__init__.py +2 -0
  73. waldiez/models/agents/assistant/assistant.py +2 -0
  74. waldiez/models/agents/assistant/assistant_data.py +2 -0
  75. waldiez/models/agents/group_manager/__init__.py +9 -1
  76. waldiez/models/agents/group_manager/group_manager.py +2 -0
  77. waldiez/models/agents/group_manager/group_manager_data.py +2 -0
  78. waldiez/models/agents/group_manager/speakers.py +49 -13
  79. waldiez/models/agents/rag_user/__init__.py +21 -4
  80. waldiez/models/agents/rag_user/rag_user.py +3 -1
  81. waldiez/models/agents/rag_user/rag_user_data.py +2 -0
  82. waldiez/models/agents/rag_user/retrieve_config.py +268 -17
  83. waldiez/models/agents/rag_user/vector_db_config.py +5 -3
  84. waldiez/models/agents/swarm_agent/__init__.py +49 -0
  85. waldiez/models/agents/swarm_agent/after_work.py +178 -0
  86. waldiez/models/agents/swarm_agent/on_condition.py +103 -0
  87. waldiez/models/agents/swarm_agent/on_condition_available.py +140 -0
  88. waldiez/models/agents/swarm_agent/on_condition_target.py +40 -0
  89. waldiez/models/agents/swarm_agent/swarm_agent.py +107 -0
  90. waldiez/models/agents/swarm_agent/swarm_agent_data.py +125 -0
  91. waldiez/models/agents/swarm_agent/update_system_message.py +144 -0
  92. waldiez/models/agents/user_proxy/__init__.py +2 -0
  93. waldiez/models/agents/user_proxy/user_proxy.py +2 -0
  94. waldiez/models/agents/user_proxy/user_proxy_data.py +2 -0
  95. waldiez/models/chat/__init__.py +21 -3
  96. waldiez/models/chat/chat.py +241 -7
  97. waldiez/models/chat/chat_data.py +192 -48
  98. waldiez/models/chat/chat_message.py +153 -144
  99. waldiez/models/chat/chat_nested.py +33 -53
  100. waldiez/models/chat/chat_summary.py +2 -0
  101. waldiez/models/common/__init__.py +6 -6
  102. waldiez/models/common/base.py +4 -1
  103. waldiez/models/common/method_utils.py +163 -83
  104. waldiez/models/flow/__init__.py +2 -0
  105. waldiez/models/flow/flow.py +176 -40
  106. waldiez/models/flow/flow_data.py +63 -2
  107. waldiez/models/flow/utils.py +172 -0
  108. waldiez/models/model/__init__.py +2 -0
  109. waldiez/models/model/model.py +25 -6
  110. waldiez/models/model/model_data.py +3 -1
  111. waldiez/models/skill/__init__.py +4 -1
  112. waldiez/models/skill/skill.py +30 -2
  113. waldiez/models/skill/skill_data.py +2 -0
  114. waldiez/models/waldiez.py +28 -4
  115. waldiez/runner.py +142 -228
  116. waldiez/running/__init__.py +33 -0
  117. waldiez/running/environment.py +83 -0
  118. waldiez/running/gen_seq_diagram.py +185 -0
  119. waldiez/running/running.py +300 -0
  120. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/METADATA +32 -26
  121. waldiez-0.3.0.dist-info/RECORD +125 -0
  122. waldiez-0.3.0.dist-info/licenses/LICENSE +201 -0
  123. waldiez/exporting/agents/__init__.py +0 -5
  124. waldiez/exporting/agents/agent.py +0 -236
  125. waldiez/exporting/agents/agent_skills.py +0 -67
  126. waldiez/exporting/agents/llm_config.py +0 -53
  127. waldiez/exporting/chats/chats.py +0 -46
  128. waldiez/exporting/chats/helpers.py +0 -420
  129. waldiez/exporting/flow/def_main.py +0 -32
  130. waldiez/exporting/flow/flow.py +0 -189
  131. waldiez/exporting/utils/__init__.py +0 -36
  132. waldiez/exporting/utils/importing.py +0 -265
  133. waldiez/exporting/utils/method_utils.py +0 -35
  134. waldiez/exporting/utils/path_check.py +0 -51
  135. waldiez-0.2.2.dist-info/RECORD +0 -92
  136. waldiez-0.2.2.dist-info/licenses/LICENSE +0 -21
  137. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/WHEEL +0 -0
  138. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -1,53 +0,0 @@
1
- """Get an agent's llm config argument."""
2
-
3
- from typing import Dict, List, Tuple
4
-
5
- from waldiez.models import WaldiezAgent, WaldiezModel
6
-
7
- from ..models import export_agent_models
8
-
9
-
10
- def get_agent_llm_config(
11
- agent: WaldiezAgent,
12
- agent_name: str,
13
- all_models: List[WaldiezModel],
14
- model_names: Dict[str, str],
15
- ) -> Tuple[str, str]:
16
- """Get the llm config argument string for one agent.
17
-
18
- Parameters
19
- ----------
20
- agent : WaldiezAgent
21
- The agent.
22
- agent_name : str
23
- The name of the agent.
24
- all_models : List[WaldiezModel]
25
- All the models in the flow.
26
- model_names : Dict[str, str]
27
- A mapping of model id to model name.
28
-
29
- Returns
30
- -------
31
- Tuple[str, str]
32
- The llm config argument string and extra content
33
- to use before the argument (the variable definition if needed).
34
- """
35
- content_before = ""
36
- if not agent.data.model_ids:
37
- # no models
38
- return "False", content_before
39
- if len(agent.data.model_ids) == 1:
40
- # one model
41
- model_id = agent.data.model_ids[0]
42
- model_name = model_names[model_id]
43
- return f"{model_name}_llm_config", content_before
44
- arg = f"{agent_name}_llm_config"
45
- content_before = "\n" + (
46
- export_agent_models(
47
- agent_model_ids=agent.data.model_ids,
48
- all_models=all_models,
49
- agent_name=agent_name,
50
- )
51
- + "\n"
52
- )
53
- return arg, content_before
@@ -1,46 +0,0 @@
1
- """Export the chats content."""
2
-
3
- from typing import Dict, List, Tuple
4
-
5
- from waldiez.models import WaldiezAgent, WaldiezChat
6
-
7
- from .helpers import export_multiple_chats_string, export_single_chat_string
8
-
9
-
10
- def export_chats(
11
- main_chats: List[Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent]],
12
- agent_names: Dict[str, str],
13
- chat_names: Dict[str, str],
14
- tabs: int,
15
- ) -> Tuple[str, str]:
16
- """Get the chats content.
17
-
18
- Parameters
19
- ----------
20
- main_chats : List[Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent]]
21
- The main flow chats.
22
- agent_names : Dict[str, str]
23
- A mapping of agent id to agent name.
24
- chat_names : Dict[str, str]
25
- A mapping of chat id to chat name.
26
- tabs : int
27
- The number of tabs to use for indentation.
28
-
29
- Returns
30
- -------
31
- Tuple[str, str]
32
- The chats content and additional methods string if any.
33
- """
34
- if len(main_chats) == 1:
35
- return export_single_chat_string(
36
- flow=main_chats[0],
37
- agent_names=agent_names,
38
- chat_names=chat_names,
39
- tabs=tabs,
40
- )
41
- return export_multiple_chats_string(
42
- main_chats=main_chats,
43
- chat_names=chat_names,
44
- agent_names=agent_names,
45
- tabs=tabs,
46
- )
@@ -1,420 +0,0 @@
1
- """Helper functions for exporting chat data to code.
2
-
3
- Functions
4
- ---------
5
- export_single_chat_string
6
- Get the chat string when there is only one chat in the flow.
7
- export_multiple_chats_string
8
- Get the chats content, when there are more than one chats in the flow.
9
- """
10
-
11
- # flake8: noqa E501
12
- from typing import Any, Dict, List, Optional, Tuple
13
-
14
- from waldiez.models import (
15
- WaldiezAgent,
16
- WaldiezChat,
17
- WaldiezChatMessage,
18
- WaldiezRagUser,
19
- )
20
-
21
- from ..utils import get_escaped_string, get_object_string
22
-
23
-
24
- # pylint: disable=line-too-long
25
- def export_single_chat_string(
26
- flow: Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent],
27
- agent_names: Dict[str, str],
28
- chat_names: Dict[str, str],
29
- tabs: int,
30
- ) -> Tuple[str, str]:
31
- """Get the chat string when there is only one chat in the flow.
32
-
33
- Parameters
34
- ----------
35
- flow : Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent]
36
- The chat flow.
37
- agent_names : Dict[str, str]
38
- A mapping of agent id to agent name.
39
- chat_names : Dict[str, str]
40
- A mapping of chat id to chat name.
41
- tabs : int
42
- The number of tabs to use for indentation.
43
-
44
- Returns
45
- -------
46
- Tuple[str, str]
47
- The chat string and additional methods string if any
48
-
49
- Example
50
- -------
51
- ```python
52
- >>> from waldiez.models import WaldiezAgent, WaldiezChat, WaldiezChatData, WaldiezChatMessage
53
- >>> chat = WaldiezChat(
54
- ... id="wc-1",
55
- ... name="chat1",
56
- ... description="A chat between two agents.",
57
- ... tags=["chat", "chat1"],
58
- ... requirements=[],
59
- ... data=WaldiezChatData(
60
- ... sender="wa-1",
61
- ... recipient="wa-2",
62
- ... message=WaldiezChatMessage(
63
- ... type="string",
64
- ... content="Hello, how are you?",
65
- ... ),
66
- ... ),
67
- ... )
68
- >>> agent_names = {"wa-1": "agent1", "wa-2": "agent2"}
69
- >>> chat_names = {"wc-1": "chat1"}
70
- >>> export_single_chat_string((chat, agent1, agent2), agent_names, chat_names, 0)
71
- agent1.initiate_chat(
72
- agent2,
73
- message="Hello, how are you?",
74
- )
75
- ```
76
- """
77
- tab = " " * tabs
78
- chat, sender, recipient = flow
79
- chat_args = chat.get_chat_args(sender=sender)
80
- chat_args = escape_summary_args_quotes(chat_args)
81
- if not chat_args:
82
- return _get_empty_simple_chat_string(
83
- tab,
84
- chat=chat,
85
- sender=sender,
86
- recipient=recipient,
87
- agent_names=agent_names,
88
- )
89
- return _get_simple_chat_string(
90
- chat=chat,
91
- chat_args=chat_args,
92
- sender=sender,
93
- recipient=recipient,
94
- agent_names=agent_names,
95
- chat_names=chat_names,
96
- tabs=tabs,
97
- )
98
-
99
-
100
- def export_multiple_chats_string(
101
- main_chats: List[Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent]],
102
- chat_names: Dict[str, str],
103
- agent_names: Dict[str, str],
104
- tabs: int,
105
- ) -> Tuple[str, str]:
106
- """Get the chats content, when there are more than one chats in the flow.
107
-
108
- Parameters
109
- ----------
110
- main_chats : List[Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent]]
111
- The main chats.
112
- chat_names : Dict[str, str]
113
- A mapping of chat id to chat name.
114
- agent_names : Dict[str, str]
115
- A mapping of agent id to agent name.
116
- tabs : int
117
- The number of tabs to use for indentation.
118
-
119
- Returns
120
- -------
121
- Tuple[str, str]
122
- The main chats content and additional methods string if any.
123
-
124
- Example
125
- -------
126
- ```python
127
- >>> from waldiez.models import WaldiezAgent, WaldiezChat, WaldiezChatData, WaldiezChatMessage
128
- >>> chat1 = WaldiezChat(
129
- ... id="wc-1",
130
- ... name="chat1",
131
- ... description="A chat between two agents.",
132
- ... tags=["chat", "chat1"],
133
- ... requirements=[],
134
- ... data=WaldiezChatData(
135
- ... sender="wa-1",
136
- ... recipient="wa-2",
137
- ... position=0,
138
- ... message=WaldiezChatMessage(
139
- ... type="string",
140
- ... content="Hello, how are you?",
141
- ... ),
142
- ... ),
143
- ... )
144
- >>> chat2 = WaldiezChat(
145
- ... id="wc-2",
146
- ... name="chat2",
147
- ... description="A chat between two agents.",
148
- ... tags=["chat", "chat2"],
149
- ... requirements=[],
150
- ... data=WaldiezChatData(
151
- ... sender="wa-2",
152
- ... recipient="wa-1",
153
- ... position=1,
154
- ... message=WaldiezChatMessage(
155
- ... type="string",
156
- ... content="I am good, thank you. How about you?",
157
- ... ),
158
- ... ),
159
- ... )
160
- >>> agent_names = {"wa-1": "agent1", "wa-2": "agent2"}
161
- >>> chat_names = {"wc-1": "chat1", "wc-2": "chat2"}
162
- >>> export_multiple_chats_string([(chat1, agent1, agent2), (chat2, agent2, agent1)], chat_names, agent_names, 0)
163
- initiate_chats([
164
- {
165
- "sender": agent1,
166
- "recipient": agent2,
167
- "message": "Hello, how are you?",
168
- },
169
- {
170
- "sender": agent2,
171
- "recipient": agent1,
172
- "message": "I am good, thank you. How about you?",
173
- },
174
- ])
175
- ```
176
- """
177
- tab = " " * tabs
178
- content = "\n"
179
- additional_methods_string = ""
180
- content = "initiate_chats(["
181
- for chat, sender, recipient in main_chats:
182
- chat_string, additional_methods = _get_chat_dict_string(
183
- chat=chat,
184
- chat_names=chat_names,
185
- sender=sender,
186
- recipient=recipient,
187
- agent_names=agent_names,
188
- tabs=tabs + 1,
189
- )
190
- additional_methods_string += additional_methods
191
- content += f"\n{tab} {chat_string}"
192
- content += "\n" + " " * tabs + "])"
193
- return content, additional_methods_string
194
-
195
-
196
- def escape_summary_args_quotes(chat_args: Dict[str, Any]) -> Dict[str, Any]:
197
- """Escape quotes in the summary args if they are strings.
198
-
199
- Parameters
200
- ----------
201
- chat_args : Dict[str, Any]
202
- The chat arguments.
203
-
204
- Returns
205
- -------
206
- Dict[str, Any]
207
- The chat arguments with the summary prompt escaped.
208
- """
209
- if "summary_args" in chat_args and isinstance(
210
- chat_args["summary_args"], dict
211
- ):
212
- for key, value in chat_args["summary_args"].items():
213
- if isinstance(value, str):
214
- chat_args["summary_args"][key] = get_escaped_string(value)
215
- return chat_args
216
-
217
-
218
- def _get_chat_message_string(
219
- chat: WaldiezChat,
220
- chat_names: Dict[str, str],
221
- ) -> Tuple[str, Optional[str]]:
222
- """Get the agent's message as a string.
223
-
224
- Parameters
225
- ----------
226
- chat : WaldiezChat
227
- The chat.
228
- chat_names : Dict[str, str]
229
- A mapping of chat id to chat name with all the chats in the flow.
230
-
231
- Returns
232
- -------
233
- Tuple[str, Optional[str]]
234
- If the message is a string, the message content and None.
235
- If the message is a method, the method name and the method content.
236
- If the message is None, 'None' and None.
237
- """
238
- if (
239
- not chat.message
240
- or chat.message.type == "none"
241
- or chat.message.content is None
242
- or chat.message_content is None
243
- ):
244
- return "None", None
245
- if chat.message.type == "string":
246
- return get_escaped_string(chat.message.content), None
247
- chat_name = chat_names[chat.id]
248
- original_function_name = "callable_message"
249
- method_args = "sender, recipient, context"
250
- function_name = f"{original_function_name}_{chat_name}"
251
- function_def = f"def {function_name}({method_args}):"
252
- return function_name, function_def + "\n" + chat.message_content + "\n"
253
-
254
-
255
- def _get_chat_dict_string(
256
- chat: WaldiezChat,
257
- sender: WaldiezAgent,
258
- recipient: WaldiezAgent,
259
- chat_names: Dict[str, str],
260
- agent_names: Dict[str, str],
261
- tabs: int,
262
- ) -> Tuple[str, str]:
263
- """Get a chat dictionary string.
264
-
265
- If the chat message is a separate method and not a string or a lambda,
266
- we return the method string (definition and body) as well as the rest
267
- of the arguments.
268
-
269
- Parameters
270
- ----------
271
- chat : WaldiezChat
272
- The chat.
273
- sender : WaldiezAgent
274
- The sender.
275
- recipient : WaldiezAgent
276
- The recipient.
277
- chat_names : Dict[str, str]
278
- A mapping of chat id to chat name.
279
- agent_names : Dict[str, str]
280
- A mapping of agent id to agent name.
281
- tabs : int
282
- The number of tabs to use for indentation.
283
-
284
- Returns
285
- -------
286
- Tuple[str, str]
287
- The chat dictionary string and additional methods string if any.
288
- """
289
- tab = " " * tabs
290
- chat_args = chat.get_chat_args(sender=sender)
291
- chat_args = escape_summary_args_quotes(chat_args)
292
- chat_string = "{"
293
- chat_string += "\n" + f'{tab} "sender": {agent_names[sender.id]},'
294
- chat_string += "\n" + f'{tab} "recipient": {agent_names[recipient.id]},'
295
- additional_methods_string = ""
296
- for key, value in chat_args.items():
297
- if isinstance(value, str):
298
- chat_string += "\n" + f'{tab} "{key}": "{value}",'
299
- elif isinstance(value, dict):
300
- chat_string += (
301
- "\n"
302
- f'{tab} "{key}": {get_object_string(value, tabs=tabs + 1)},'
303
- )
304
- else:
305
- chat_string += "\n" + f'{tab} "{key}": {value},'
306
- if (
307
- sender.agent_type == "rag_user"
308
- and isinstance(sender, WaldiezRagUser)
309
- and chat.message.type == "rag_message_generator"
310
- ):
311
- message = f"{agent_names[sender.id]}.message_generator"
312
- chat_string += "\n" + f'{tab} "message": {message},'
313
- chat_string += "\n" + tab + "},"
314
- return chat_string, additional_methods_string
315
- message, method_content = _get_chat_message_string(
316
- chat=chat,
317
- chat_names=chat_names,
318
- )
319
- if message and isinstance(chat.data.message, WaldiezChatMessage):
320
- message = get_escaped_string(message)
321
- if chat.data.message.type == "method":
322
- if method_content:
323
- additional_methods_string += "\n" + method_content
324
- chat_string += "\n" + f'{tab} "message": {message},'
325
- elif chat.data.message.type == "string" and chat.data.message.content:
326
- chat_string += "\n" + f'{tab} "message": "{message}",'
327
- chat_string += "\n" + tab + "},"
328
- return chat_string, additional_methods_string
329
-
330
-
331
- def _get_empty_simple_chat_string(
332
- tab: str,
333
- chat: WaldiezChat,
334
- sender: WaldiezAgent,
335
- recipient: WaldiezAgent,
336
- agent_names: Dict[str, str],
337
- ) -> Tuple[str, str]:
338
- content = tab
339
- sender_name = agent_names[sender.id]
340
- recipient_name = agent_names[recipient.id]
341
- content += f"{sender_name}.initiate_chat(\n"
342
- content += tab + f" {recipient_name},\n"
343
- message_arg, _ = _get_chat_message(
344
- tab=tab,
345
- chat=chat,
346
- chat_names={},
347
- sender=sender,
348
- sender_name=sender_name,
349
- )
350
- content += message_arg
351
- content += tab + ")"
352
- return content, ""
353
-
354
-
355
- def _get_chat_message(
356
- tab: str,
357
- chat: WaldiezChat,
358
- chat_names: Dict[str, str],
359
- sender: WaldiezAgent,
360
- sender_name: str,
361
- ) -> Tuple[str, str]:
362
- additional_methods_string = ""
363
- method_content: Optional[str] = None
364
- if (
365
- sender.agent_type == "rag_user"
366
- and isinstance(sender, WaldiezRagUser)
367
- and chat.message.type == "rag_message_generator"
368
- ):
369
- message = f"{sender_name}.message_generator"
370
- return f"\n{tab} message={message},", additional_methods_string
371
- message, method_content = _get_chat_message_string(
372
- chat=chat,
373
- chat_names=chat_names,
374
- )
375
- if message and isinstance(chat.data.message, WaldiezChatMessage):
376
- message = get_escaped_string(message)
377
- if chat.data.message.type == "method":
378
- additional_methods_string += (
379
- method_content if method_content else ""
380
- )
381
- return f"\n{tab} message={message},", additional_methods_string
382
- if chat.message.type == "string" and chat.data.message.content:
383
- return f'\n{tab} message="{message}",', additional_methods_string
384
- return "", additional_methods_string
385
- return "", additional_methods_string # pragma: no cover
386
-
387
-
388
- def _get_simple_chat_string(
389
- chat: WaldiezChat,
390
- sender: WaldiezAgent,
391
- recipient: WaldiezAgent,
392
- agent_names: Dict[str, str],
393
- chat_names: Dict[str, str],
394
- chat_args: Dict[str, Any],
395
- tabs: int,
396
- ) -> Tuple[str, str]:
397
- tab = " " * tabs
398
- sender_name = agent_names[sender.id]
399
- recipient_name = agent_names[recipient.id]
400
- chat_string = f"{sender_name}.initiate_chat(\n"
401
- chat_string += f"{tab} {recipient_name},"
402
- for key, value in chat_args.items():
403
- if isinstance(value, str):
404
- chat_string += f'\n{tab} {key}="{value}",'
405
- elif isinstance(value, dict):
406
- chat_string += (
407
- f"\n{tab} {key}={get_object_string(value, tabs + 1)},"
408
- )
409
- else:
410
- chat_string += f"\n{tab} {key}={value},"
411
- message_arg, additional_methods_string = _get_chat_message(
412
- tab=tab,
413
- chat=chat,
414
- chat_names=chat_names,
415
- sender=sender,
416
- sender_name=sender_name,
417
- )
418
- chat_string += message_arg
419
- chat_string += f"\n{tab})"
420
- return chat_string, additional_methods_string
@@ -1,32 +0,0 @@
1
- """Get the main function (if exporting to python)."""
2
-
3
- from ..utils import get_logging_stop_string, get_sqlite_to_csv_call_string
4
-
5
-
6
- def get_def_main(waldiez_chats: str) -> str:
7
- """Get the main function.
8
-
9
- When exporting to python, waldiez_chats string will be the
10
- content of the main function. It contains either a
11
- `{sender.initiate_chat(recipient, ...)}` (if there is only one chat)
12
- or `initiate_chats([..])`, with the list of chats to initiate.
13
-
14
- Parameters
15
- ----------
16
- waldiez_chats : str
17
- The content of the main function.
18
-
19
- Returns
20
- -------
21
- str
22
- The main function.
23
- """
24
- content = """def main():
25
- # type: () -> Union[ChatResult, List[ChatResult]]
26
- \"\"\"Start chatting.\"\"\"
27
- """
28
- content += f" results = {waldiez_chats}" + "\n"
29
- content += get_logging_stop_string(1) + "\n"
30
- content += get_sqlite_to_csv_call_string(1) + "\n"
31
- content += " return results\n"
32
- return content