Skip to content

Commit

Permalink
v2.0.51
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Nov 15, 2023
1 parent dadbb0e commit 3f54a8e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
41 changes: 25 additions & 16 deletions phi/assistant/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from phi.assistant.assistant import Assistant
from phi.assistant.exceptions import ThreadIdNotSet
from phi.utils.log import logger
from phi.utils.timer import Timer

try:
from openai import OpenAI
Expand Down Expand Up @@ -239,21 +238,31 @@ def print_messages(self) -> None:
table.add_section()
console.print(table)

def print_response(self, message: str, assistant: Assistant) -> None:
# Start the response timer
response_timer = Timer()
response_timer.start()

# Add the message to the thread
self.add(messages=[Message(role="user", content=message)])

# Run the assistant
self.run(assistant=assistant)

# Stop the response timer
response_timer.stop()

self.print_messages()
def print_response(self, message: str, assistant: Assistant, current_message_only: bool = False) -> None:
from rich.progress import Progress, SpinnerColumn, TextColumn

with Progress(SpinnerColumn(), TextColumn("{task.description}"), transient=True) as progress:
progress.add_task("Working")
self.run(
message=message,
assistant=assistant,
wait=True,
)

if current_message_only:
response_messages = []
for m in self.messages:
if m.role == "assistant":
response_messages.append(m)
if m.role == "user" and m.get_content_text() == message:
break

total_messages = len(response_messages)
for idx, response_message in enumerate(response_messages[::-1], start=1):
response_message.pprint(title=f"[bold] :robot: Assistant ({idx}/{total_messages}) [/bold]")
else:
for m in self.messages[::-1]:
m.pprint()

def __str__(self) -> str:
import json
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phidata"
version = "2.0.50"
version = "2.0.51"
description = "AI Toolkit for Engineers"
requires-python = ">=3.7"
readme = "README.md"
Expand Down

0 comments on commit 3f54a8e

Please sign in to comment.