Open Jamesllllllllll opened 9 months ago
In OpenAI's example, all the keys in the tools
object have quotations. Is this required in our back-end?
I generated the steps based on OpenAI's documentation:
const assistant = await openai.beta.assistants.create({
// ... other assistant configurations ...
tools: [{
"type": "function",
"function": {
"name": "sendDocumentString",
// ... other function parameters and descriptions ...
}
}]
// ... possibly more functions ...
});
When a user sends a message that triggers the sendDocumentString function, the run will enter a requires_action state. You can check this by retrieving the run.
Fetch the run details to see which functions are required. The run's details will include the required_action object, which specifies the function calls needed.
Based on the function name and arguments provided in the required_action, execute the corresponding function in your backend. For example, if sendDocumentString is called, run that function with the provided arguments.
After executing the function, submit the outputs back to the Assistant's API. Use the tool_call_id to match the output with each function call. Here's how you might do it for sendDocumentString:
const run = await openai.beta.threads.runs.submitToolOutputs(
thread.id,
run.id,
{
tool_outputs: [
{
tool_call_id: callIdForSendDocumentString,
output: "Success message or relevant output from sendDocumentString",
},
// ... outputs for other tool calls, if any ...
],
}
);
After submitting the outputs, the run will enter a queued state and then continue its execution, processing the output you provided.
I updated retrieveRun
to the following
static async retrieveRun(threadId, runId) {
const retrievedThread = await openai.beta.threads.runs.retrieve(
threadId,
runId
);
return new Run(
retrievedThread.id,
retrievedThread.thread_id,
retrievedThread.assistant_id,
retrievedThread.status,
retrievedThread.required_action // This is the only new line
);
}
I started working on the Assistant constructor. I added a second
type
object in thetools
property array:The changes are not live.