pub fn process_messages(messages: &[Message]) -> Vec<Message>
Expand description
process_messages take arbitrary user input messages and process them to ensure them conform to Anthropic API requirements. the requirements are:
- start with user message
- alternate between user and assistant message
- the last assistant message cannot have trailing empty space
This function will:
- drop any empty message
- concatenate consecutive messages of the same role
- add a user message to the start of the conversation if the first message is of role assistant
- trim trailing empty space from the last message if it is of role assistant