Allow ChatVertexAI to get stop_reason in the AIMessage of the stream, astream result.
The reason for this change is that the stop_reason is also used in streaming to determine the next action.
ai_message_chunk: AIMessageChunk = None
for chunk in model.stream([HumanMessage(content="Hello, world!")]):
ai_message_chunk = ai_message_chunk + chunk if ai_message_chunk else chunk
print(ai_message_chunk.response_metadata["stop_reason"], ai_message.response_metadata["stop_sequence"])
# end_turn None
Allow
ChatVertexAI
to getstop_reason
in theAIMessage
of thestream
,astream
result. The reason for this change is that thestop_reason
is also used in streaming to determine the next action.