Skip to content

Commit

Permalink
Merge pull request #191 from PrefectHQ/avoid-bot_response.last
Browse files Browse the repository at this point in the history
  • Loading branch information
jlowin authored Apr 9, 2023
2 parents 76512f1 + 73ab1b3 commit 5cabe79
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/marvin/cli/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ async def name_thread(history: str, personality: str, current_name: str = None)
"""
This function generates a short, relevant name for the provided thread
`history`. The name should be fewer than five words and must reflect the
user's intent or objective in a clear, fun way. It can include emojis and
use sentence capitalization, but should not end with a period. The name itself
should be entirely based on the provided `history`, but the tone should reflect the
provided `personality`. If the thread has a `current_name` already, it is
provided and you can choose to keep it unchanged.
user's intent or objective in a clear, fun way. Return only the name, no
other commentary. It can include emojis and use sentence capitalization, but
should not end with a period. The name itself should be entirely based on
the provided `history`, but the tone should reflect the provided
`personality`. If the thread has a `current_name` already, it is provided
and you can choose to keep it unchanged.
"""


Expand Down Expand Up @@ -664,14 +665,17 @@ async def get_bot_response(self, event: Input.Submitted) -> str:
self.action_rename_thread()

# update the bot response with the actual message id
bot_responses.last().message.id = response.id
bot_response.message.id = response.id

# update the last user response with the actual message id
messages = await marvin.api.threads.get_messages(
thread_id=self.app.thread_id, limit=2
thread_id=self.app.thread_id, limit=5
)
if len(messages) == 2:
self.query("UserResponse").last().message.id = messages[0].id
last_user_message = next(
(m for m in reversed(messages) if m.role == "user"), None
)
if last_user_message:
self.query("UserResponse").last().message.id = last_user_message.id
finally:
self.app.bot_responding = False

Expand Down

0 comments on commit 5cabe79

Please sign in to comment.