OpenAI

The OpenAI AI connector enables you to connect the AI models served on the OpenAI Platform for the following tasks:

#Release Stage

Alpha

#Resource Configuration

The up-to-date configuration is maintained here.

FieldTypeNote
api_key*stringEnter your OpenAI API key. To find your keys, go to your OpenAI's Account page.

#No-code Setup

PREREQUISITES

To create a OpenAI AI connector, you'll first need to create a OpenAI account by visiting openai.com. Access to your API keys can then be managed through OpenAI's Account page.

To create a OpenAI AI connector:

  1. Go to the Resource page and click Add Resource
  2. Select OpenAI
  3. Fill in a unique ID for the resource. Optionally, give a short description in the Description field
  4. Fill in the required fields.
    • Fill API Key. Follow the OpenAI documentation to find your API key
    • Optionally, fill Orgnization ID that specify which organization is used for the requests. Usage will count against the specified organization's subscription quota.

#Low-code Setup

cURL(Instill-Cloud)
cURL(Instill-Core)
Copy

curl -X POST https://api.instill.tech/vdp/v1alpha/users/<user-id>/connectors \
--header 'Authorization: Bearer <Instill-Cloud-API-Token>' \
--data '{
"id": "my-openai",
"connector_definition_name": "connector-definitions/ai-openai",
"configuration": {
"api_key": "<open-ai-api-key>"
}
}'

For other operations, please refer to the VDP Protobufs.

#Connector Configuration

When using the OpenAI AI connector in your pipeline, certain fields of the input data need to be filled to trigger the pipeline effectively. Here are the expected input and output data fields for the OpenAI AI connector.

#Text Generation

If task is set to TASK_TEXT_GENERATION

InputTypeDescription
taskstringTASK_TEXT_GENERATION
promptstringText prompt
modelstringThe model that you want to use. eg., gpt-4 and gpt-3.5-turbo .
system_messagestringThe system message helps set the behavior of the assistant. For example, you can modify the personality of the assistant or provide specific instructions about how it should behave throughout the conversation. By default, the model's behavior is using a generic message as "You are a helpful assistant."
temperaturefloatThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
nintHow many chat completion choices to generate for each input message.
max_tokensintThe maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. Example Python code for counting tokens.
top_pfloatAn alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
presence_penaltyfloatNumber between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. See more information about frequency and presence penalties.
frequency_penaltyfloatNumber between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. See more information about frequency and presence penalties.
response_format.typestringSetting to json_object enables JSON mode.
OutputTypeDescription
textsarray[string]Generated text array

#Text Embeddings

InputTypeDescription
taskstringTASK_TEXT_EMBEDDINGS
textstringText to be converted to dense vector
modelstringThe model that you want to use. eg. text-embedding-ada-002
OutputTypeDescription
embeddingarray[float]A vector embeddings

#Speech Recognition

InputTypeDescription
taskstringTASK_SPEECH_RECOGNITION
modelstringThe model that you want to use, e.g., whisper-1.
audiostringBase64 encoded audio recording to transcribe
temperaturefloatThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
languagestringThe language of the input audio. Supplying the input language in ISO-639-1 format will improve accuracy and latency.
promptstringAn optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language.
OutputTypeDescription
textstringTranscribed text

#Text to Image

InputTypeDescription
taskstringTASK_TEXT_TO_IMAGE
modelstringID of the model to use
promptstringA text description of the desired image(s).
nfloatThe number of images to generate. Must be between 1 and 10. For dall-e-3, only n=1 is supported.
sizestringThe size of the generated images.
stylestringThe style of the generated images.
OutputTypeDescription
resultsarray[object]Generated images

#Example

Example input and output data for each task:

TASK_TEXT_GENERATION
TASK_TEXT_EMBEDDINGS
TASK_SPEECH_RECOGNITION
TASK_TEXT_TO_IMAGE
Copy

// Input
{
"task": "TASK_TEXT_GENERATION",
"model": "gpt-3.5-turbo",
"prompt": "Write me a story about London"
}
// Output
{
"texts": [
"Once upon a time, in the heart of England, there stood a vibrant city named London. It was a place of rich history, diverse culture, and endless possibilities. From its iconic landmarks to its bustling streets, the city had a unique charm that drew people from all walks of life..."
]
}

Last updated: 1/8/2024, 8:56:57 AM