Mistral: sanitize tool call id

This commit is contained in:
Cohee 2024-10-06 20:07:43 +03:00
parent 2e36f45e24
commit 2a25f75fa5

View File

@ -522,8 +522,18 @@ function convertMistralMessages(messages, charName = '', userName = '') {
lastMsg.prefix = true;
}
const sanitizeToolId = (id) => id.replace(/[^a-zA-Z0-9]/g, '').slice(0, 9);
// Doesn't support completion names, so prepend if not already done by the frontend (e.g. for group chats).
messages.forEach(msg => {
if ('tool_calls' in msg && Array.isArray(msg.tool_calls)) {
msg.tool_calls.forEach(tool => {
tool.id = sanitizeToolId(tool.id);
});
}
if ('tool_call_id' in msg && msg.role === 'tool') {
msg.tool_call_id = sanitizeToolId(msg.tool_call_id);
}
if (msg.role === 'system' && msg.name === 'example_assistant') {
if (charName && !msg.content.startsWith(`${charName}: `)) {
msg.content = `${charName}: ${msg.content}`;