# utils.py from typing import List def build_conversation_prompt(history: List[str], user_input: str, system_prompt: str = None) -> str: """ Build a single string prompt for the causal LM from conversation history and the new user input. history: list of previous lines (alternating user/assistant) or full conversation pieces. user_input: current user message. system_prompt: optional introductory prompt at beginning. """ parts = [] if system_prompt: parts.append(system_prompt.strip()) for i, h in enumerate(history): parts.append(h.strip()) parts.append("User: " + user_input.strip()) parts.append("Assistant:") return "\n".join(parts)