Skip to content

Commit

Permalink
Resolve #2 -- Add a typing indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Dec 2, 2023
1 parent 694c8cc commit 5b00cfc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sam/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ def process_run(event: {str, Any}, say: Say):
thread_id=thread_id,
assistant_id=config.OPENAI_ASSISTANT_ID,
)
msg = say(f":speech_balloon:", mrkdwn=True)
logger.info(f"User={user_id} started Run={run.id} for Thread={thread_id}")
cycle = 0
while run.status in ["queued", "in_progress"]:
run = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run.id)
time.sleep(2**cycle)
if run.status != "completed":
logger.error(run.last_error)
say(f"🤖 {run.last_error.message}")
say(
f"🤖 {run.last_error.message}",
)
logger.error(f"Run {run.id} {run.status} for Thread {thread_id}")
logger.error(run.last_error.message)
return
Expand All @@ -63,7 +66,12 @@ def process_run(event: {str, Any}, say: Say):
messages = client.beta.threads.messages.list(thread_id=thread_id)
for message in messages:
if message.role == "assistant":
say(message.content[0].text.value, mrkdwn=True)
say.client.chat_update(
channel=say.channel,
ts=msg["ts"],
text=message.content[0].text.value,
mrkdwn=True,
)
logger.info(f"Sam responded to the User={user_id} in Channel={channel_id}")
break

Expand Down

0 comments on commit 5b00cfc

Please sign in to comment.