Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created February 28, 2025 00:23
Show Gist options
  • Select an option

  • Save KyMidd/e4b21130598e7e29aa22f379a588d0ba to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/e4b21130598e7e29aa22f379a588d0ba to your computer and use it in GitHub Desktop.
# Iterate over streamed chunks
for chunk in streaming_response["stream"]:
if "contentBlockDelta" in chunk:
text = chunk["contentBlockDelta"]["delta"]["text"]
response += text
buffer += text
token_counter += 1
if token_counter >= 10:
client.chat_update(
text=response,
channel=channel_id,
ts=message_ts
)
# Every time we update to slack, we zero out the token counter and buffer
token_counter = 0
buffer = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment