Add `finish_reason` field to `StreamingChunk`
Is your feature request related to a problem? Please describe.
Formatting streamed results from an LLM can be a bit tricky. Currently in our print_streaming_chunk utility function we use the presence of the finish_reason in the meta of a StreamingChunk to indicate that we have reached the end of a response (i.e. a full Chat Message) so we then print two newlines as a separator.
https://github.com/deepset-ai/haystack/blob/25c8d7ef9a487ef543c747ca5cd8ee7c4f73d201/haystack/components/generators/utils.py#L56-L59
However, often times in user applications we'd like to stream the LLM output in a mark down type format so we can prettify the output. In this case we often switch between text blocks and code blocks, which means we'd need to actually inspect the finish_reason to know if we should finish closing a code block (e.g. for the end of a tool call or a tool call result) or just need to return newlines (e.g. for normal text). In general knowing what the finish reasons could be would allow for more sophisticated formatting of the streamed result.
Describe the solution you'd like
So instead of storing the finish_reason in the meta field, I think it makes sense to make it a dedicated field in StreamingChunk. However, the majority of the work for completing this will be to come up with a standardized mapping of finish reasons across our different LLM integrations. For example, OpenAI uses the finish reason tool_calls vs. Bedrock uses tool_use. So it'd be good if we pick a standard set of finish reasons (maybe just the OpenAI ones?) so that we can then easily map our different integrations to this set of finish reasons.
Additional context Once the standard set of finish reasons is picked we can open up follow up issues to update our integrations to map to this standard.