-
Notifications
You must be signed in to change notification settings - Fork 2.4k
FIX: streamify was appending StatusStreamingCallback directly to the shared settings.callbacks list #9073
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
glesperance
wants to merge
3
commits into
stanfordnlp:main
Choose a base branch
from
Trampoline-AI:fix/streamify-callbacks-settings-leak
base: main
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.
+95
−1
Open
FIX: streamify was appending StatusStreamingCallback directly to the shared settings.callbacks list #9073
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,100 @@ def module_start_status_message(self, instance, inputs): | |
| assert status_messages[2].message == "Predict starting!" | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_default_then_custom_status_message_provider(): | ||
|
Collaborator
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. We may want to refactor the testing a bit - instead of default => custom, we can put up two threads that apply different |
||
| class MyProgram(dspy.Module): | ||
| def __init__(self): | ||
| self.generate_question = dspy.Tool(lambda x: f"What color is the {x}?", name="generate_question") | ||
| self.predict = dspy.Predict("question->answer") | ||
|
|
||
| def __call__(self, x: str): | ||
| question = self.generate_question(x=x) | ||
| return self.predict(question=question) | ||
|
|
||
| class MyStatusMessageProvider(StatusMessageProvider): | ||
| def tool_start_status_message(self, instance, inputs): | ||
| return "Tool starting!" | ||
|
|
||
| def tool_end_status_message(self, outputs): | ||
| return "Tool finished!" | ||
|
|
||
| def module_start_status_message(self, instance, inputs): | ||
| if isinstance(instance, dspy.Predict): | ||
| return "Predict starting!" | ||
|
|
||
| lm = dspy.utils.DummyLM([{"answer": "red"}, {"answer": "blue"}]) | ||
| with dspy.context(lm=lm): | ||
| program = dspy.streamify(MyProgram()) | ||
| output = program("sky") | ||
|
|
||
| status_messages = [] | ||
| async for value in output: | ||
| if isinstance(value, StatusMessage): | ||
| status_messages.append(value) | ||
|
|
||
| assert len(status_messages) == 2 | ||
| assert status_messages[0].message == "Calling tool generate_question..." | ||
| assert status_messages[1].message == "Tool calling finished! Querying the LLM with tool calling results..." | ||
|
|
||
| program = dspy.streamify(MyProgram(), status_message_provider=MyStatusMessageProvider()) | ||
| output = program("sky") | ||
| status_messages = [] | ||
| async for value in output: | ||
| if isinstance(value, StatusMessage): | ||
| status_messages.append(value) | ||
| assert len(status_messages) == 3 | ||
| assert status_messages[0].message == "Tool starting!" | ||
| assert status_messages[1].message == "Tool finished!" | ||
| assert status_messages[2].message == "Predict starting!" | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_custom_then_default_status_message_provider(): | ||
| class MyProgram(dspy.Module): | ||
| def __init__(self): | ||
| self.generate_question = dspy.Tool(lambda x: f"What color is the {x}?", name="generate_question") | ||
| self.predict = dspy.Predict("question->answer") | ||
|
|
||
| def __call__(self, x: str): | ||
| question = self.generate_question(x=x) | ||
| return self.predict(question=question) | ||
|
|
||
| class MyStatusMessageProvider(StatusMessageProvider): | ||
| def tool_start_status_message(self, instance, inputs): | ||
| return "Tool starting!" | ||
|
|
||
| def tool_end_status_message(self, outputs): | ||
| return "Tool finished!" | ||
|
|
||
| def module_start_status_message(self, instance, inputs): | ||
| if isinstance(instance, dspy.Predict): | ||
| return "Predict starting!" | ||
|
|
||
| lm = dspy.utils.DummyLM([{"answer": "red"}, {"answer": "blue"}]) | ||
| with dspy.context(lm=lm): | ||
| program = dspy.streamify(MyProgram(), status_message_provider=MyStatusMessageProvider()) | ||
| output = program("sky") | ||
| status_messages = [] | ||
| async for value in output: | ||
| if isinstance(value, StatusMessage): | ||
| status_messages.append(value) | ||
| assert len(status_messages) == 3 | ||
| assert status_messages[0].message == "Tool starting!" | ||
| assert status_messages[1].message == "Tool finished!" | ||
| assert status_messages[2].message == "Predict starting!" | ||
|
|
||
| program = dspy.streamify(MyProgram()) | ||
| output = program("sky") | ||
| status_messages = [] | ||
| async for value in output: | ||
| if isinstance(value, StatusMessage): | ||
| status_messages.append(value) | ||
| assert len(status_messages) == 2 | ||
| assert status_messages[0].message == "Calling tool generate_question..." | ||
| assert status_messages[1].message == "Tool calling finished! Querying the LLM with tool calling results..." | ||
|
|
||
|
|
||
| @pytest.mark.llm_call | ||
| @pytest.mark.anyio | ||
| async def test_stream_listener_chat_adapter(lm_for_test): | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.