Transform your presentations with ChatGPT API

Updated on Dec 26,2023

Transform your presentations with ChatGPT API

Table of Contents

  1. Introduction
  2. Integrating GPT API with Google Slides
  3. Demo
  4. Code Walkthrough
    • Defining API Key and GPT model
    • Creating a new menu item
    • Finding the active presentation and selected text
    • Creating the prompt
    • Composing the request body
    • Sending the request and getting the response
    • Inserting the generated text into a new text box
  5. Workflow Explanation
  6. Adding a New Menu Item
  7. Customizing the Code
  8. Conclusion

Introduction

In this tutorial, we will learn how to integrate the Charging GPT (GPT API) with Google Slides. By doing this, You will be able to generate AI-written content directly within your Google slide without leaving the platform. We have previously covered integrating GPT API with Google Docs and Google Spreadsheet, completing the trilogy.

Integrating GPT API with Google Slides

To integrate GPT API with Google Slides, you will need an OpenAI API token. The token is essential for authentication and authorization. If you don't have one, you can refer to the previous video in this series where we extensively covered obtaining the token.

Demo

Before diving into the code walkthrough, let's start with a quick demo to understand the process. In this demo, we will insert a new slide and generate AI-written content within it.

  1. Open Google Slides.
  2. Create a new slide.
  3. Type any text you want to use as a prompt. For example, "Data Science."
  4. Click on the "Charge GPT" menu item.
  5. Click on "Generate Prompt."
  6. Wait for the process to complete. It may take some time as the text is sent to OpenAI and then generated.
  7. Format the generated text if necessary.
  8. Move the new content down and delete the existing one.

By following these steps, you will have AI-generated content right within your Google slide.

Code Walkthrough

Now, let's move on to the code walkthrough to understand how the integration works. The JavaScript code for this integration can be found in my GitHub repository (link provided in the YouTube description).

Defining API Key and GPT Model

First, we need to define the OpenAI API Key and the Charging GPT model.

Creating a New Menu Item

To make the integration accessible within Google Slides, we will create a new menu item called "Chat GPT." This menu item will contain a sub-item called "Generate Prompt."

Finding the Active Presentation and Selected Text

To determine on which topic you want to generate AI-written content, we need to find the active presentation and the selected text. The selected text will be the input for the content generation.

Creating the Prompt

Next, we create a prompt Based on the selected text. The prompt consists of generating three points on the selected text. For example, if the selected text is "Elon Musk," the prompt will be "Generate three points on Elon Musk."

Composing the Request Body

To communicate with the GPT API, we need to Compose the request body. It includes the model, messages, temperature, and max tokens. The prompt we generated earlier becomes part of the messages.

Sending the Request and Getting the Response

Once we have the request body, we send the request to the Chat GPT API and retrieve the response. The response contains the generated content in the choices -> message -> content format.

Inserting the Generated Text into a New Text Box

Finally, we insert the generated text into a new text box within the slide. This allows us to easily Visualize and manipulate the AI-written content.

Workflow Explanation

Let's summarize the workflow of integrating GPT API with Google Slides:

  1. Insert a new slide.
  2. Type the desired prompt in the slide.
  3. Generate the AI-written content by clicking on the "Charge GPT" menu item and selecting "Generate Prompt."
  4. Format and adjust the generated content as needed.
  5. Delete the existing content and move the new content to the desired position.

This simple workflow allows you to seamlessly create AI-generated content within your Google slide presentations.

Adding a New Menu Item

If you want to customize the integration further, you can add a new menu item. To do this, follow these steps:

  1. Edit line 8 of the code to create a new menu item name.
  2. Link the new menu item with a corresponding function in the code.
  3. Save and run the project in Google Apps Script.
  4. Return to your presentation and click on the new menu item.
  5. Follow the same process as before to generate AI-written content based on the new prompt.

By adding new menu items, you can extend the functionality of the integration to suit your specific needs.

Customizing the Code

To customize the code, modify the prompt generation process to generate AI-written content based on your desired criteria. You can also experiment with different options such as inserting shapes instead of text boxes. The code provides flexibility for customization and can be enhanced based on your requirements.

Conclusion

Congratulations! You have successfully integrated Charging GPT with Google Slides, allowing you to generate AI-written content directly within your presentations. We have covered the code walkthrough, demonstrated the workflow, and discussed customization options. Feel free to explore and adapt the code to suit your needs. If you have any questions or need further assistance, please leave a comment below.

Most people like