praisonaiagents 0.0.17__py3-none-any.whl → 0.0.19__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- praisonaiagents/__init__.py +4 -0
- praisonaiagents/main.py +198 -6
- {praisonaiagents-0.0.17.dist-info → praisonaiagents-0.0.19.dist-info}/METADATA +1 -1
- {praisonaiagents-0.0.17.dist-info → praisonaiagents-0.0.19.dist-info}/RECORD +6 -6
- {praisonaiagents-0.0.17.dist-info → praisonaiagents-0.0.19.dist-info}/WHEEL +0 -0
- {praisonaiagents-0.0.17.dist-info → praisonaiagents-0.0.19.dist-info}/top_level.txt +0 -0
praisonaiagents/__init__.py
CHANGED
@@ -16,6 +16,8 @@ from .main import (
|
|
16
16
|
display_generating,
|
17
17
|
clean_triple_backticks,
|
18
18
|
error_logs,
|
19
|
+
register_display_callback,
|
20
|
+
display_callbacks,
|
19
21
|
)
|
20
22
|
|
21
23
|
__all__ = [
|
@@ -32,4 +34,6 @@ __all__ = [
|
|
32
34
|
'display_generating',
|
33
35
|
'clean_triple_backticks',
|
34
36
|
'error_logs',
|
37
|
+
'register_display_callback',
|
38
|
+
'display_callbacks',
|
35
39
|
]
|
praisonaiagents/main.py
CHANGED
@@ -12,6 +12,7 @@ from rich.text import Text
|
|
12
12
|
from rich.markdown import Markdown
|
13
13
|
from rich.logging import RichHandler
|
14
14
|
from rich.live import Live
|
15
|
+
import asyncio
|
15
16
|
|
16
17
|
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
|
17
18
|
|
@@ -25,6 +26,13 @@ logging.basicConfig(
|
|
25
26
|
# Global list to store error logs
|
26
27
|
error_logs = []
|
27
28
|
|
29
|
+
# Global callback registry
|
30
|
+
display_callbacks = {}
|
31
|
+
|
32
|
+
def register_display_callback(display_type: str, callback_fn):
|
33
|
+
"""Register a callback function for a specific display type."""
|
34
|
+
display_callbacks[display_type] = callback_fn
|
35
|
+
|
28
36
|
def _clean_display_content(content: str, max_length: int = 20000) -> str:
|
29
37
|
"""Helper function to clean and truncate content for display."""
|
30
38
|
if not content or not str(content).strip():
|
@@ -49,18 +57,28 @@ def display_interaction(message, response, markdown=True, generation_time=None,
|
|
49
57
|
"""Display the interaction between user and assistant."""
|
50
58
|
if console is None:
|
51
59
|
console = Console()
|
52
|
-
|
53
|
-
console.print(Text(f"Response generated in {generation_time:.1f}s", style="dim"))
|
54
|
-
|
60
|
+
|
55
61
|
# Handle multimodal content (list)
|
56
62
|
if isinstance(message, list):
|
57
|
-
# Extract just the text content from the multimodal message
|
58
63
|
text_content = next((item["text"] for item in message if item["type"] == "text"), "")
|
59
64
|
message = text_content
|
60
65
|
|
61
66
|
message = _clean_display_content(str(message))
|
62
67
|
response = _clean_display_content(str(response))
|
63
68
|
|
69
|
+
# Execute callback if registered
|
70
|
+
if 'interaction' in display_callbacks:
|
71
|
+
display_callbacks['interaction'](
|
72
|
+
message=message,
|
73
|
+
response=response,
|
74
|
+
markdown=markdown,
|
75
|
+
generation_time=generation_time
|
76
|
+
)
|
77
|
+
|
78
|
+
# Existing display logic...
|
79
|
+
if generation_time:
|
80
|
+
console.print(Text(f"Response generated in {generation_time:.1f}s", style="dim"))
|
81
|
+
|
64
82
|
if markdown:
|
65
83
|
console.print(Panel.fit(Markdown(message), title="Message", border_style="cyan"))
|
66
84
|
console.print(Panel.fit(Markdown(response), title="Response", border_style="cyan"))
|
@@ -74,6 +92,11 @@ def display_self_reflection(message: str, console=None):
|
|
74
92
|
if console is None:
|
75
93
|
console = Console()
|
76
94
|
message = _clean_display_content(str(message))
|
95
|
+
|
96
|
+
# Execute callback if registered
|
97
|
+
if 'self_reflection' in display_callbacks:
|
98
|
+
display_callbacks['self_reflection'](message=message)
|
99
|
+
|
77
100
|
console.print(Panel.fit(Text(message, style="bold yellow"), title="Self Reflection", border_style="magenta"))
|
78
101
|
|
79
102
|
def display_instruction(message: str, console=None):
|
@@ -82,6 +105,11 @@ def display_instruction(message: str, console=None):
|
|
82
105
|
if console is None:
|
83
106
|
console = Console()
|
84
107
|
message = _clean_display_content(str(message))
|
108
|
+
|
109
|
+
# Execute callback if registered
|
110
|
+
if 'instruction' in display_callbacks:
|
111
|
+
display_callbacks['instruction'](message=message)
|
112
|
+
|
85
113
|
console.print(Panel.fit(Text(message, style="bold blue"), title="Instruction", border_style="cyan"))
|
86
114
|
|
87
115
|
def display_tool_call(message: str, console=None):
|
@@ -90,6 +118,11 @@ def display_tool_call(message: str, console=None):
|
|
90
118
|
if console is None:
|
91
119
|
console = Console()
|
92
120
|
message = _clean_display_content(str(message))
|
121
|
+
|
122
|
+
# Execute callback if registered
|
123
|
+
if 'tool_call' in display_callbacks:
|
124
|
+
display_callbacks['tool_call'](message=message)
|
125
|
+
|
93
126
|
console.print(Panel.fit(Text(message, style="bold cyan"), title="Tool Call", border_style="green"))
|
94
127
|
|
95
128
|
def display_error(message: str, console=None):
|
@@ -98,19 +131,178 @@ def display_error(message: str, console=None):
|
|
98
131
|
if console is None:
|
99
132
|
console = Console()
|
100
133
|
message = _clean_display_content(str(message))
|
134
|
+
|
135
|
+
# Execute callback if registered
|
136
|
+
if 'error' in display_callbacks:
|
137
|
+
display_callbacks['error'](message=message)
|
138
|
+
|
101
139
|
console.print(Panel.fit(Text(message, style="bold red"), title="Error", border_style="red"))
|
102
|
-
# Store errors
|
103
140
|
error_logs.append(message)
|
104
141
|
|
105
142
|
def display_generating(content: str = "", start_time: Optional[float] = None):
|
106
143
|
if not content or not str(content).strip():
|
107
|
-
return Panel("", title="", border_style="green")
|
144
|
+
return Panel("", title="", border_style="green")
|
145
|
+
|
108
146
|
elapsed_str = ""
|
109
147
|
if start_time is not None:
|
110
148
|
elapsed = time.time() - start_time
|
111
149
|
elapsed_str = f" {elapsed:.1f}s"
|
112
150
|
|
113
151
|
content = _clean_display_content(str(content))
|
152
|
+
|
153
|
+
# Execute callback if registered
|
154
|
+
if 'generating' in display_callbacks:
|
155
|
+
display_callbacks['generating'](
|
156
|
+
content=content,
|
157
|
+
elapsed_time=elapsed_str.strip() if elapsed_str else None
|
158
|
+
)
|
159
|
+
|
160
|
+
return Panel(Markdown(content), title=f"Generating...{elapsed_str}", border_style="green")
|
161
|
+
|
162
|
+
# Async versions with 'a' prefix
|
163
|
+
async def adisplay_interaction(message, response, markdown=True, generation_time=None, console=None):
|
164
|
+
"""Async version of display_interaction."""
|
165
|
+
if console is None:
|
166
|
+
console = Console()
|
167
|
+
|
168
|
+
if isinstance(message, list):
|
169
|
+
text_content = next((item["text"] for item in message if item["type"] == "text"), "")
|
170
|
+
message = text_content
|
171
|
+
|
172
|
+
message = _clean_display_content(str(message))
|
173
|
+
response = _clean_display_content(str(response))
|
174
|
+
|
175
|
+
if 'interaction' in display_callbacks:
|
176
|
+
callback = display_callbacks['interaction']
|
177
|
+
if asyncio.iscoroutinefunction(callback):
|
178
|
+
await callback(
|
179
|
+
message=message,
|
180
|
+
response=response,
|
181
|
+
markdown=markdown,
|
182
|
+
generation_time=generation_time
|
183
|
+
)
|
184
|
+
else:
|
185
|
+
loop = asyncio.get_event_loop()
|
186
|
+
await loop.run_in_executor(
|
187
|
+
None,
|
188
|
+
callback,
|
189
|
+
message,
|
190
|
+
response,
|
191
|
+
markdown,
|
192
|
+
generation_time
|
193
|
+
)
|
194
|
+
|
195
|
+
if generation_time:
|
196
|
+
console.print(Text(f"Response generated in {generation_time:.1f}s", style="dim"))
|
197
|
+
|
198
|
+
if markdown:
|
199
|
+
console.print(Panel.fit(Markdown(message), title="Message", border_style="cyan"))
|
200
|
+
console.print(Panel.fit(Markdown(response), title="Response", border_style="cyan"))
|
201
|
+
else:
|
202
|
+
console.print(Panel.fit(Text(message, style="bold green"), title="Message", border_style="cyan"))
|
203
|
+
console.print(Panel.fit(Text(response, style="bold blue"), title="Response", border_style="cyan"))
|
204
|
+
|
205
|
+
async def adisplay_self_reflection(message: str, console=None):
|
206
|
+
"""Async version of display_self_reflection."""
|
207
|
+
if not message or not message.strip():
|
208
|
+
return
|
209
|
+
if console is None:
|
210
|
+
console = Console()
|
211
|
+
message = _clean_display_content(str(message))
|
212
|
+
|
213
|
+
if 'self_reflection' in display_callbacks:
|
214
|
+
callback = display_callbacks['self_reflection']
|
215
|
+
if asyncio.iscoroutinefunction(callback):
|
216
|
+
await callback(message=message)
|
217
|
+
else:
|
218
|
+
loop = asyncio.get_event_loop()
|
219
|
+
await loop.run_in_executor(None, callback, message)
|
220
|
+
|
221
|
+
console.print(Panel.fit(Text(message, style="bold yellow"), title="Self Reflection", border_style="magenta"))
|
222
|
+
|
223
|
+
async def adisplay_instruction(message: str, console=None):
|
224
|
+
"""Async version of display_instruction."""
|
225
|
+
if not message or not message.strip():
|
226
|
+
return
|
227
|
+
if console is None:
|
228
|
+
console = Console()
|
229
|
+
message = _clean_display_content(str(message))
|
230
|
+
|
231
|
+
if 'instruction' in display_callbacks:
|
232
|
+
callback = display_callbacks['instruction']
|
233
|
+
if asyncio.iscoroutinefunction(callback):
|
234
|
+
await callback(message=message)
|
235
|
+
else:
|
236
|
+
loop = asyncio.get_event_loop()
|
237
|
+
await loop.run_in_executor(None, callback, message)
|
238
|
+
|
239
|
+
console.print(Panel.fit(Text(message, style="bold blue"), title="Instruction", border_style="cyan"))
|
240
|
+
|
241
|
+
async def adisplay_tool_call(message: str, console=None):
|
242
|
+
"""Async version of display_tool_call."""
|
243
|
+
if not message or not message.strip():
|
244
|
+
return
|
245
|
+
if console is None:
|
246
|
+
console = Console()
|
247
|
+
message = _clean_display_content(str(message))
|
248
|
+
|
249
|
+
if 'tool_call' in display_callbacks:
|
250
|
+
callback = display_callbacks['tool_call']
|
251
|
+
if asyncio.iscoroutinefunction(callback):
|
252
|
+
await callback(message=message)
|
253
|
+
else:
|
254
|
+
loop = asyncio.get_event_loop()
|
255
|
+
await loop.run_in_executor(None, callback, message)
|
256
|
+
|
257
|
+
console.print(Panel.fit(Text(message, style="bold cyan"), title="Tool Call", border_style="green"))
|
258
|
+
|
259
|
+
async def adisplay_error(message: str, console=None):
|
260
|
+
"""Async version of display_error."""
|
261
|
+
if not message or not message.strip():
|
262
|
+
return
|
263
|
+
if console is None:
|
264
|
+
console = Console()
|
265
|
+
message = _clean_display_content(str(message))
|
266
|
+
|
267
|
+
if 'error' in display_callbacks:
|
268
|
+
callback = display_callbacks['error']
|
269
|
+
if asyncio.iscoroutinefunction(callback):
|
270
|
+
await callback(message=message)
|
271
|
+
else:
|
272
|
+
loop = asyncio.get_event_loop()
|
273
|
+
await loop.run_in_executor(None, callback, message)
|
274
|
+
|
275
|
+
console.print(Panel.fit(Text(message, style="bold red"), title="Error", border_style="red"))
|
276
|
+
error_logs.append(message)
|
277
|
+
|
278
|
+
async def adisplay_generating(content: str = "", start_time: Optional[float] = None):
|
279
|
+
"""Async version of display_generating."""
|
280
|
+
if not content or not str(content).strip():
|
281
|
+
return Panel("", title="", border_style="green")
|
282
|
+
|
283
|
+
elapsed_str = ""
|
284
|
+
if start_time is not None:
|
285
|
+
elapsed = time.time() - start_time
|
286
|
+
elapsed_str = f" {elapsed:.1f}s"
|
287
|
+
|
288
|
+
content = _clean_display_content(str(content))
|
289
|
+
|
290
|
+
if 'generating' in display_callbacks:
|
291
|
+
callback = display_callbacks['generating']
|
292
|
+
if asyncio.iscoroutinefunction(callback):
|
293
|
+
await callback(
|
294
|
+
content=content,
|
295
|
+
elapsed_time=elapsed_str.strip() if elapsed_str else None
|
296
|
+
)
|
297
|
+
else:
|
298
|
+
loop = asyncio.get_event_loop()
|
299
|
+
await loop.run_in_executor(
|
300
|
+
None,
|
301
|
+
callback,
|
302
|
+
content,
|
303
|
+
elapsed_str.strip() if elapsed_str else None
|
304
|
+
)
|
305
|
+
|
114
306
|
return Panel(Markdown(content), title=f"Generating...{elapsed_str}", border_style="green")
|
115
307
|
|
116
308
|
def clean_triple_backticks(text: str) -> str:
|
@@ -1,5 +1,5 @@
|
|
1
|
-
praisonaiagents/__init__.py,sha256=
|
2
|
-
praisonaiagents/main.py,sha256=
|
1
|
+
praisonaiagents/__init__.py,sha256=bXQwi56S1iZOXs_TyXs3doxVxAeRAyqKVyZEIoBOipM,853
|
2
|
+
praisonaiagents/main.py,sha256=XtrOfVDK4KEaclOTBxUXpc_q9F44Udue6u1W8wMvSrg,12529
|
3
3
|
praisonaiagents/agent/__init__.py,sha256=sKO8wGEXvtCrvV1e834r1Okv0XAqAxqZCqz6hKLiTvA,79
|
4
4
|
praisonaiagents/agent/agent.py,sha256=_UmUWGbZjd3tApPX2T6RPB5Pll3Gos97XBhhg_zmfn8,30662
|
5
5
|
praisonaiagents/agents/__init__.py,sha256=7RDeQNSqZg5uBjD4M_0p_F6YgfWuDuxPFydPU50kDYc,120
|
@@ -16,7 +16,7 @@ praisonaiagents/process/__init__.py,sha256=lkYbL7Hn5a0ldvJtkdH23vfIIZLIcanK-65C0
|
|
16
16
|
praisonaiagents/process/process.py,sha256=4qXdrCDQPH5MtvHvdJVURXKNgSl6ae3OYTiqAF_A2ZU,24295
|
17
17
|
praisonaiagents/task/__init__.py,sha256=VL5hXVmyGjINb34AalxpBMl-YW9m5EDcRkMTKkSSl7c,80
|
18
18
|
praisonaiagents/task/task.py,sha256=UiiWgLDOdX_w0opP8h8-u-leVZlq1CkpGUmf7L2qyJs,3110
|
19
|
-
praisonaiagents-0.0.
|
20
|
-
praisonaiagents-0.0.
|
21
|
-
praisonaiagents-0.0.
|
22
|
-
praisonaiagents-0.0.
|
19
|
+
praisonaiagents-0.0.19.dist-info/METADATA,sha256=engdE6dLJ0SxfZv28CX2MKTZuYc04I_CdIWBjOdijXA,233
|
20
|
+
praisonaiagents-0.0.19.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
21
|
+
praisonaiagents-0.0.19.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
|
22
|
+
praisonaiagents-0.0.19.dist-info/RECORD,,
|
File without changes
|
File without changes
|