Skip to content

Commit

Permalink
Remove unneeded code
Browse files Browse the repository at this point in the history
`gemini-1.5-pro-latest` successfully accept multiple user messages,
so it's now no need to insert dummy model messages between them
  • Loading branch information
johnd0e committed Apr 11, 2024
1 parent 26d09dc commit ce3b012
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" } });
Expand Down

0 comments on commit ce3b012

Please sign in to comment.