def _process_msgs()

in evals/solvers/providers/together/together_solver.py [0:0]


    def _process_msgs(self, msgs: list[dict[str, str]]) -> list[dict[str, str]]:
        """
        Many OS models, like Llama-2 and Mixtral, expect a more specific format than
        we often provide to OpenAI models. In particular
        - there should only be a single system prompt, at the start
        - there should be at least one user prompt
        - after an optional system prompt, the messages should alternate between
            user and assistant messages.
        """
        msgs = copy.deepcopy(msgs)

        # if there is only a system message, turn it to a user message
        if len(msgs) == 1 and msgs[0]["role"] == "system":
            return [{"role": "user", "content": msgs[0]["content"]}]

        # convert all system messages except a possible first one to user messages
        for i, msg in enumerate(msgs):
            if msg["role"] == "system" and i > 0:
                msg["role"] = "user"

        # if the first message is a system message and the second one is an assistant message,
        # this implies that we previously converted the initial system message to a user message,
        # so we should convert the initial system message to a user message again for consistency
        # NOTE: this looks like it'd fail on length 1 messages, but that's handled by the first if
        # combined with the first statement of this if and lazy evaluation
        if msgs[0]["role"] == "system" and msgs[1]["role"] == "assistant":
            msgs[0]["role"] = "user"

        # before returning, we optionally merge all adjacent messages from the same role
        if self.merge_adjacent_msgs:
            merged_msgs = []
            for msg in msgs:
                if len(merged_msgs) > 0 and merged_msgs[-1]["role"] == msg["role"]:
                    merged_msgs[-1]["content"] += "\n\n" + msg["content"]
                else:
                    merged_msgs.append(msg)
            msgs = merged_msgs
        return msgs