waldiez 0.1.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.
- waldiez/__init__.py +15 -0
- waldiez/__main__.py +6 -0
- waldiez/_version.py +3 -0
- waldiez/cli.py +162 -0
- waldiez/exporter.py +293 -0
- waldiez/exporting/__init__.py +14 -0
- waldiez/exporting/agents/__init__.py +5 -0
- waldiez/exporting/agents/agent.py +229 -0
- waldiez/exporting/agents/agent_skills.py +67 -0
- waldiez/exporting/agents/code_execution.py +67 -0
- waldiez/exporting/agents/group_manager.py +209 -0
- waldiez/exporting/agents/llm_config.py +53 -0
- waldiez/exporting/agents/rag_user/__init__.py +5 -0
- waldiez/exporting/agents/rag_user/chroma_utils.py +134 -0
- waldiez/exporting/agents/rag_user/mongo_utils.py +83 -0
- waldiez/exporting/agents/rag_user/pgvector_utils.py +93 -0
- waldiez/exporting/agents/rag_user/qdrant_utils.py +112 -0
- waldiez/exporting/agents/rag_user/rag_user.py +165 -0
- waldiez/exporting/agents/rag_user/vector_db.py +119 -0
- waldiez/exporting/agents/teachability.py +37 -0
- waldiez/exporting/agents/termination_message.py +45 -0
- waldiez/exporting/chats/__init__.py +14 -0
- waldiez/exporting/chats/chats.py +46 -0
- waldiez/exporting/chats/helpers.py +395 -0
- waldiez/exporting/chats/nested.py +264 -0
- waldiez/exporting/flow/__init__.py +5 -0
- waldiez/exporting/flow/def_main.py +37 -0
- waldiez/exporting/flow/flow.py +185 -0
- waldiez/exporting/models/__init__.py +193 -0
- waldiez/exporting/skills/__init__.py +128 -0
- waldiez/exporting/utils/__init__.py +34 -0
- waldiez/exporting/utils/comments.py +136 -0
- waldiez/exporting/utils/importing.py +267 -0
- waldiez/exporting/utils/logging_utils.py +203 -0
- waldiez/exporting/utils/method_utils.py +35 -0
- waldiez/exporting/utils/naming.py +127 -0
- waldiez/exporting/utils/object_string.py +81 -0
- waldiez/io_stream.py +181 -0
- waldiez/models/__init__.py +107 -0
- waldiez/models/agents/__init__.py +65 -0
- waldiez/models/agents/agent/__init__.py +21 -0
- waldiez/models/agents/agent/agent.py +190 -0
- waldiez/models/agents/agent/agent_data.py +162 -0
- waldiez/models/agents/agent/code_execution.py +71 -0
- waldiez/models/agents/agent/linked_skill.py +30 -0
- waldiez/models/agents/agent/nested_chat.py +73 -0
- waldiez/models/agents/agent/teachability.py +68 -0
- waldiez/models/agents/agent/termination_message.py +167 -0
- waldiez/models/agents/agents.py +129 -0
- waldiez/models/agents/assistant/__init__.py +6 -0
- waldiez/models/agents/assistant/assistant.py +41 -0
- waldiez/models/agents/assistant/assistant_data.py +29 -0
- waldiez/models/agents/group_manager/__init__.py +19 -0
- waldiez/models/agents/group_manager/group_manager.py +87 -0
- waldiez/models/agents/group_manager/group_manager_data.py +91 -0
- waldiez/models/agents/group_manager/speakers.py +211 -0
- waldiez/models/agents/rag_user/__init__.py +26 -0
- waldiez/models/agents/rag_user/rag_user.py +58 -0
- waldiez/models/agents/rag_user/rag_user_data.py +32 -0
- waldiez/models/agents/rag_user/retrieve_config.py +592 -0
- waldiez/models/agents/rag_user/vector_db_config.py +162 -0
- waldiez/models/agents/user_proxy/__init__.py +6 -0
- waldiez/models/agents/user_proxy/user_proxy.py +41 -0
- waldiez/models/agents/user_proxy/user_proxy_data.py +30 -0
- waldiez/models/chat/__init__.py +22 -0
- waldiez/models/chat/chat.py +129 -0
- waldiez/models/chat/chat_data.py +326 -0
- waldiez/models/chat/chat_message.py +304 -0
- waldiez/models/chat/chat_nested.py +160 -0
- waldiez/models/chat/chat_summary.py +110 -0
- waldiez/models/common/__init__.py +38 -0
- waldiez/models/common/base.py +63 -0
- waldiez/models/common/method_utils.py +165 -0
- waldiez/models/flow/__init__.py +9 -0
- waldiez/models/flow/flow.py +302 -0
- waldiez/models/flow/flow_data.py +87 -0
- waldiez/models/model/__init__.py +11 -0
- waldiez/models/model/model.py +169 -0
- waldiez/models/model/model_data.py +86 -0
- waldiez/models/skill/__init__.py +9 -0
- waldiez/models/skill/skill.py +129 -0
- waldiez/models/skill/skill_data.py +37 -0
- waldiez/models/waldiez.py +301 -0
- waldiez/py.typed +0 -0
- waldiez/runner.py +304 -0
- waldiez/stream/__init__.py +7 -0
- waldiez/stream/consumer.py +139 -0
- waldiez/stream/provider.py +339 -0
- waldiez/stream/server.py +412 -0
- waldiez-0.1.0.dist-info/METADATA +181 -0
- waldiez-0.1.0.dist-info/RECORD +94 -0
- waldiez-0.1.0.dist-info/WHEEL +4 -0
- waldiez-0.1.0.dist-info/entry_points.txt +2 -0
- waldiez-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"""TCP socket input provider.
|
|
2
|
+
|
|
3
|
+
It connects to a TCP server,
|
|
4
|
+
listens for `PROVIDE:` messages to receive prompts,
|
|
5
|
+
and sends `USE:` messages to pass the response.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
import socket
|
|
10
|
+
import threading
|
|
11
|
+
import time
|
|
12
|
+
from types import TracebackType
|
|
13
|
+
from typing import Optional, Type
|
|
14
|
+
|
|
15
|
+
END_OF_MESSAGE = b"\r\n"
|
|
16
|
+
LOGGER = logging.getLogger("tcp::provider")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class InputProviderThread(threading.Thread):
|
|
20
|
+
"""Input provider thread."""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
host: str,
|
|
25
|
+
port: int,
|
|
26
|
+
response: Optional[str],
|
|
27
|
+
timeout: Optional[float] = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
"""Create a new input provider thread.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
host : str
|
|
34
|
+
The host to connect to.
|
|
35
|
+
port : int
|
|
36
|
+
The port to connect to.
|
|
37
|
+
response : str, optional
|
|
38
|
+
The response to send.
|
|
39
|
+
timeout : float, optional
|
|
40
|
+
The timeout for the provider, by default None (no timeout).
|
|
41
|
+
"""
|
|
42
|
+
super().__init__(
|
|
43
|
+
name="InputProviderThread",
|
|
44
|
+
daemon=True,
|
|
45
|
+
target=self.run,
|
|
46
|
+
)
|
|
47
|
+
self.host = host
|
|
48
|
+
self.port = port
|
|
49
|
+
self.timeout = timeout
|
|
50
|
+
self._response = response
|
|
51
|
+
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
|
|
52
|
+
self.running = False
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def response(self) -> Optional[str]:
|
|
56
|
+
"""Get the response."""
|
|
57
|
+
return self._response
|
|
58
|
+
|
|
59
|
+
@response.setter
|
|
60
|
+
def response(self, response: str) -> None:
|
|
61
|
+
"""Set the response.
|
|
62
|
+
|
|
63
|
+
Parameters
|
|
64
|
+
----------
|
|
65
|
+
response : str
|
|
66
|
+
The response to set.
|
|
67
|
+
"""
|
|
68
|
+
self._response = response
|
|
69
|
+
|
|
70
|
+
def _run_no_timeout(self) -> None:
|
|
71
|
+
"""Start the provider."""
|
|
72
|
+
self.socket.connect((self.host, self.port))
|
|
73
|
+
self.socket.sendall("PROVIDER\r\n".encode("utf-8"))
|
|
74
|
+
self.running = True
|
|
75
|
+
while self.running:
|
|
76
|
+
data = b""
|
|
77
|
+
while not data.endswith(END_OF_MESSAGE):
|
|
78
|
+
try:
|
|
79
|
+
data += self.socket.recv(1024)
|
|
80
|
+
except BaseException: # pylint: disable=broad-except
|
|
81
|
+
break
|
|
82
|
+
if not data:
|
|
83
|
+
break
|
|
84
|
+
if data.startswith(b"PROVIDE:"):
|
|
85
|
+
prompt = data[len(b"PROVIDE:") : -len(END_OF_MESSAGE)]
|
|
86
|
+
LOGGER.debug("Got a prompt: %s", prompt)
|
|
87
|
+
if self.response:
|
|
88
|
+
message = f"USE:{self.response}" + "\r\n"
|
|
89
|
+
self.socket.sendall(message.encode("utf-8"))
|
|
90
|
+
self.socket.close()
|
|
91
|
+
self.running = False
|
|
92
|
+
|
|
93
|
+
def _run_with_timeout(self, timeout: float) -> None:
|
|
94
|
+
"""Start the provider with a timeout."""
|
|
95
|
+
self.socket.connect((self.host, self.port))
|
|
96
|
+
self.socket.sendall("PROVIDER\r\n".encode("utf-8"))
|
|
97
|
+
self.running = True
|
|
98
|
+
start_time = time.monotonic()
|
|
99
|
+
while self.running:
|
|
100
|
+
data = b""
|
|
101
|
+
while time.monotonic() - start_time < timeout:
|
|
102
|
+
try:
|
|
103
|
+
data += self.socket.recv(1024)
|
|
104
|
+
except BaseException: # pylint: disable=broad-except
|
|
105
|
+
break
|
|
106
|
+
if data.endswith(END_OF_MESSAGE):
|
|
107
|
+
break
|
|
108
|
+
if not data:
|
|
109
|
+
break
|
|
110
|
+
if data.startswith(b"PROVIDE:"):
|
|
111
|
+
prompt = data[len(b"PROVIDE:") : -len(END_OF_MESSAGE)]
|
|
112
|
+
LOGGER.debug("Got a prompt: %s", prompt)
|
|
113
|
+
if self.response:
|
|
114
|
+
message = f"USE:{self.response}" + "\r\n"
|
|
115
|
+
self.socket.sendall(message.encode("utf-8"))
|
|
116
|
+
self.socket.close()
|
|
117
|
+
self.running = False
|
|
118
|
+
|
|
119
|
+
def run(self) -> None:
|
|
120
|
+
"""Run the provider."""
|
|
121
|
+
if self.timeout is None or self.timeout < 1:
|
|
122
|
+
self._run_no_timeout()
|
|
123
|
+
else:
|
|
124
|
+
self._run_with_timeout(self.timeout)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class InputProviderWrapper:
|
|
128
|
+
"""Input provider wrapper."""
|
|
129
|
+
|
|
130
|
+
thread: Optional[InputProviderThread] = None
|
|
131
|
+
|
|
132
|
+
def __init__(
|
|
133
|
+
self,
|
|
134
|
+
host: str,
|
|
135
|
+
port: int,
|
|
136
|
+
response: Optional[str] = None,
|
|
137
|
+
timeout: Optional[float] = None,
|
|
138
|
+
) -> None:
|
|
139
|
+
"""Create a new input provider wrapper.
|
|
140
|
+
|
|
141
|
+
Parameters
|
|
142
|
+
----------
|
|
143
|
+
host : str
|
|
144
|
+
The host to connect to.
|
|
145
|
+
port : int
|
|
146
|
+
The port to connect to.
|
|
147
|
+
response : str, optional
|
|
148
|
+
The response to send.
|
|
149
|
+
timeout : float, optional
|
|
150
|
+
The timeout for the provider, by default None (no timeout).
|
|
151
|
+
"""
|
|
152
|
+
self._host = host
|
|
153
|
+
self._port = port
|
|
154
|
+
self._timeout = timeout
|
|
155
|
+
self._response = response
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def response(self) -> Optional[str]:
|
|
159
|
+
"""Get the response."""
|
|
160
|
+
if self.thread:
|
|
161
|
+
return self.thread.response
|
|
162
|
+
return self._response
|
|
163
|
+
|
|
164
|
+
def start(self) -> None:
|
|
165
|
+
"""Start the provider."""
|
|
166
|
+
self.thread = InputProviderThread(
|
|
167
|
+
self._host, self._port, self._response, self._timeout
|
|
168
|
+
)
|
|
169
|
+
self.thread.daemon = True
|
|
170
|
+
self.thread.start()
|
|
171
|
+
|
|
172
|
+
def set_response(self, response: str) -> None:
|
|
173
|
+
"""Set the response.
|
|
174
|
+
|
|
175
|
+
Parameters
|
|
176
|
+
----------
|
|
177
|
+
response : str
|
|
178
|
+
The response to set.
|
|
179
|
+
"""
|
|
180
|
+
self._response = response
|
|
181
|
+
if self.thread:
|
|
182
|
+
self.thread.response = response
|
|
183
|
+
|
|
184
|
+
def stop(self) -> None:
|
|
185
|
+
"""Stop the provider."""
|
|
186
|
+
if self.thread:
|
|
187
|
+
self.thread.running = False
|
|
188
|
+
self.thread.join(timeout=1)
|
|
189
|
+
del self.thread
|
|
190
|
+
self.thread = None
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class TCPProvider:
|
|
194
|
+
"""Input provider."""
|
|
195
|
+
|
|
196
|
+
_wrapper: Optional[InputProviderWrapper] = None
|
|
197
|
+
|
|
198
|
+
def __init__(
|
|
199
|
+
self,
|
|
200
|
+
host: str,
|
|
201
|
+
port: int,
|
|
202
|
+
response: Optional[str] = None,
|
|
203
|
+
timeout: Optional[float] = 30,
|
|
204
|
+
) -> None:
|
|
205
|
+
"""Create a new input provider.
|
|
206
|
+
|
|
207
|
+
Parameters
|
|
208
|
+
----------
|
|
209
|
+
host : str
|
|
210
|
+
The host to connect to.
|
|
211
|
+
port : int
|
|
212
|
+
The port to connect to.
|
|
213
|
+
response : str, optional
|
|
214
|
+
The response to send.
|
|
215
|
+
timeout : float, optional
|
|
216
|
+
The timeout for the provider, by default 30.
|
|
217
|
+
"""
|
|
218
|
+
self._host = host
|
|
219
|
+
self._port = port
|
|
220
|
+
self._response = response
|
|
221
|
+
self._timeout = timeout
|
|
222
|
+
self._start_called = False
|
|
223
|
+
self._init_wrapper()
|
|
224
|
+
|
|
225
|
+
def __enter__(self) -> "TCPProvider":
|
|
226
|
+
"""Enter the context."""
|
|
227
|
+
self.start()
|
|
228
|
+
return self
|
|
229
|
+
|
|
230
|
+
def __exit__(
|
|
231
|
+
self,
|
|
232
|
+
exc_type: Optional[Type[BaseException]],
|
|
233
|
+
exc_value: Optional[BaseException],
|
|
234
|
+
traceback: Optional[TracebackType],
|
|
235
|
+
) -> None:
|
|
236
|
+
"""Exit the context."""
|
|
237
|
+
self.stop()
|
|
238
|
+
|
|
239
|
+
@property
|
|
240
|
+
def thread(self) -> Optional[InputProviderThread]:
|
|
241
|
+
"""Get the thread."""
|
|
242
|
+
if not self._wrapper:
|
|
243
|
+
return None
|
|
244
|
+
return self._wrapper.thread
|
|
245
|
+
|
|
246
|
+
@property
|
|
247
|
+
def response(self) -> Optional[str]:
|
|
248
|
+
"""Get the response."""
|
|
249
|
+
if self._wrapper:
|
|
250
|
+
return self._wrapper.response
|
|
251
|
+
return self._response
|
|
252
|
+
|
|
253
|
+
def _init_wrapper(self) -> None:
|
|
254
|
+
"""Initialize the wrapper."""
|
|
255
|
+
self._wrapper = InputProviderWrapper(
|
|
256
|
+
host=self._host,
|
|
257
|
+
port=self._port,
|
|
258
|
+
response=self._response,
|
|
259
|
+
timeout=self._timeout,
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
def is_running(self) -> bool:
|
|
263
|
+
"""Check if the provider is running.
|
|
264
|
+
|
|
265
|
+
Returns
|
|
266
|
+
-------
|
|
267
|
+
bool
|
|
268
|
+
True if the provider is running, False otherwise.
|
|
269
|
+
"""
|
|
270
|
+
if not self._wrapper:
|
|
271
|
+
return False
|
|
272
|
+
if not self.thread:
|
|
273
|
+
return False
|
|
274
|
+
return self.thread.running is True
|
|
275
|
+
|
|
276
|
+
def wait(self, timeout: float) -> None:
|
|
277
|
+
"""Wait until the provider is running.
|
|
278
|
+
|
|
279
|
+
Parameters
|
|
280
|
+
----------
|
|
281
|
+
timeout : float
|
|
282
|
+
The timeout to wait.
|
|
283
|
+
"""
|
|
284
|
+
start_time = time.time()
|
|
285
|
+
while not self.is_running():
|
|
286
|
+
if time.time() - start_time > timeout:
|
|
287
|
+
break
|
|
288
|
+
time.sleep(1)
|
|
289
|
+
|
|
290
|
+
def start(self) -> None:
|
|
291
|
+
"""Start the provider.
|
|
292
|
+
|
|
293
|
+
Raises
|
|
294
|
+
------
|
|
295
|
+
RuntimeError
|
|
296
|
+
If the wrapper is not initialized.
|
|
297
|
+
"""
|
|
298
|
+
# avoid starting the provider multiple times
|
|
299
|
+
# (if the wrapped thread has not yet started)
|
|
300
|
+
if self._start_called is True:
|
|
301
|
+
return
|
|
302
|
+
self._start_called = True
|
|
303
|
+
if self.is_running():
|
|
304
|
+
return
|
|
305
|
+
if not self._wrapper:
|
|
306
|
+
raise RuntimeError("Wrapper not initialized")
|
|
307
|
+
self._wrapper.start()
|
|
308
|
+
|
|
309
|
+
def set_response(self, response: str) -> None:
|
|
310
|
+
"""Set the response.
|
|
311
|
+
|
|
312
|
+
Parameters
|
|
313
|
+
----------
|
|
314
|
+
response : str
|
|
315
|
+
The response to set.
|
|
316
|
+
|
|
317
|
+
Raises
|
|
318
|
+
------
|
|
319
|
+
RuntimeError
|
|
320
|
+
If the wrapper is not initialized.
|
|
321
|
+
"""
|
|
322
|
+
if not self._wrapper:
|
|
323
|
+
raise RuntimeError("Wrapper not initialized")
|
|
324
|
+
self._wrapper.set_response(response or "\n")
|
|
325
|
+
|
|
326
|
+
def stop(self) -> None:
|
|
327
|
+
"""Stop the provider."""
|
|
328
|
+
self._start_called = False
|
|
329
|
+
if not self.is_running():
|
|
330
|
+
return
|
|
331
|
+
if self._wrapper:
|
|
332
|
+
self._wrapper.stop()
|
|
333
|
+
del self._wrapper
|
|
334
|
+
self._init_wrapper()
|
|
335
|
+
|
|
336
|
+
def restart(self) -> None:
|
|
337
|
+
"""Restart the provider."""
|
|
338
|
+
self.stop()
|
|
339
|
+
self.start()
|