Help me renew my tool. I have trouble connecting gpt-3.5-turbo-0301

Hi guys,

Thank you in advance!

im having issues with my code and i am really new to all this. I want this to work with Chat gpt (gpt-3.5-turbo-0301) this tool was developed to use text-davinci-003 but this is an old language model and i’d like to use the new one.

Can someone help me figuring out where the issue lies?

My guess is here, but im not sure where i get the new URL from:

const url = “.com /v1/completions”
var results=


function onOpen() {
SpreadsheetApp.getUi().createMenu(“OpenAI”)
.addItem(“Generate”, “openAi”)
.addItem(“Clear Content”, “clearContent”)
.addToUi();
}

function clearContent(){
const sheet = SpreadsheetApp.getActiveSheet();
const lastRow = sheet.getLastRow();
sheet.getRange(2,1,lastRow,2).clearContent();
}

function openAi(){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const settings = ss.getSheetByName(‘Settings’);
const sheet = ss.getSheetByName(‘AI’);
const model = settings.getRange(2,2).getValue();
const temperature = settings.getRange(4,2).getValue();
const maxTokens = settings.getRange(3,2).getValue();
const apiKey = settings.getRange(5,2).getValue();
const data = sheet.getDataRange().getValues();

const url = “com/v1 /completions”
var results=

for (var i =1; i<data.length; i++){
var prompt = data[i][0]
const payload = {
model: model,
prompt: prompt,
temperature: temperature,
max_tokens: maxTokens,
};

const options = {
contentType: “application/json”,
headers: { Authorization: "Bearer " + apiKey },
payload: JSON.stringify(payload),
};

const response = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
results.push ([response[‘choices’][0][‘text’]])
}

sheet.getRange(2,2,results.length,1).setValues(results)
}

Your “payload” has to be in the new messages format instead of an open-ended text prompt. You can get “chat” documentation and the correct url from “API reference” on the forum sidebar.

1 Like