mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-11 17:07:07 +01:00
Fix tool call reuse between Claude and OAI
This commit is contained in:
parent
f7ec2e47d6
commit
6b022e783d
@ -88,6 +88,15 @@ function tryParse(str) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringifies an object if it is not already a string.
|
||||
* @param {any} obj The object to stringify
|
||||
* @returns {string} A JSON string representation of the object.
|
||||
*/
|
||||
function stringify(obj) {
|
||||
return typeof obj === 'string' ? obj : JSON.stringify(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class that represents a tool definition.
|
||||
*/
|
||||
@ -571,7 +580,7 @@ export class ToolManager {
|
||||
id,
|
||||
displayName,
|
||||
name,
|
||||
parameters,
|
||||
parameters: stringify(parameters),
|
||||
result: toolResult,
|
||||
};
|
||||
result.invocations.push(invocation);
|
||||
|
@ -131,13 +131,14 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
|
||||
}
|
||||
|
||||
// Now replace all further messages that have the role 'system' with the role 'user'. (or all if we're not using one)
|
||||
const parse = (str) => typeof str === 'string' ? JSON.parse(str) : str;
|
||||
messages.forEach((message) => {
|
||||
if (message.role === 'assistant' && message.tool_calls) {
|
||||
message.content = message.tool_calls.map((tc) => ({
|
||||
type: 'tool_use',
|
||||
id: tc.id,
|
||||
name: tc.function.name,
|
||||
input: tc.function.arguments,
|
||||
input: parse(tc.function.arguments),
|
||||
}));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user