#Malformed JSON in tool calls
6 messages · Page 1 of 1 (latest)
function: async (ret) => {
try {
if(!target) {
logger.error(`Tool::Structure Path and name are required to create project structure`)
return
}
let { files } = ret as any
if(isString(files)){
try {
files = JSON.parse(files)
} catch (error) {
logger.error(`Tool::Structure Error parsing files`, error, ret)
write(path.join(target, 'tools-output.json'), files)
return
}
}
for (const file of files) {
const filePath = path.join(target, file.path);
logger.debug(`Tool:Structure Writing file ${filePath}`)
await write(filePath, file.content)
}
} catch (error) {
logger.error(`Error creating project structure`, error)
}
},
parse: JSON.parse,
sometimes it just sends strings 🙂
can you show us how you are sending the tool calling prompt?
thanks, yes
the params
let _tools = template.tools || []
const params = {
model: options.model,
messages: [
{
role: "system",
content: "You are software engineer :)"
},
...template.messages,
{
role: "user",
content: `Current files:\n${JSON.stringify(files, null, 2)}`
},
{
role: "user",
content: `${query}`
}
],
tools: _tools,
tool_choice: 'auto',
stream: true
}
the call
let runner = null
try {
runner = await client.beta.chat.completions.runTools(params as ChatCompletionToolRunnerParams<any>)
.on('message', (msg) => {
if (!msg.content) return
const messageWithMetadata = {
...msg,
timestamp: new Date().toISOString(),
sessionId,
query: options.query
}
sessionMessages.messages.push(messageWithMetadata)
})
.on('content', (diff) => process.stdout.write(diff))
} catch (error) {
logger.error('Failed to create runner:', error.message, error.issues)
return
}