langchain-ai / langchain-google

MIT License
76 stars 79 forks source link

chore: add stop_reason in ChatAnthropicVertex stream response #342

Closed kiarina closed 3 days ago

kiarina commented 4 days ago

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