The Chat Messages Format
Modern LLM APIs (Anthropic, OpenAI) take a list of messages. Each message has
a role ("user" or "assistant") and content. The model continues the
conversation.
[
{ role: "user", content: "Hi!" },
{ role: "assistant", content: "Hello! How can I help?" }
]
Your task
Write toMessages(turns) that takes an array of plain strings and returns a
messages array. The first string is from the "user", and roles then
alternate user β assistant β user β ...
β‘ 30 XP
solution.jsRuns in your browser
Loading editorβ¦
Tests2 to pass
alternates roles
empty input β empty array
Run your code to check these.