Skip to content
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

Allow streaming actions to yield just state for all but the last one #277

Open
elijahbenizzy opened this issue Jul 19, 2024 · 0 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@elijahbenizzy
Copy link
Contributor

Is your feature request related to a problem? Please describe.

This should work:

@streaming_action(reads=["prompt"], writes=['response'])
        def streaming_response(state: State) -> Generator[dict, None, tuple[dict, State]]:
            response = client.chat.completions.create(
                model='gpt-3.5-turbo',
                messages=[{
                    'role': 'user',
                    'content': state["prompt"]
                    }],
                temperature=0,
            )
            buffer = []
            for chunk in response:
                delta = chunk.choices[0].delta.content
                buffer.append(delta)
                # yield partial results
                yield {'response': delta}
            full_response = ''.join(buffer)
            # return the final result
            return {'response': full_response}, state.update(response=full_response)

Instead the yield needs to be {"response": delta}, None

Describe the solution you'd like
If it's not the last yield, we should just yield the result, no need to specify None for the state update.

Tasks:

  1. Make the change here and in the function below:
    # TODO -- consider adding support for just returning a result.
  2. Add tests for this, copy from those that use this class, and corresponding async.

Describe alternatives you've considered
Not doing it

@elijahbenizzy elijahbenizzy added enhancement New feature or request good first issue Good for newcomers labels Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant