-
Notifications
You must be signed in to change notification settings - Fork 850
feat: support and flush chunks in the chat stream helper #1809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zimeg
wants to merge
6
commits into
zimeg-feat-ai-apps-chunks
Choose a base branch
from
zimeg-feat-ai-apps-chunks-streamer
base: zimeg-feat-ai-apps-chunks
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5de794b
feat: support and flush chunks in the chat stream helper
zimeg 61d6d53
test: dump chunks json before comparison for exact parsings
zimeg 85081e1
test: update async tests to expect chunks when flushing buffer
zimeg a6bb951
style: prefer using markdown text chunks in internal calls
zimeg 92c93e0
fix: support explicit json values as chunk objects
zimeg 7c32814
fix: mirror dictionary chunk option to async streamer
zimeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| from slack_sdk.models.blocks.basic_components import FeedbackButtonObject | ||
| from slack_sdk.models.blocks.block_elements import FeedbackButtonsElement, IconButtonElement | ||
| from slack_sdk.models.blocks.blocks import ContextActionsBlock | ||
| from slack_sdk.models.messages.chunk import MarkdownTextChunk, TaskUpdateChunk | ||
| from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server | ||
| from tests.slack_sdk.web.mock_web_api_handler import MockHandler | ||
|
|
||
|
|
@@ -105,7 +106,10 @@ def test_streams_a_short_message(self): | |
| stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) | ||
| self.assertEqual(stop_request.get("channel"), "C0123456789") | ||
| self.assertEqual(stop_request.get("ts"), "123.123") | ||
| self.assertEqual(stop_request.get("markdown_text"), "nice!") | ||
| self.assertEqual( | ||
| json.dumps(stop_request.get("chunks")), | ||
| '[{"text": "nice!", "type": "markdown_text"}]', | ||
| ) | ||
|
|
||
| def test_streams_a_long_message(self): | ||
| streamer = self.client.chat_stream( | ||
|
|
@@ -146,13 +150,19 @@ def test_streams_a_long_message(self): | |
| start_request = self.thread.server.chat_stream_requests.get("/chat.startStream", {}) | ||
| self.assertEqual(start_request.get("channel"), "C0123456789") | ||
| self.assertEqual(start_request.get("thread_ts"), "123.000") | ||
| self.assertEqual(start_request.get("markdown_text"), "**this messag") | ||
| self.assertEqual( | ||
| json.dumps(start_request.get("chunks")), | ||
| '[{"text": "**this messag", "type": "markdown_text"}]', | ||
| ) | ||
| self.assertEqual(start_request.get("recipient_team_id"), "T0123456789") | ||
| self.assertEqual(start_request.get("recipient_user_id"), "U0123456789") | ||
|
|
||
| append_request = self.thread.server.chat_stream_requests.get("/chat.appendStream", {}) | ||
| self.assertEqual(append_request.get("channel"), "C0123456789") | ||
| self.assertEqual(append_request.get("markdown_text"), "e is bold!") | ||
| self.assertEqual( | ||
| json.dumps(append_request.get("chunks")), | ||
| '[{"text": "e is bold!", "type": "markdown_text"}]', | ||
| ) | ||
| self.assertEqual(append_request.get("token"), "xoxb-chat_stream_test_token1") | ||
| self.assertEqual(append_request.get("ts"), "123.123") | ||
|
|
||
|
|
@@ -162,10 +172,74 @@ def test_streams_a_long_message(self): | |
| '[{"elements": [{"negative_button": {"text": {"emoji": true, "text": "bad", "type": "plain_text"}, "value": "-1"}, "positive_button": {"text": {"emoji": true, "text": "good", "type": "plain_text"}, "value": "+1"}, "type": "feedback_buttons"}, {"icon": "trash", "text": {"emoji": true, "text": "delete", "type": "plain_text"}, "type": "icon_button"}], "type": "context_actions"}]', | ||
| ) | ||
| self.assertEqual(stop_request.get("channel"), "C0123456789") | ||
| self.assertEqual(stop_request.get("markdown_text"), "**") | ||
| self.assertEqual( | ||
| json.dumps(stop_request.get("chunks")), | ||
| '[{"text": "**", "type": "markdown_text"}]', | ||
| ) | ||
| self.assertEqual(stop_request.get("token"), "xoxb-chat_stream_test_token2") | ||
| self.assertEqual(stop_request.get("ts"), "123.123") | ||
|
|
||
| def test_streams_a_chunk_message(self): | ||
| streamer = self.client.chat_stream( | ||
| channel="C0123456789", | ||
| recipient_team_id="T0123456789", | ||
| recipient_user_id="U0123456789", | ||
| thread_ts="123.000", | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i tested this with an empty call to |
||
| streamer.append(markdown_text="**this is ") | ||
| streamer.append(markdown_text="buffered**") | ||
| streamer.append( | ||
| chunks=[ | ||
| TaskUpdateChunk( | ||
| id="001", | ||
| title="Counting...", | ||
| status="pending", | ||
| ), | ||
| ], | ||
| ) | ||
| streamer.append( | ||
| chunks=[ | ||
| MarkdownTextChunk(text="**this is unbuffered**"), | ||
| ], | ||
| ) | ||
| streamer.append(markdown_text="\n") | ||
| streamer.stop( | ||
| chunks=[ | ||
| MarkdownTextChunk(text=":space_invader:"), | ||
| ], | ||
| ) | ||
|
|
||
| self.assertEqual(self.received_requests.get("/chat.startStream", 0), 1) | ||
| self.assertEqual(self.received_requests.get("/chat.appendStream", 0), 1) | ||
| self.assertEqual(self.received_requests.get("/chat.stopStream", 0), 1) | ||
|
|
||
| if hasattr(self.thread.server, "chat_stream_requests"): | ||
| start_request = self.thread.server.chat_stream_requests.get("/chat.startStream", {}) | ||
| self.assertEqual(start_request.get("channel"), "C0123456789") | ||
| self.assertEqual(start_request.get("thread_ts"), "123.000") | ||
| self.assertEqual( | ||
| json.dumps(start_request.get("chunks")), | ||
| '[{"text": "**this is buffered**", "type": "markdown_text"}, {"id": "001", "status": "pending", "title": "Counting...", "type": "task_update"}]', | ||
| ) | ||
| self.assertEqual(start_request.get("recipient_team_id"), "T0123456789") | ||
| self.assertEqual(start_request.get("recipient_user_id"), "U0123456789") | ||
|
|
||
| append_request = self.thread.server.chat_stream_requests.get("/chat.appendStream", {}) | ||
| self.assertEqual(append_request.get("channel"), "C0123456789") | ||
| self.assertEqual(append_request.get("ts"), "123.123") | ||
| self.assertEqual( | ||
| json.dumps(append_request.get("chunks")), | ||
| '[{"text": "**this is unbuffered**", "type": "markdown_text"}]', | ||
| ) | ||
|
|
||
| stop_request = self.thread.server.chat_stream_requests.get("/chat.stopStream", {}) | ||
| self.assertEqual(stop_request.get("channel"), "C0123456789") | ||
| self.assertEqual(stop_request.get("ts"), "123.123") | ||
| self.assertEqual( | ||
| json.dumps(stop_request.get("chunks")), | ||
| '[{"text": "\\n", "type": "markdown_text"}, {"text": ":space_invader:", "type": "markdown_text"}]', | ||
| ) | ||
|
|
||
| def test_streams_errors_when_appending_to_an_unstarted_stream(self): | ||
| streamer = self.client.chat_stream( | ||
| channel="C0123456789", | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🌟 it is much easier to have both markdown and chunks optional!