How can I access the assistants data through API?

I have trained my assistance with my data.

I have the assistance ID, API key, and thread ID how can I access the trained data using the assistance API?

I want to retrieve my trained data through API using node js.

const OpenAI = require('openai');
const dotenv = require('dotenv');

dotenv.config();

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

async function main() {
  const threadMessages = await openai.beta.threads.messages.create(
    "thre9kzUr",
    { role: "user", content: "How can I contact your technical support team?" }
  );

  console.log(threadMessages);
}

main();

This code gives the value of the same as what I am asking. How can I modify this code to get the desired output?

After loading a user message into a thread, after configuring an assistant, you must invoke a run with the assistant and thread ID. You must then continue polling to wait for a reply to be ready.

Documentation and API reference are two links in the sidebar on the left or menu of this forum. Each have a section for assistants.

@_j After referring I come up with the below solution. By running this code I am getting the same response.

const OpenAI = require('openai');
const dotenv = require('dotenv');

dotenv.config();

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });


const sumfun = async () => {


const thread = await openai.beta.threads.create({
  messages: [
    {
      "role": "user",
      "content": "How can I contact your technical support team?",
    }
  ]
});

const run = await openai.beta.threads.runs.create(
  thread.id,
  {
    assistant_id: "asst_65QoRVZBT",
  }
);


const run_response = await openai.beta.threads.runs.retrieve(
  thread.id,
  run.id
);
console.log("run respnse:  => " + run_response);


const threadMessages = await openai.beta.threads.messages.list(
  thread.id
);

console.log(threadMessages.data[0].content[0]);

}


sumfun();

Response:

{
  type: 'text',
  text: {
    value: 'How can I contact your technical support team?',
    annotations: []
  }
}

Are there any modifications that need to be made?

The AI doesn’t have an answer ready milliseconds after you set the run into motion.

Polling for updates

In order to keep the status of your run up to date, you will have to periodically retrieve the Run object. You can check the status of the run each time you retrieve the object to determine what your application should do next. We plan to add support for streaming to make this simpler in the near future.

1 Like

Yeah, I got it. I am getting the response that I want. Thank you.