Sorry Nelson, just to add on the irrelevancy part. There may be information within the cell that is not relevant to the query. I was hoping to break down the token limit by only extracting that piece of information that is relevant. But it occurs to me that I can probably do this with an intermediate query, then feed the extracted information into the final prompt.
Yes, I agree, I think your use cases might be a bit more complicated than the current spreadsheet can handle, because if we add additional search results, then you will have to measure the number of tokens so the prompt doesn’t exceed the max. I am currently working on a more robust solution that handle multiple documents and embedding. If you are interested I can show you how that works and see if it can help you solve this problem. Feel free to PM or connect with me on linkedin if you like, thanks.
https://www.linkedin.com/in/nelsonchu247/
Can we fine tune GPT 3 model using google app script ?
Hi @notifications
The gsheet is currently used for managing data between the Embeddings API and Completion API. Currently it is not designed for the FineTuning API. From my experience most uses cases don’t need the Fine Tuning API, what are you looking to do with OpenAI’s API library?
Thank you Nelson for a quick reply
I have made an end to end app using google app script as backend language and used app sheet for front end and google sheet for database.
Now I have already integrated the app with Open AI api for some of the use case.
Now I want to fine tune the model with the data captured by the app during the operation of the business.
I have never worked on python the only language I know is google app script.
Hi @notifications
For the fine tuning API, I don’t have plan on integrating with the current Google Sheet at the moment but you can follow the direction here to do it. OpenAI API
Hi Nelson,
I already trained my model by reading documentation and steps and all instructions related doubts were asked to Chat GPT itself. Learning is so easy with the help of AI… it is substantially increasing implementation process.
Thank you for your time.
Glad to hear you have made progress in such a short time. Well done!!!
I am trying to use your script and am getting an error as if the default API key of “xxxx” is still in use. The API key is valid because I have another Gsheet that makes calls to OpenAPI and it works.

After you modify the API key it won’t trigger the function yet.
Have you tried updating the cells with the input?
I tried to troubleshoot it. In the end, I found another Google Sheet that worked.
Sorry to hear that it didn’t work for you, best of luck to your project.
Hi, do you mind drop the link for the Google Sheet that worked? I make a copy of the Google Sheet and face the same issue as you mentioned in previous post.
I found out how to make it work. Need to click appscript and approve the permission and then it works perfectly.
Thanks. I’ll take another look. Here is the script that worked for me:
const SECRET_KEY = “”;
const MAX_TOKENS = 200;
const gpt_model = “text-davinci-003”
function OpenAI(prompt, temperature = 0.7, model = gpt_model) {
const url = “https://api.openai.com/v1/completions”;
const payload = {
model: model,
prompt: 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].text.trim();
}
I made a new copy of the Google Sheet and tried it again. I accepted the security settings, but no luck. I must have some other weird setting.
Hi @johnfaig
Can you also check if you are
- Using this latest version of the sheet
GPT3-On-Custom-Data - Google Sheets - Using the api key without the Bearer keyword, meaning that it should only contain the value sk-xxxxxxxxxx
Thanks for your help. It works now.
I made a copy of the Google Sheet from the link you just provided. I’m not sure if it was a previous version, but you need to do some serious editing to your sample formulas. For example, simply pressing [F2] to edit and pressing [ENTER] doesn’t cut it. I added a leading apostrophe to make it a text label and then removed it and that worked. In some cases, I’ve copied formulas around. It seems like Google Shhet might have some caching.
Good to know that you were able to get it up and running.
Cheers!
This sheet has been super helpful for our experiments. Just want to flag that it looks like it may need some updates to support the just recently updated ChatGPT. It seems the API endpoint is slightly different for those models.
FYI the docs for that are here, including how to use ChatGPT for the completion use case: