Hello, I’m currently working on implementing an Assistant chatbot in React. Initially, I followed the steps outlined in the documentation, and everything seemed to be functioning correctly a few days ago. I was able to successfully interact with the API. However, recently, I’ve encountered an issue when attempting to retrieve the run. Regardless of what I try, it consistently fails. I’m unsure of what mistake I might be making. If anyone could offer assistance, I would greatly appreciate it
here is the code.
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: import.meta.env.VITE_API_KEY,
dangerouslyAllowBrowser: true,
});
const assistant_id = "asst_VvjBUWSbAj4c2pn2ITjOohwN";
async function FetchBot(chatMessages, setId) {
// this function just create retrieve the assistant and create a Thread
// Get the assistant
const myAssistant = await openai.beta.assistants.retrieve(assistant_id);
// Create a thread
const Thread = await openai.beta.threads.create();
setId(Thread.id);
}
async function handleUserMessage(
id,
msg,
chatMessages,
setChatMessages,
setIsChatbotTyping
) {
// create threats
const message = await openai.beta.threads.messages.create(id, {
role: "user",
content: "hola",
});
// Create Run
let run = await openai.beta.threads.runs.create(id, {
assistant_id: assistant_id,
});
setIsChatbotTyping(true);
let status = false;
while (!status) {
try {
await new Promise((resolve) => setTimeout(resolve, 500));
run = await openai.beta.threads.runs.retrieve(id, run.id);
console.log(run.status);
if (run.status === "completed") {
status = true;
setIsChatbotTyping(false);
await openai.beta.threads.messages.list(id);
setChatMessages([...chatMessages]);
}
} catch (error) {
console.log("algo salio mal ");
}
}
}