get_buffer_string#
- langchain_core.messages.utils.get_buffer_string(messages: Sequence[BaseMessage], human_prefix: str = 'Human', ai_prefix: str = 'AI') str [source]#
Convert a sequence of Messages to strings and concatenate them into one string.
- Parameters:
messages (Sequence[BaseMessage]) β Messages to be converted to strings.
human_prefix (str) β The prefix to prepend to contents of HumanMessages. Default is βHumanβ.
ai_prefix (str) β THe prefix to prepend to contents of AIMessages. Default is βAIβ.
- Returns:
A single string concatenation of all input messages.
- Raises:
ValueError β If an unsupported message type is encountered.
- Return type:
str
Example
from langchain_core import AIMessage, HumanMessage messages = [ HumanMessage(content="Hi, how are you?"), AIMessage(content="Good, how are you?"), ] get_buffer_string(messages) # -> "Human: Hi, how are you?\nAI: Good, how are you?"