Call ChatGPT REST API in SSIS

Introduction

OpenAI, the creators of ChatGPT, provide both a web interface and an API for seamless integration of their tools into applications. This article provides a comprehensive guide on how to establish a connection with the OpenAI API in SSIS using ZappySys JSON Source, enabling seamless data integration and retrieval.

Prerequisites

Before we perform steps listed in this article, you will need to make sure following prerequisites are met:

  1. SSIS designer installed. Sometimes it is referred as BIDS or SSDT (download it from Microsoft site).
  2. Basic knowledge of SSIS package development using Microsoft SQL Server Integration Services.
  3. Make sure ZappySys SSIS PowerPack is installed (download it).
  4. Optional (If you want to Deploy and Schedule ) – Deploy and Schedule SSIS Packages

Step-by-step guide to making a ChatGPT Rest API call

How to get an OpenAI API Key for ChatGPT

First, obtain your API key from OpenAI. This key is required for authenticating your requests.

To access the services, you will be required to set up an account with OpenAI. Click here to create your account. Once your account has been successfully created, proceed to log in to your OpenAI account.

You can find the API key by following these steps:

  1. Navigate to the top right corner of the screen.
  2. Click on your account name.
  3. From the drop-down menu, select “API Keys.”
  4. Alternatively, you can directly access the API Keys section by clicking here.

To generate a new secret key, please follow these steps:

  1. Go to the API Keys page.
  2. Look for the “Create new secret key” button.
  3. Click the button to generate a new secret key.

Generate a new key

Upon generation, your API key will be visible on the screen. It’s crucial to copy the key and store it in a secure location immediately, as it will not be displayed again for security purposes.

The new key

Now that you have your API key, you can begin utilizing it to make calls with your components. A preliminary example involves retrieving a list of all available models in OpenAI. For detailed instructions, please refer to the API documentation available here.

ChatGPT Rest API call using JSON Source

1. Drag and Drop the SSIS Data Flow Task from the SSIS Toolbox.

Drag and drop Data flow task

2. Double-click on the DataFlow task to see the DataFlow designer surface.

3. From the SSIS toolbox drag and drop ZS JSON Source on the dataflow designer surface.

Drag and drop a JSON source

4. We will use this on the URL path:

5. In the HTTP headers grid add the following values by clicking Raw Edit button :

Authorization: Bearer YOUR_OPENAI_API_KEY
OpenAI-Organization: org-YQ9qpxxxxxxxxxxxxgoPi

6. Select your preferred Array Filter, simply click the “Select Filter” button. for this API call we need to select the $.data[*]  array filter

7. Final step: Click ‘Preview’ to initiate the ChatGTP Rest API call. You will also find a demonstration within our component, along with the resulting output from the call, below.

ChatGPT call

That’s it the configuration for the ChatGPT Rest API call has been completed successfully.

Load ChatGPT data in SQL Server using Upsert Destination (Insert or Update)

ZappySys SSIS PowerPack makes it easy to load data from various sources such as REST, SOAP, JSON, XML, CSV or from other source into SQL Server, or PostgreSQL, or Amazon Redshift, or other targets. The Upsert Destination component allows you to automatically insert new records and update existing ones based on key columns. Below are the detailed steps to configure it.

Step 1: Add Upsert Destination to Data Flow

  1. Drag and drop the Upsert Destination component from the SSIS Toolbox.
  2. Connect your source component (e.g., JSON / REST / Other Source) to the Upsert Destination.

SSIS - Data Flow - Drang and Drop Upsert Destination Component

Step 2: Configure Target Connection

  1. Double-click the Upsert Destination component to open the configuration window.
  2. Under Connection, select an existing target connection or click NEW to create a new connection.
    • Example: SQL Server, or PostgreSQL, or Amazon Redshift.

Step 3: Select or Create Target Table

  1. In the Target Table dropdown, select the table where you want to load data.
  2. Optionally, click NEW to create a new table based on the source columns.

Configure SSIS Upsert Destination Connection - Loading data (REST / SOAP / JSON / XML /CSV) into SQL Server or other target using SSIS

Step 4: Map Columns

  1. Go to the Mappings tab.
  2. Click Auto Map to map source columns to target columns by name.
  3. Ensure you check the Primary key column(s) that will determine whether a record is inserted or updated.
  4. You can manually adjust the mappings if necessary.

SSIS Upsert Destination - Columns Mappings

Step 5: Save Settings

  • Click OK to save the Upsert Destination configuration.

Step 6: Optional: Add Logging or Analysis

  • You may add extra destination components to log the number of inserted vs. updated records for monitoring or auditing purposes.

Step 7: Execute the Package

  • Run your SSIS package and verify that the data is correctly inserted and updated in the target table.

SSIS Upsert Destination Execution

Conclusion

In this article, we explored the seamless process of establishing a connection with ChatGPT in SSIS and integrating data effortlessly, all without the need for coding. Interested in trying it out yourself? Feel free to Download ZappySys SSIS PowerPack by clicking here and experience the simplicity firsthand. Should you have any lingering queries, please don’t hesitate to ask by clicking here or initiating a conversation with our experts via the live chat icon at the bottom-right corner of this page.

Posted in JSON File / REST API Driver, REST API, Uncategorized and tagged , , .