Hey y’all,
I am trying to build my own veterinarian assistant that talks to the user back and forth about their pet. Right now I am building API’s for each function so that I can call them via an API client like insomnia. Right now I am trying to pass threads to my createRun function which takes the thread_id and assistant_id. I keep getting the error saying “thread_id” not found. I also created a retrieveThread function but that is also saying the same thing. I was reading the other forums and I don’t understand if we must store the thread_id into a database and call it from there? I don’t understand if we store that thread_id somewhere, where is the thread itself? If we can’t find the ID where would the actual thread itself be? Here is my code for nodeJS and ExpressJs:
export async function createThread (request: Request, response: Response){
const openai = new OpenAI({ apiKey });
try {
const thread = await openai.beta.threads.create();
console.log(thread);
return response.json({ thread: thread });
} catch (e) {
console.log(e);
return response.json({ error: e });
}
}
export async function retrieveThread (request: Request, response: Response){
const threadId = request.params.threadId;
if (!threadId)
return response.status(400).json({ error: "No id provided" });
const openai = new OpenAI({ apiKey });
try {
if (typeof threadId === "string") {
const thread = await openai.beta.threads.retrieve(threadId);
console.log(thread);
return response.json({ thread: thread });
}
} catch (e) {
console.log(e);
return response.json({ error: e });
}
}
This createRun isn’t working as the thread_id is not there.
export async function createRun(request: Request, response: Response) {
const { threadId, assistantId } = request.params;
if(!threadId)
return response.status(400).json({error: "Missing threadId"})
if(!assistantId)
return response.status(400).json({error: "Missing assistantId"})
const openai = new OpenAI({ apiKey });
try {
if (typeof threadId === "string") {
const run = await openai.beta.threads.runs.create(threadId, {
assistant_id: assistantId
});
console.log({ run: run });
return response.json({ run });
}
} catch (e) {
console.log(e);
return response.status(500).json({ error: e});
}
}
Any help is greatly appreciated!