diff --git a/src/worker.mjs b/src/worker.mjs index a496a46..ad412f4 100644 --- a/src/worker.mjs +++ b/src/worker.mjs @@ -197,19 +197,14 @@ const transformMsg = async ({ role, content }) => { const transformMessages = async (messages) => { const contents = []; let system_instruction; - let lastRole; for (const item of messages) { if (item.role === "system") { delete item.role; system_instruction = await transformMsg(item); - continue; - } - item.role = item.role === "assistant" ? "model" : "user"; - if (item.role === "user" && lastRole === "user") { - contents.push({ role: "model", parts: { text: "" } }); + } else { + item.role = item.role === "assistant" ? "model" : "user"; + contents.push(await transformMsg(item)); } - lastRole = item.role; - contents.push(await transformMsg(item)); } if (system_instruction && contents.length === 0) { contents.push({ role: "user", parts: { text: "" } });