Skip to content

Commit d834230

Browse files
committed
feat: add chat_stream to app_mention
1 parent 1ee90f6 commit d834230

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

listeners/events/app_mentioned.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,22 @@ def app_mentioned_callback(client: WebClient, event: dict, logger: Logger, say:
3434

3535
returned_message = call_llm([{"role": "user", "content": text}])
3636

37-
stream_response = client.chat_startStream(
38-
channel=channel_id, recipient_team_id=team_id, recipient_user_id=user_id, thread_ts=thread_ts
37+
streamer = client.chat_stream(
38+
channel=channel_id,
39+
recipient_team_id=team_id,
40+
recipient_user_id=user_id,
41+
thread_ts=thread_ts,
3942
)
4043

41-
stream_ts = stream_response["ts"]
42-
43-
# Loop over OpenAI response stream
44-
# https://platform.openai.com/docs/api-reference/responses/create
44+
# use of this for loop is specific to openai response method
4545
for event in returned_message:
4646
if event.type == "response.output_text.delta":
47-
client.chat_appendStream(channel=channel_id, ts=stream_ts, markdown_text=f"{event.delta}")
47+
streamer.append(markdown_text=f"{event.delta}")
4848
else:
4949
continue
5050

5151
feedback_block = create_feedback_block()
52-
client.chat_stopStream(channel=channel_id, ts=stream_ts, blocks=feedback_block)
53-
52+
streamer.stop(blocks=feedback_block)
5453
except Exception as e:
5554
logger.exception(f"Failed to handle a user message event: {e}")
5655
say(f":warning: Something went wrong! ({e})")

0 commit comments

Comments
 (0)