OpenAI API

OpenAI API


Author: Jerry Chae

Overview

OpenAI API integrates some of the key features of the comprehensive API that is provided by OpenAI https://openai.com/

The functions included in this plugin are

1.   Chat

2.   Generate Image

3.   Speech-to-text

4.   Obtain the updated list of OpenAI models

5.   Obtain information about the models

This plugin is extremely useful when users would like to

·        build an end-to-end process automation software that include the chatGPT solution

·        build it with minimum investment of time and money

·        distribute the software within the organization while maintaining “governance”



Need help?

Technical contact to tech@argos-labs.com


May you search all operations,



How to obtain OpenAI API credentials

Go to https://openai.com/

Org ID https://platform.openai.com/account/org-settings

API Key  https://platform.openai.com/account/api-keys


FYI – below is what you would receive from chatGPT, if you ask, “show me how to use OpenAI API?” As you see this is all written for software developers (from #2 down) and is not easy to understand for non-programmers. For the Low-code Python users, you just need to do #1 and obtain API credentials from the OpenAI website and you are ready to use the popular feature of the OpenAI solution!


Prompt:

How do I use OpenAI API?


Answer:

To use the ChatGPT API, you'll need to make HTTP requests to the API endpoint. Here's a step-by-step guide on how to use the ChatGPT API:

  1. Obtain an API key: Visit the OpenAI website (openai.com) and navigate to the API section. Follow the instructions to sign up for an API key if you haven't already
  2. Set up your API environment: You can use any programming language that can make HTTP requests. Make sure you have the necessary libraries or tools to send HTTP requests. Popular choices include Python with libraries like `requests` or `curl` command-line tool.
  3. Make a POST request: Construct an HTTP POST request to the API endpoint `https://api.openai.com/v1/chat/completions`.
  4. Set the headers: Include the following headers in your request:

       - `'Content-Type': 'application/json'`
    
       - `'Authorization': 'Bearer YOUR_API_KEY'` (Replace `YOUR_API_KEY` with the actual API key you obtained earlier)


  5. Define the payload: In the body of your request, pass a JSON object with the following parameters:

     - `'model': 'gpt-3.5-turbo'` (specifies the model to use)
    
       - `'messages'`: an array of message objects containing the conversation history. Each message object should have a `'role'` (either "system", "user", or "assistant") and a `'content'` (the content of the message).
    
    Here's an example of a payload JSON object:
    
    ```json
    
    {
    
      'model': 'gpt-3.5-turbo',
    
      'messages': [
    
        {'role': 'system', 'content': 'You are a helpful assistant.'},
    
        {'role': 'user', 'content': 'Who won the world series in 2020?'},
    
        {'role': 'assistant', 'content': 'The Los Angeles Dodgers won the World Series in 2020.'}
    
      ]
    
    }
    
    ```


  6. Send the request: Send the POST request to the API endpoint with the headers and payload you defined.
  7. Handle the response: The API will respond with a JSON object containing the assistant's reply. Extract the response from the JSON and use it in your application.

Please note that usage of the OpenAI API may involve costs, so make sure to review the pricing and terms on the OpenAI website.

It's important to refer to the official OpenAI API documentation for more detailed information, including any updates or changes since my knowledge cutoff date.



Sample Bot

OpenAI API sample bot is available from here

 

Now how to set up the plugin parameters

 

Function: Chat (with Prompt)

Required input

  • Org ID
  • API Key
  • Choose function = Chat

Advanced input (required)

  • Model name (gpt-3.5-turbo for free account and gpt-4 for paid account)
  • Prompt (your question – it is required to be in one line)

Advanced input (optional)

  • Is Text Out – unchecked will receive JSON output, checked will give TXT output


Return Value

                  API returns the answer to your question (prompt) (String, CSV, or File)

Return Code

  • 0 - Success
  • 1 - Invalid Argument – such as no API key found
  • 2 - Invalid file – no prompt, incorrect reference file
  • 99 - Everything else


Function: Chat (with YAML file)

Required input

  • Org ID
  • API Key
  • Choose function = Chat

Advanced input (required)

  • Model name (gpt-3.5-turbo for free account and gpt-4 for paid account)
  • YAML file with a format which is explained here
    • Example: YAML should look like this –

      - role: system
      
        content: You are a helpful assistant.
      
      - role: user
      
        content: Who won the world series in 2020?
      
      - role: assistant
      
        content: The Los Angeles Dodgers won the World Series in 2020.

Advanced input (optional)

  • Is Text Out – this will output only the text part of the API response.


Return Value

                  API returns the answer to your question (prompt) (String, CSV, or File)

Return Code

  • 0 - Success
  • 1 - Invalid Argument – such as no API key found
  • 2 - Invalid file – no prompt, incorrect reference file
  • 99 - Everything else

Function: Chat (with Reference Text File)

Required input

  • Org ID
  • API Key
  • Choose function = Chat

Advanced input (required)

  • Model name (gpt-3.5-turbo for free account and gpt-4 for paid account)
  • Reference Text File without any specific format
  • Prompt – your question about the Reference File

Advanced input (optional)

  • Is Text Out – this will output only the text part of the API response.


Return Value

                  API returns the answer to your question (prompt) (String, CSV, or File)

Return Code

  • 0 - Success
  • 1 - Invalid Argument – such as no API key found
  • 2 - Invalid file – no prompt, incorrect reference file
  • 99 - Everything else

Function: Gen Image (generate image)

Required input

  • Org ID
  • API Key
  • Choose function = Gen Images

Advanced input (required)

  • Prompt – your request for the image to be generated by OpenAI
  • Num Images – number of images you request OpenAI to generate – in integer
  • Img Size – size of the images of your request – choose from the pull-down menu
  • Img prefix – the output image files will contain this prefix in their file names

Advanced input (optional)

  • None


Return Value

                  API returns the file names of your image files (String, CSV, or File)

Return Code

  • 0 - Success
  • 1 - Invalid Argument – such as no API key found
  • 2 - Invalid file – no prompt, incorrect reference file
  • 99 - Everything else



Function: Speech-To-Text (STT)

Required input

  • Org ID
  • API Key
  • Choose function = Speech to Text

Advanced input (required)

  • Voice file – audio file in format of WAV and mp3

Advanced input (optional)

  • Is Text Out – unchecked will give JSON, checked will output TXT


Return Value

                  API returns the file names of your image files (String, CSV, or File)

Return Code

  • 0 - Success
  • 1 - Invalid Argument – such as no API key found
  • 2 - Invalid file – no prompt, incorrect reference file
  • 99 - Everything else



Function: List Models

This function simply returns the latest list of OpenAI’s active models

Required input

  • Org ID
  • API Key
  • Choose function = List Model

Advanced input (required)

  • None

Advanced input (optional)

  • None


Return Value

                  API returns the list of OpenAI models (String, CSV, or File)

Return Code

  • 0 - Success
  • 1 - Invalid Argument – such as no API key found
  • 2 - Invalid file – no prompt, incorrect reference file
  • 99 - Everything else



Function: Model Info

This function simply returns information about a specific model

Required input

  • Org ID
  • API Key
  • Choose function = List Model

Advanced input (required)

  • Model Name

Advanced input (optional)

  • None


Return Value

                  API returns the information of the model (model name) (String, CSV, or File)

Return Code

  • 0 - Success
  • 1 - Invalid Argument – such as no API key found
  • 2 - Invalid file – no prompt, incorrect reference file
  • 99 - Everything else







All Plugins