| 522 | lastMsg.prefix = true; | 522 | lastMsg.prefix = true; |
| 523 | } | 523 | } |
| 524 | | 524 | |
| | 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}`; |