mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Mistral: sanitize tool call id
This commit is contained in:
@ -522,8 +522,18 @@ function convertMistralMessages(messages, charName = '', userName = '') {
|
|||||||
lastMsg.prefix = true;
|
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).
|
// Doesn't support completion names, so prepend if not already done by the frontend (e.g. for group chats).
|
||||||
messages.forEach(msg => {
|
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 (msg.role === 'system' && msg.name === 'example_assistant') {
|
||||||
if (charName && !msg.content.startsWith(`${charName}: `)) {
|
if (charName && !msg.content.startsWith(`${charName}: `)) {
|
||||||
msg.content = `${charName}: ${msg.content}`;
|
msg.content = `${charName}: ${msg.content}`;
|
||||||
|
Reference in New Issue
Block a user