docstr: This parser is based on the format described in
  https://huggingface.co/blog/llama2#how-to-prompt-llama-2 .
  The expected format is:
      "<s>[INST] <<SYS>>
      {{ system_prompt }}
      <</SYS>>
  
      {{ user_msg_1 }} [/INST] {{ model_answer_1 }} </s>
      <s>[INST] {{ user_msg_2 }} [/INST]"
docstr_tok: ["This","parser","is","based","on","the","format","described","in","https",":","\/\/huggingface.co\/blog\/llama2","#","how-to-prompt-llama-2",".","The","expected","format","is",":","``","<","s",">","[","INST","]","<","<","SYS",">",">","{","{","system_prompt","}","}","<","<","\/SYS",">",">","{","{","user_msg_1","}","}","[","\/INST","]","{","{","model_answer_1","}","}","<","\/s",">","<","s",">","[","INST","]","{","{","user_msg_2","}","}","[","\/INST","]","''"]
code: def _parse_chat_messages_to_prompt(
      messages: List[chat.RequestMessage],
  ) -> str:
      """
      This parser is based on the format described in
      https://huggingface.co/blog/llama2#how-to-prompt-llama-2 .
      The expected format is:
          "<s>[INST] <<SYS>>
          {{ system_prompt }}
          <</SYS>>
  
          {{ user_msg_1 }} [/INST] {{ model_answer_1 }} </s>
          <s>[INST] {{ user_msg_2 }} [/INST]"
      """
      prompt = "<s>"  # Always start with an opening <s> tag
      for m in messages:
          if m.role == "system" or m.role == "user":
              inst = m.content
  
              # Wrap system messages in <<SYS>> tags
              if m.role == "system":
                  inst = f"<<SYS>> {inst} <</SYS>>"
  
              # Close the [INST] tag
              inst += " [/INST]"
  
              # If the previous message was a system/user message,
              # remove previous closing [/INST] tag
              if prompt.endswith("[/INST]"):
                  prompt = prompt[:-7]
              # Otherwise, add an opening [INST] tag
              else:
                  inst = f"[INST] {inst}"
              prompt += inst
          elif m.role == "assistant":
              # Add statement closing/opening tags by default
              prompt += f" {m.content} </s><s>"
          else:
              raise MlflowException.invalid_parameter_value(
                  f"Invalid role {m.role} inputted. Must be one of 'system', "
                  "'user', or 'assistant'.",
              )
  
      # Remove the last </s><s> tags if they exist to allow for
      # assistant completion prompts.
      if prompt.endswith("</s><s>"):
          prompt = prompt[:-7]
      return prompt
  
file_path: mlflow/mlflow/gateway/providers/mosaicml.py
imports: import time
  from contextlib import contextmanager
  from typing import Any, Dict, List
  from fastapi import HTTPException
  from fastapi.encoders import jsonable_encoder
  from mlflow.exceptions import MlflowException
  from mlflow.gateway.config import MosaicMLConfig, RouteConfig
  from mlflow.gateway.providers.base import BaseProvider
  from mlflow.gateway.providers.utils import rename_payload_keys, send_request
  from mlflow.gateway.schemas import chat, completions, embeddings
label_desc: Use image node_id 2 for calling the MosaicMLProvider obj's underlying member method code with example usage: obj._parse_chat_messages_to_prompt(messages) and returns: prompt