From ce3b012265e75482436ccefdf01f3bda28ca292b Mon Sep 17 00:00:00 2001 From: johnd0e <1838643+johnd0e@users.noreply.github.com> Date: Thu, 11 Apr 2024 21:20:23 +0200 Subject: [PATCH] Remove unneeded code `gemini-1.5-pro-latest` successfully accept multiple user messages, so it's now no need to insert dummy model messages between them --- src/worker.mjs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) 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: "" } });