I call ChatGPT with the following App Script in a Google Sheet. I’ve created an assistant with an ID.
How can I call the assistant instead of having the role set to “you are a helpful assistant”?
Thanks in advance.
const SECRET_KEY = "myapikeylskadfjlkasjflk";
const MAX_TOKENS = 800;
const TEMPERATURE = 0.4;
function GPTturbo(prompt, temperature = 0.4, model = "gpt-4-1106-preview") {
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();
}