Skip to content

on_chat_model_stream event chunk content in astream_events() is list not str #486

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
Maxew42 opened this issue May 21, 2025 · 0 comments · May be fixed by #491
Open

on_chat_model_stream event chunk content in astream_events() is list not str #486

Maxew42 opened this issue May 21, 2025 · 0 comments · May be fixed by #491

Comments

@Maxew42
Copy link

Maxew42 commented May 21, 2025

When using astream_events() with ChatBedrockConverse, the on_chat_model_stream events do not have the format I was expecting. The field data.chunk.content is a list rather then a string.
This is not aligned with the behaviour presented here for chat models. This is also not aligned with the behaviour of the ChatBedrock model, which gives a string. Its also not aligned with the behaviour of ChatBedrockConverse described in the table below here.

Is this intentional ?

Code:

from langchain_aws import ChatBedrockConverse
import os

async def chat_langchain_astream_events():
    llm = ChatBedrockConverse(
        model="anthropic.claude-3-5-sonnet-20240620-v1:0",
        region_name="eu-central-1",
        aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
        aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
        )

    message = [("user", "Hey, how are you?")]
    events = []
    async for event in llm.astream_events(message, version="v2"):
        events.append(event)
    print(events[1:3])

Output:

[{'event': 'on_chat_model_stream', 'run_id': '6915e633-7473-42d0-bbab-b894920929c8', 'name': 'ChatBedrockConverse', 'tags': [], 'metadata': {'ls_provider': 'amazon_bedrock', 'ls_model_name': 'anthropic.claude-3-5-sonnet-20240620-v1:0', 'ls_model_type': 'chat', 'ls_temperature': None}, 'data': {'chunk': AIMessageChunk(content=[], additional_kwargs={}, response_metadata={}, id='run--6915e633-7473-42d0-bbab-b894920929c8')}, 'parent_ids': []}, 
 {'event': 'on_chat_model_stream', 'run_id': '6915e633-7473-42d0-bbab-b894920929c8', 'name': 'ChatBedrockConverse', 'tags': [], 'metadata': {'ls_provider': 'amazon_bedrock', 'ls_model_name': 'anthropic.claude-3-5-sonnet-20240620-v1:0', 'ls_model_type': 'chat', 'ls_temperature': None}, 'data': {'chunk': AIMessageChunk(content=[{'type': 'text', 'text': 'Hello', 'index': 0}], additional_kwargs={}, response_metadata={}, id='run--6915e633-7473-42d0-bbab-b894920929c8')}, 'parent_ids': []}]

in particular ...'data': {'chunk': AIMessageChunk(content=[{'type': 'text', 'text': 'Hello', 'index': 0}], ...
Where I would expect ...'data': {'chunk': AIMessageChunk(content='Hello', ... as

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 a pull request may close this issue.

1 participant