66from botocore .eventstream import EventStream
77from botocore .exceptions import ClientError
88from haystack import component , default_from_dict , default_to_dict , logging
9+ from haystack .components .generators .utils import _normalize_messages
910from haystack .dataclasses import (
1011 ChatMessage ,
1112 ComponentInfo ,
@@ -520,7 +521,7 @@ def _resolve_flattened_generation_kwargs(generation_kwargs: dict[str, Any]) -> d
520521 @component .output_types (replies = list [ChatMessage ])
521522 def run (
522523 self ,
523- messages : list [ChatMessage ],
524+ messages : list [ChatMessage ] | str ,
524525 streaming_callback : StreamingCallbackT | None = None ,
525526 generation_kwargs : dict [str , Any ] | None = None ,
526527 tools : ToolsType | None = None ,
@@ -531,6 +532,7 @@ def run(
531532 Supports both standard and streaming responses depending on whether a streaming callback is provided.
532533
533534 :param messages: A list of `ChatMessage` objects forming the chat history.
535+ If a string is provided, it is converted to a list containing a ChatMessage with user role.
534536 :param streaming_callback: Optional callback for handling streaming outputs.
535537 :param generation_kwargs: Optional dictionary of generation parameters. Some common parameters are:
536538 - `maxTokens`: Maximum number of tokens to generate.
@@ -546,6 +548,7 @@ def run(
546548 :raises AmazonBedrockInferenceError:
547549 If the Bedrock inference API call fails.
548550 """
551+ messages = _normalize_messages (messages )
549552 component_info = ComponentInfo .from_component (self )
550553
551554 params , callback = self ._prepare_request_params (
@@ -582,7 +585,7 @@ def run(
582585 @component .output_types (replies = list [ChatMessage ])
583586 async def run_async (
584587 self ,
585- messages : list [ChatMessage ],
588+ messages : list [ChatMessage ] | str ,
586589 streaming_callback : StreamingCallbackT | None = None ,
587590 generation_kwargs : dict [str , Any ] | None = None ,
588591 tools : ToolsType | None = None ,
@@ -593,6 +596,7 @@ async def run_async(
593596 Designed for use cases where non-blocking or concurrent execution is desired.
594597
595598 :param messages: A list of `ChatMessage` objects forming the chat history.
599+ If a string is provided, it is converted to a list containing a ChatMessage with user role.
596600 :param streaming_callback: Optional async-compatible callback for handling streaming outputs.
597601 :param generation_kwargs: Optional dictionary of generation parameters. Some common parameters are:
598602 - `maxTokens`: Maximum number of tokens to generate.
@@ -608,6 +612,7 @@ async def run_async(
608612 :raises AmazonBedrockInferenceError:
609613 If the Bedrock inference API call fails.
610614 """
615+ messages = _normalize_messages (messages )
611616 component_info = ComponentInfo .from_component (self )
612617
613618 params , callback = self ._prepare_request_params (
0 commit comments