mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
🔝fix: Re-order System Message to Top for Mistral API Payloads (#1678)
* fix: re-order System Message if Mistral AI API as it only allows System Message at start of Payload * fix: re-introduce singular system message change role to `user` if `system`
This commit is contained in:
parent
c4fd8a38e3
commit
9fad1b2cae
1 changed files with 14 additions and 1 deletions
|
|
@ -976,9 +976,22 @@ ${convo}
|
|||
...opts,
|
||||
});
|
||||
|
||||
/* hacky fix for Mistral AI API not allowing a singular system message in payload */
|
||||
/* hacky fixes for Mistral AI API:
|
||||
- Re-orders system message to the top of the messages payload, as not allowed anywhere else
|
||||
- If there is only one message and it's a system message, change the role to user
|
||||
*/
|
||||
if (opts.baseURL.includes('https://api.mistral.ai/v1') && modelOptions.messages) {
|
||||
const { messages } = modelOptions;
|
||||
|
||||
const systemMessageIndex = messages.findIndex((msg) => msg.role === 'system');
|
||||
|
||||
if (systemMessageIndex > 0) {
|
||||
const [systemMessage] = messages.splice(systemMessageIndex, 1);
|
||||
messages.unshift(systemMessage);
|
||||
}
|
||||
|
||||
modelOptions.messages = messages;
|
||||
|
||||
if (messages.length === 1 && messages[0].role === 'system') {
|
||||
modelOptions.messages[0].role = 'user';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue