get_openai_messages¶
- torchtune.data.get_openai_messages(sample: Mapping[str, Any], train_on_input: bool = False) List[Message] [source]¶
Convert a chat sample adhering to the OpenAI API json structure to torchtune’s
Message
structure.OpenAI API standard chat format follows:
{ # key could be "messages" OR "conversations" "messages": [ { "role": <system|user|assistant>, "content": <message>, }, ... ] }
Message
follows:[ { "role": <system|user|assistant>, "content": <message>, }, ... ]
- Parameters:
- Raises:
ValueError – If the sample does not contain “messages” or “conversations” key.
- Returns:
A list of messages with “role” and “content” fields.
- Return type:
List[Message]