mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-04-17 18:18:11 +00:00
[FIX] Validate messages schema for gemini provider (#1351)
validate messages schema for gemini provider
This commit is contained in:
parent
7b18a36288
commit
948ac8a3dd
1 changed files with 18 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue