Skip to content
Snippets Groups Projects
Unverified Commit 948ac8a3 authored by Sean Hatfield's avatar Sean Hatfield Committed by GitHub
Browse files

[FIX] Validate messages schema for gemini provider (#1351)

validate messages schema for gemini provider
parent 7b18a362
No related branches found
No related tags found
No related merge requests found
......@@ -114,6 +114,24 @@ class GeminiLLM {
allMessages[allMessages.length - 1].role === "user"
)
allMessages.pop();
// Validate that after every user message, there is a model message
// sometimes when using gemini we try to compress messages in order to retain as
// much context as possible but this may mess up the order of the messages that the gemini model expects
// we do this check to work around the edge case where 2 user prompts may be next to each other, in the message array
for (let i = 0; i < allMessages.length; i++) {
if (
allMessages[i].role === "user" &&
i < allMessages.length - 1 &&
allMessages[i + 1].role !== "model"
) {
allMessages.splice(i + 1, 0, {
role: "model",
parts: [{ text: "Okay." }],
});
}
}
return allMessages;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment