def format_history(history): """Format chat history for the model input.""" formatted = "" for user_msg, assistant_msg in history: formatted += f"User: {user_msg}\nAssistant: {assistant_msg}\n" return formatted.strip()