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

Amazon Bedrock Workshop - [Bug] Streaming example in bedrock_basics.ipynb fails to output text #235

Open
jicowan opened this issue Apr 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jicowan
Copy link

jicowan commented Apr 23, 2024

Describe the bug
When you run the invoke_model_with_response_stream example in the bedrock_basics notebook, nothing is streamed to stdout.

Here is the code from the example:

    if stream:
        for event in stream:
            chunk = event.get('chunk')
            if chunk:
                chunk_obj = json.loads(chunk.get('bytes').decode())
                if 'outputText' in chunk_obj:
                    text = chunk_obj.get('outputText', None)
                    print(text,end='')
                    if not text :
                        break
                    #text = chunk_obj['outputText']
                    clear_output(wait=True)
                    output.append(text)
                    display_markdown(Markdown(''.join(output)))

I replaced the code block above with the following:

    if stream:
        for event in stream:
            chunk = event.get('chunk')
            if chunk:
                chunk_obj = json.loads(chunk.get('bytes').decode())
                text = chunk_obj['outputText']
                display_markdown(Markdown(print(text, end='')))

Expected behavior
The results should be streamed to stdout

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version NA

! Additional context !

  • Using PyCharm 2024.1
@jicowan jicowan added the bug Something isn't working label Apr 23, 2024
@jicowan jicowan changed the title Amazon Bedrock Workshop - [Streaming example in bedrock_basics.ipynb fails to output text] Amazon Bedrock Workshop - [Bug] Streaming example in bedrock_basics.ipynb fails to output text Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant