Why im unable to get the response of thread even though im running the thread
Here is my complete code :
exports.petMateAssistant = functions.https.onRequest(async (req, res) => {
try {
const configSnapshot = await refs.config.get();
const configData = configSnapshot.docs[0].data();
const { assistantId,vectorStoreId } = configData;
const snapshot = await refs.pets.where('userId', '==', userID).get();
if (snapshot.empty) {
res.status(404).send('No pet found for the provided userID');
return;
}
const petData = snapshot.docs[0].data();
let petInstructions = petAssistant()
const thread = await openai.beta.threads.create({
messages: [ { role: "user", content: query} ],
tool_resources: {
"file_search": {
"vector_store_ids": [vectorStoreId]
}
}
});
const run = await openai.beta.threads.runs.create(
thread.id,
{
assistant_id: assistantId,
model: "gpt-4o",
instructions: petInstructions,
tools: [{"type": "file_search"}]
}
);
const completedRun = await waitForCompletion(thread.id, run.id);
res.status(200).json({
response: "Response"
});
} catch (error) {
console.error(error);
res.status(500).send(`Error: ${error.message}`);
}
})