在Slack上如何使用GPT3?| 无代码创建!
Table of Contents
- Introduction
- Getting API Key
- Accessing Open AI Website
- Registering and Logging In
- Obtaining Open AI API Key
- Testing the API Call
- Using SyncTree to Call GPT
- Cleaning the Response Data
- Creating Slack Incoming Webhook
- Creating Slack Slash Command
- Implementing Slack Block Kit
- Creating Click Event
- Conclusion
Introduction
In this article, we will discuss how to obtain an API key for using GPT and how to make API calls using Open AI and SyncTree. We will also explore various features provided by Open AI, such as creating a chatbot using GPT. Additionally, we will learn how to use SyncTree to receive and clean the response data. Finally, we will cover how to integrate GPT with Slack by creating an incoming webhook, a slash command, and implementing Slack Block Kit.
Getting API Key
To get started with GPT, we first need to obtain an API key. Here are the steps to follow:
- Search for "Open AI" and access their website.
- Click on the API tab at the top since we will be making API calls.
- If You don't have an Open AI account, sign up. Otherwise, proceed with logging in.
- After logging in, you will see a "Welcome to Open AI" window. From here, we can explore the APIs.
- Go to the "Explore Examples" tab on the left and select the "Cherry" API since we want to Create a GPT chatbot.
- In the API request, you will find the Open AI API key on the fourth line. We need to obtain this API key.
Accessing Open AI Website
To access the Open AI Website and obtain the API key, follow these steps:
- Click on the account icon in the top right corner.
- Click on "API Keys" in the drop-down menu.
- If you already have an API key, you can use it. Otherwise, click on the "Create New Secret Key" button.
- Open AI will automatically generate a new API key for you. Make sure to copy and store it as you won't be able to see it again.
Using SyncTree to Call GPT
Once we have obtained the API key, we can use SyncTree to make API calls to GPT. Here's how:
- Search for "SyncTree" in the search bar and access their website.
- Click on the "Get Started" button in the top left corner.
- If you already have an account, log in. Otherwise, sign up and proceed with logging in.
- SyncTree provides an infrastructure environment to start developing immediately. Click on the "Create App" button on the top right.
- Inside the GPT app, we can add Biz Units to create a development environment.
- In the Biz Units section, add a GPT Biz Unit by filling in the required fields.
- Once the Biz Unit is added, click on the Blue "Add" button to create the environment with the revision name specified earlier. Development can now begin.
- In the Biz Unit, you can use various blocks provided by SyncTree. Our goal is to call GPT from SyncTree and receive the response.
- To make an external API call, use the Transfer block. Drag and drop the block into the Statements section.
- Copy and paste the URL you obtained from Open AI into the Endpoint URL field.
- Add the necessary request headers in the headers section. For the key, use "Authorization" and for the value, enter the API key obtained earlier.
- In the body section, add the desired prompt to communicate with GPT.
- Save the changes and test the call using the testing feature.
- By entering a question in the prompt, you should receive the answer in the response value.
Cleaning the Response Data
Since the response from GPT contains a large amount of data, we need to clean it and extract only the necessary parts. Follow these steps to extract the desired response:
- Create a new variable to store the response data.
- Use the Fetch block to fetch the response body from the external API call.
- Extract the necessary text by using the JSON Decode block and accessing the desired fields.
- Store the extracted text in a variable for further use.
Creating Slack Incoming Webhook
To integrate GPT with Slack and send messages, we need to create an incoming webhook. Follow these steps to create the webhook:
- Access the Slack API page.
- Click on the "Apps" tab in the top right corner.
- Create a new app and name it according to your preference.
- Enable the "Incoming Webhooks" feature.
- Add a new webhook to your workspace.
- Copy the webhook URL for future use.
Creating Slack Slash Command
To implement a slash command in Slack, follow these steps:
- Access the Slack API page.
- Go to your GPT app and click on the "Slash Commands" tab in the left sidebar.
- Create a new command by specifying the command name and providing the URL of the API that will be called.
- Save the command and install it in your workspace.
Implementing Slack Block Kit
To use Slack Block Kit and display messages in a desired format, follow these steps:
- Access the Slack Block Kit Builder page.
- Copy the desired JSON data or create your own JSON structure.
- Import the JSON data into your Slack bot business via the import button.
- Use the imported block in your workflow to send messages in Slack.
Conclusion
In this article, we have discussed how to obtain an API key for GPT and make API calls using Open AI and SyncTree. We have also learned how to integrate GPT with Slack by creating an incoming webhook, a slash command, and implementing Slack Block Kit. By following these steps, you can easily create a GPT chatbot and receive responses in Slack.