How to Create an Automation System Using Google Sheets and GPT-3 for User Input and Output?

This topic was automatically generated from Slack. You can find the original thread here.

Hey, I’m trying to build a small Automation.

I have a Google Sheets table with two columns. On the left should be the input and on the right the output.

I want the user to enter a sentence at a2, then there is an automation with gpt-3 and at b2 the output should come.

If the user writes something at a4, should be at b4 the output.

The trigger should start automatically.

To create an automation that uses Google Sheets and GPT-3, you’ll need to follow these steps: 1. Set up a Google Sheets trigger in Pipedream to listen for changes in the specific cells (A2, A4, etc.). 2. Use the OpenAI GPT-3 action to generate the output based on the input from the Google Sheets trigger. 3. Update the Google Sheets with the GPT-3 output in the corresponding cells (B2, B4, etc.). Here’s an example Pipedream component to get you started: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, openai: { type: “app”, app: “openai”, }, sheetId: { type: “string”, label: “Google Sheet ID”, }, }, async run({ steps, $ }) { // Get the input from Google Sheets const inputResponse = await axios($, { url: https://sheets.googleapis.com/v4/spreadsheets/${this.sheetId}/values/A2:A4, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, }, }); // Process the input using GPT-3 const inputText = inputResponse.data.values; const gpt3Response = await this.openai.gpt3.generate_text({ prompt: inputText, max_tokens: 50, }); // Update the Google Sheets with the GPT-3 output const outputData = { range: “B2:B4”, values: [[gpt3Response.choices[0].text]], }; await axios($, { method: “PUT”, url: https://sheets.googleapis.com/v4/spreadsheets/${this.sheetId}/values/B2:B4, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, params: { valueInputOption: “RAW”, }, data: { range: “B2:B4”, values: outputData.values, }, }); return { message: “Google Sheet updated with GPT-3 output” }; }, });

but i don’t want it in specific cells but everywhere.

I understand that you want the automation to work for any cell in the Google Sheet, not just specific cells. In that case, you can modify the Pipedream component to listen for changes in the entire sheet and update the corresponding output cells accordingly. Here’s an example component to get you started: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google: { type: “app”, app: “google”, }, openai: { type: “app”, app: “openai”, }, sheetId: { type: “string”, label: “Google Sheet ID”, }, }, async run({ steps, $ }) { // Get the input from Google Sheets const inputResponse = await axios($, { url: https://sheets.googleapis.com/v4/spreadsheets/${this.sheetId}/values/A:A, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, }, }); const inputValues = inputResponse.data.values; const outputValues = []; for (const inputValue of inputValues) { if (inputValue) { const gpt3Response = await this.openai.gpt3.generate_text({ prompt: inputValue, max_tokens: 50, }); outputValues.push([gpt3Response.choices[0].text]); } else { outputValues.push([“”]); } } // Update the Google Sheets with the GPT-3 output await axios($, { method: “PUT”, url: https://sheets.googleapis.com/v4/spreadsheets/${this.sheetId}/values/B:B, headers: { Authorization: Bearer ${this.google.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, params: { valueInputOption: “RAW”, }, data: { range: “B:B”, values: outputValues, }, }); return { message: “Google Sheet updated with GPT-3 output” }; }, });

i am new. how do i start now with this code?

i am new. how do i start now with this code?

I understand that you’re new to Pipedream and want to get started with the provided code. Here’s a step-by-step guide to help you: 1. Sign in to your Pipedream account. 2. Click on “New” in the top right corner and select “New Workflow”. 3. In the new workflow, click the “+” button to add a new step. 4. Choose “Run Node.js code” to add a code step. 5. Copy the provided code and paste it into the code editor. 6. Customize the props values in the code, if necessary, to match your use case. 7. Click “Deploy” to save and deploy the workflow. Now, whenever the workflow is triggered, it will execute the code you’ve added. If you need further assistance or have any questions, feel free to ask.

can i do this without a code?

can i do this without a code?

Yes, you can achieve automation without writing code by using Pipedream’s pre-built actions and triggers. Pipedream offers a wide range of app integrations, triggers, and actions that you can use directly from the UI to create your workflows. To get started, you can search for the app and the specific component you need within the Pipedream UI. If you’re looking for a specific app integration that doesn’t exist yet, you can submit a new integration request at New Pipedream Integration Request.

How can i do this whisout code? I understand that you want the automation to work for any cell in the Google Sheet, not just specific cells. In that case, you can modify the Pipedream component to listen for changes in the entire sheet and update the corresponding output cells accordingly. Here’s an example component to get you started:

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    google: {
      type: "app",
      app: "google",
    },
    openai: {
      type: "app",
      app: "openai",
    },
    sheetId: {
      type: "string",
      label: "Google Sheet ID",
    },
  },
  async run({ steps, $ }) {
    // Get the input from Google Sheets
    const inputResponse = await axios($, {
      url: `https://sheets.googleapis.com/v4/spreadsheets/${this.sheetId}/values/A:A`,
      headers: {
        Authorization: `Bearer ${this.google.$auth.oauth_access_token}`,
      },
    });

    const inputValues = inputResponse.data.values;
    const outputValues = [];

    for (const inputValue of inputValues) {
      if (inputValue) {
        const gpt3Response = await this.openai.gpt3.generate_text({
          prompt: inputValue,
          max_tokens: 50,
        });

        outputValues.push([gpt3Response.choices[0].text]);
      } else {
        outputValues.push([""]);
      }
    }

    // Update the Google Sheets with the GPT-3 output
    await axios($, {
      method: "PUT",
      url: `https://sheets.googleapis.com/v4/spreadsheets/${this.sheetId}/values/B:B`,
      headers: {
        Authorization: `Bearer ${this.google.$auth.oauth_access_token}`,
        "Content-Type": "application/json",
      },
      params: {
        valueInputOption: "RAW",
      },
      data: {
        range: "B:B",
        values: outputValues,
      },
    });

    return { message: "Google Sheet updated with GPT-3 output" };
  },
});

This component will listen for changes in column A and update the corresponding cells in column B with the GPT-3 output. Note that this example assumes you have the OpenAI app set up in Pipedream.

If you’d like to automate a process without writing code, you can use Pipedream’s pre-built triggers and actions. Pipedream offers a wide range of app integrations, triggers, and actions that you can use directly from the UI to create your workflows. To get started: 1. Search for the app you want to use in the Pipedream UI. 2. Look for the specific trigger or action you need within the app components. 3. Add the trigger or action to your workflow and configure the required fields. For example, if you’re working with Google Sheets and OpenAI, search for those apps in the Pipedream UI and use the available triggers and actions to create your workflow. If you can’t find a specific app integration, you can submit a new integration request at New Pipedream Integration Request.