Google Spreadsheet + GPT3

Thanks Nelson. As far as I can tell, this now seems to be working for me!

I’ve noticed that the Search function only returns the entire text of the cell with the highest cosine similarity. Is there any way to make it so that the Search returns information from more than one cell (and not irrelevant information)?

I’m not much of a programmer so it is all a bit new to me. ChatGPT tells me I might consider using Named Entity Recognition based on spaCy, but wondering if you have any obvious workarounds.

What I am ultimately hoping to achieve is to fill the Sheets with my worldbuilding information then feed in relevant information into new prompts dynamically. Also, to have a summary cell for each category (e.g. a place) that I occasionally update using the Search function.

1 Like

Hi @songsofthespheres

I’m glad that you find it useful. As you mentioned, the search function was designed to only give you the result with the highest score. May I ask why the result with the highest score is giving you irrelevant information? I think we need to look into why that is happening, otherwise give you more results back might not help.

1 Like

Hi Nelson.

To give an example if cell one is ‘Alice is red’ and cell two is ‘Alice is tall’, when I ask ‘Describe Alex’ I get one or the other of those descriptors (red or tall) but never both. This is probably not a use that you intended the sheet to cover.

The reason Alice might be variously described in my use is because things in my world might be related. For example, a city may be mentioned in the context of more than one entry relating to a faction.

It may be that the solution is not in the code as such but in how I organise the data.

1 Like

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.

1 Like

Hi @songsofthespheres1

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.

1 Like

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.
ScreenHunter 3783

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 = “”;
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

  1. Using this latest version of the sheet
    GPT3-On-Custom-Data - Google Sheets
  2. Using the api key without the Bearer keyword, meaning that it should only contain the value sk-xxxxxxxxxx