Skip to content

Make it easier to do sync streaming #8183

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

Merged

Conversation

chenmoneygithub
Copy link
Collaborator

Introduce a bool flag async_streaming to dspy.streamify so that users can switch easily between sync and async streaming.

By default calling a streamified DSPy program produces an async generator. In order to get back
a sync generator, you can set the flag `async_streaming=False`:

```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```python

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually is this block necessary? It seems to be duplicated with the following example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah thank you for catching it

@@ -249,11 +249,11 @@ def __call__(self, x: str, **kwargs):
dspy.streaming.StreamListener(signature_field_name="judgement"),
],
include_final_prediction_in_output_stream=False,
async_streaming=False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test run in the CI pipeline? It seems to require OPENAI_API_KEY

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not running in CI, but written for local checking. streaming behavior is a bit unreliable to verify with mock, and we should find a way to set up API key for github actions.

Copy link
Collaborator

@TomeHirata TomeHirata May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, is it difficult to mock the LiteLLM call with a dummy generator? I agree testing with a real API can increase safety, but having a unit test without relying on external infra is also valuable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocking streaming is messy but feasible, the more concerning part is the assumption on stream tokens can go wrong, which could lead to false positive test. But I agree with you that we can add another test based on mock. Merging this one now, will follow up with the test shortly.

@chenmoneygithub chenmoneygithub requested a review from TomeHirata May 7, 2025 03:01
Copy link
Collaborator

@TomeHirata TomeHirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock, let's discuss how to run these tests in CI offline

@chenmoneygithub chenmoneygithub merged commit 4771108 into stanfordnlp:main May 7, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants