#Assistant API query Response

1 messages · Page 1 of 1 (latest)

normal ocean
#

I have create a assistant , now i want that when user asks any query that assistant gets called , im doing this but im not getting the response. Keep in mind i have enabled file search feature

    const query = req.body.query;
    if (!query) {
        res.status(400).send('Query is required');
        return;
    }
    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();

        const thread = await openai.beta.threads.create({
            messages: [ { role: "user", content: query} ],
            tool_resources: {
              "file_search": {
                "vector_store_ids": [vectorStoreId]
              }
            }
          });
        console.log("🚀 thread:", thread)```
mint locustBOT
#

Hi @normal ocean. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the code you've provided, it seems like you're correctly creating a thread with a user message and attaching a vector store ID for the file search tool. However, to get a response from the assistant, you need to make a run call after creating the thread.

Here's how you can do it:

const run = await openai.beta.runs.create({
    thread_id: thread.id,
    messages: [{ role: "user", content: query }]
});
console.log("🚀 run:", run);

This run call will execute the assistant with the provided user message and return the assistant's response.

Please note that the run call should be made after the thread creation, and you should use the thread.id from the created thread as the thread_id in the run call.

Also, ensure that your OpenAI Node library is up-to-date, as there have been updates to the Assistants API and the SDKs (source (https://community.openai.com/t/747575)).

If you're still not getting a response, there could be a few reasons for this. One possibility is that the AI decided that "endoftext" was the logical output, and thus no response was given (source (https://community.openai.com/t/598994)). Another possibility could be an issue with the Node library not firing the "toolCall" event for "file_search" (source (https://github.com/openai/openai-node/issues/850)).

If you're still facing issues, I would recommend checking the OpenAI API documentation or seeking help on the OpenAI community forum.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: