How can I integrate API Assistants into my Google Sheet like I could do with normal ChatGPT?

So I’ve found this instruction on how to implement ChatGPT in Google Sheets via function and AppScripts from a blog called Mindempire:

const SECRET_KEY = "YOUR API KEY";
const MAX_TOKENS = 800;
const TEMPERATURE = 0.9;

function AI_ChatGPT(prompt, temperature = 0.4, model = "gpt-3.5-turbo") {
  const url = "https://api.openai.com/v1/chat/completions";
  const payload = {
    model: model,
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: prompt },
    ],
    temperature: TEMPERATURE,
    max_tokens: MAX_TOKENS,
  };
  const options = {
    contentType: "application/json",
    headers: { Authorization: "Bearer " + SECRET_KEY },
    payload: JSON.stringify(payload),
  };
  const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
  return res.choices[0].message.content.trim();
}

But how would I achieve the same with my prebuilt AI Assistants?

Thanks in advance.

Hey there!

Have you looked at the Assistants doc in the OpenAI docs? This might help:

https://platform.openai.com/docs/assistants/tools

If you’re the type to look at more of the code to see how it works, you can also check it out in the cookbook: