Mistral: sanitize tool call id

2a25f75fa5e6c8160dd195a7686b6220de977d3e

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -0Showing whitespace changes
src/prompt-converters.js+10 -0
@@ -522,8 +522,18 @@ function convertMistralMessages(messages, charName = '', userName = '') {
522 lastMsg.prefix = true;522 lastMsg.prefix = true;
523 }523 }
524524
525 const sanitizeToolId = (id) => id.replace(/[^a-zA-Z0-9]/g, '').slice(0, 9);
526
525 // Doesn't support completion names, so prepend if not already done by the frontend (e.g. for group chats).527 // Doesn't support completion names, so prepend if not already done by the frontend (e.g. for group chats).
526 messages.forEach(msg => {528 messages.forEach(msg => {
529 if ('tool_calls' in msg && Array.isArray(msg.tool_calls)) {
530 msg.tool_calls.forEach(tool => {
531 tool.id = sanitizeToolId(tool.id);
532 });
533 }
534 if ('tool_call_id' in msg && msg.role === 'tool') {
535 msg.tool_call_id = sanitizeToolId(msg.tool_call_id);
536 }
527 if (msg.role === 'system' && msg.name === 'example_assistant') {537 if (msg.role === 'system' && msg.name === 'example_assistant') {
528 if (charName && !msg.content.startsWith(`${charName}: `)) {538 if (charName && !msg.content.startsWith(`${charName}: `)) {
529 msg.content = `${charName}: ${msg.content}`;539 msg.content = `${charName}: ${msg.content}`;