I get the following error:
Error: 400 1 validation error for Request
body -> tool_outputs
extra fields not permitted (type=value_error.extra)
when submitting tool outputs in a stream. As far as I can tell my code is identical to the api docs:
const { content, assistantId, fnRegistry } = req
const { client } = this
const threadId = req.threadId ?? (await client.beta.threads.create()).id
const lastRuns = await client.beta.threads.runs.list(threadId, { limit: 1 })
const lastRun = lastRuns.data[0]
if (lastRun && !FINISHED_STATUSES.includes(lastRun.status)) {
throw new Error("This thread already has an active run, please wait")
}
await client.beta.threads.messages.create(threadId, {
role: "user",
content
})
const resultTextStream = []
const args = {}
return new Promise(resolve => {
let runId = ""
client.beta.threads.runs
.createAndStream(threadId, {
assistant_id: assistantId
})
.on("run", run => {
runId = run.id
})
.on("runStepDone", () => resolve({ threadId }))
.on("textCreated", text => console.log(`\nassistant > ${text.value}\n\n`))
.on("textDelta", textDelta => {
resultTextStream.push(textDelta.value)
console.log(resultTextStream.join(""))
})
.on("toolCallCreated", toolCall => console.log(`\nassistant > ${toolCall.type}\n\n`))
.on("toolCallDone", async (toolCall: FunctionToolCall) => {
const argP = JSON.parse(args[toolCall.id].join(""))
const { result } = await callFn(toolCall.function.name, argP, fnRegistry)
console.log(result)
const stream = await client.beta.threads.runs.submitToolOutputs(threadId, runId, {
tool_outputs: [
{
tool_call_id: toolCall.id,
output: "Done"
}
]
})
for await (const event of stream) {
console.log(event)
}
})
.on("toolCallDelta", (toolCallDelta, snapshot) => {
if (toolCallDelta.type === "function") {
args[snapshot.id] = [...(args[snapshot.id] ?? []), toolCallDelta.function.arguments]
}
if (toolCallDelta.type === "code_interpreter") {
if (toolCallDelta.code_interpreter.input) {
console.log(toolCallDelta.code_interpreter.input)
}
if (toolCallDelta.code_interpreter.outputs) {
console.log("\noutput >\n")
toolCallDelta.code_interpreter.outputs.forEach(output => {
if (output.type === "logs") {
console.log(`\n${output.logs}\n`)
}
})
}
}
})
})
}
Any idea what this could mean?