Integrate Google Sheets with Chat GPT to Generate CRM Contact Bios

 
Editorial Note: We earn a commission from partner links on our site. Commissions do not affect our editors’ opinions or evaluations.

In this blog post, I’ll show you how to generate short bios for your CRM contacts using Google Sheets and the GPT-3.5 Turbo language model. 

I made a script that allows you to paste CRM data into a Google Sheet, and my script will be able to read the column headers and the corresponding data for each contact. It doesn’t matter how many data columns you have in your data, or the order that the columns are in!

Follow along to get this implemented in your own Google sheet.

Step 1: Create a New Google Sheet

Go to https://docs.google.com/spreadsheets, create a blank sheet and give it a name.

Add the label Bios to cell A1, and paste your CRM data into cell B1, including the headers. Don’t worry if your column headers are different than mine – the script can handle it. 

This script is meant to handle numerous data points for each contact. If you only give the name and the email, don’t expect stellar bios.

Column A will be where we generate the bios with the script, so we’ll leave it blank for now.

You can use the mock data I used for my demo with this link.

Step 2: Open the Script Editor

Go to “Extensions” in the top menu bar and select “Apps Script.”

 

This opens up the Script Editor to an untitled project with a blank function inside. 

Rename your project and delete the blank function

Step 3: Paste My Script

Copy the script below and paste it into the editor. Make sure to replace YOUR_API_KEY with your own GPT-3 API key.


function generateBioForRow() {
  // Access the active spreadsheet and active cell
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const activeCell = SpreadsheetApp.getActiveRange();
  const rowNum = activeCell.getRow();

  // Get the headers (column names) and the number of columns
  const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
  const numColumns = headers.length;

  // Construct the GPT-3 prompt dynamically using all the column headers and values
  let prompt = "I will provide you with CRM data on a person. I want you to write a short bio about them using this data. Only include information that is from the data (don't make anything up). Keep your response under 70 tokens.:\n";
  for (let col = 0; col < numColumns; col++) {
    const header = headers[col];
    const value = sheet.getRange(rowNum, col + 1).getValue();
    prompt += `${header}: ${value}\n`;
  }

  // Define the API key, model, and other parameters for the GPT-3 API call
  const API_KEY = "YOUR_API_KEY";
  const model = "gpt-3.5-turbo";
  const temperature = 0.2; // Set to a lower value for more deterministic responses
  const maxTokens = 100; // Set max_tokens a little higher than what you said in your prompt to give it a little room

  // Set up the request body with the given parameters
  const requestBody = {
    "model": model,
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": prompt },
    ],
    "temperature": temperature,
    "max_tokens": maxTokens
  };

  // Set up the request options with the required headers
  const requestOptions = {
    "method": "POST",
    "headers": {
      "Content-Type": "application/json",
      "Authorization": "Bearer " + API_KEY
    },
    "payload": JSON.stringify(requestBody)
  };

  // Send the request to the GPT-3 API endpoint for completions
  const response = UrlFetchApp.fetch("https://api.openai.com/v1/chat/completions", requestOptions);

  // Get the response body as a JSON object
  const responseBody = JSON.parse(response.getContentText());

  // Extract the generated text from the response
  const bio = responseBody.choices[0]["message"]["content"];

  // Return the generated bio
  return bio;
}
				
					function generateBioForRow() {
  // Access the active spreadsheet and active cell
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const activeCell = SpreadsheetApp.getActiveRange();
  const rowNum = activeCell.getRow();

  // Get the headers (column names) and the number of columns
  const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
  const numColumns = headers.length;

  // Construct the GPT-3 prompt dynamically using all the column headers and values
  let prompt = "I will provide you with CRM data on a person. I want you to write a short bio about them using this data. Only include information that is from the data (don't make anything up). Keep your response under 70 tokens.:\n";
  for (let col = 0; col < numColumns; col++) {
    const header = headers[col];
    const value = sheet.getRange(rowNum, col + 1).getValue();
    prompt += `${header}: ${value}\n`;
  }

  // Define the API key, model, and other parameters for the GPT-3 API call
  const API_KEY = "YOUR_API_KEY";
  const model = "gpt-3.5-turbo";
  const temperature = 0.2; // Set to a lower value for more deterministic responses
  const maxTokens = 100; // Set max_tokens a little higher than what you said in your prompt to give it a little room

  // Set up the request body with the given parameters
  const requestBody = {
    "model": model,
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": prompt },
    ],
    "temperature": temperature,
    "max_tokens": maxTokens
  };

  // Set up the request options with the required headers
  const requestOptions = {
    "method": "POST",
    "headers": {
      "Content-Type": "application/json",
      "Authorization": "Bearer " + API_KEY
    },
    "payload": JSON.stringify(requestBody)
  };

  // Send the request to the GPT-3 API endpoint for completions
  const response = UrlFetchApp.fetch("https://api.openai.com/v1/chat/completions", requestOptions);

  // Get the response body as a JSON object
  const responseBody = JSON.parse(response.getContentText());

  // Extract the generated text from the response
  const bio = responseBody.choices[0]["message"]["content"];

  // Return the generated bio
  return bio;
}

				
			

Step 4: Save and Run the Script

Save the script by clicking “Save Project” in the Script Editor.

 

Now go back to your Google Sheet. 

Click into cell A2 and run this function: =generateBioForRow(). 

The script will generate a short bio based on the CRM data in the selected row and return the bio text.

I recommend wrapping the text so that you can see the bio in the cell. To do that click the text wrappng menu button >> the click the wrap icon, as seen in the below image.

Here’s the bio wrapped:

(this is fake/demo data)

You can copy and paste the generateBioForRow() formula down for all of your rows to generate bios for all of the contacts. Obviously, be cognizant of Open AI’s data limits.

Step 5: Explore and Experiment

Try running the script with different CRM data to see how the generated bios vary. Feel free to customize the script and experiment with different GPT-3 parameters. Practice integrating with Zapier, or publish your own web app using Google Sheets.

Conclusion

You now know how to generate short bios for your CRM contacts using Google Sheets and GPT-3. Whether you’re managing a sales team, maintaining a client database, or running a marketing campaign, this script is valuable for generating personalized and engaging content. Enjoy, and don’t forget to subscribe below to receive industry-leading content before publication.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Get updates and learn from the best

Share This Post

More To Explore