praisonaiagents 0.0.18__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/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
 
@@ -158,6 +159,152 @@ def display_generating(content: str = "", start_time: Optional[float] = None):
158
159
 
159
160
  return Panel(Markdown(content), title=f"Generating...{elapsed_str}", border_style="green")
160
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
+
306
+ return Panel(Markdown(content), title=f"Generating...{elapsed_str}", border_style="green")
307
+
161
308
  def clean_triple_backticks(text: str) -> str:
162
309
  """Remove triple backticks and surrounding json fences from a string."""
163
310
  cleaned = text.strip()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: praisonaiagents
3
- Version: 0.0.18
3
+ Version: 0.0.19
4
4
  Summary: Praison AI agents for completing complex tasks with Self Reflection Agents
5
5
  Author: Mervin Praison
6
6
  Requires-Dist: pydantic
@@ -1,5 +1,5 @@
1
1
  praisonaiagents/__init__.py,sha256=bXQwi56S1iZOXs_TyXs3doxVxAeRAyqKVyZEIoBOipM,853
2
- praisonaiagents/main.py,sha256=QP45NxcrVs4PboVWcVkvLcsqiU7EzgE1ukH13jcYKfo,6985
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.18.dist-info/METADATA,sha256=JtO_vQUfxUb2EM2x_PSt1HqTf3biR65fyz4tg0_PF0Q,233
20
- praisonaiagents-0.0.18.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
- praisonaiagents-0.0.18.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
22
- praisonaiagents-0.0.18.dist-info/RECORD,,
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,,