OpenAI Chat Completions

Overview

You can use this Snap to generate chat completions using the specified model and model parameters.


OpenAI Chat Completions Overview

Prerequisites

None.

Limitations

  • gpt-4 and gpt-4-0613 models do not support JSON Mode. Any model released after and including gpt-4-1106-preview supports JSON Mode. Learn more.

Known Issues

None.

Snap Views

View Description Examples of Upstream and Downstream Snaps
Input This Snap supports a maximum of one binary or document input view. When the input type is a document, you must provide a field to specify the path to the input prompt. The Snap requires a prompt, which can be generated either by the OpenAI Prompt Generator or any user-desired prompt intended for submission to the chat completions LLM API. Mapper
Output This Snap has at the most one document output view. The Snap provides the result generated by the OpenAI LLMs. Mapper
Error

Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the pipeline by choosing one of the following options from the When errors occur list under the Views tab. The available options are:

  • Stop Pipeline Execution Stops the current pipeline execution when the Snap encounters an error.
  • Discard Error Data and Continue Ignores the error, discards that record, and continues with the remaining records.
  • Route Error Data to Error View Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.

Snap Settings

Note:
  • Suggestion icon (): Indicates a list that is dynamically populated based on the configuration.
  • Expression icon (): Indicates whether the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.
  • Add icon (): Indicates that you can add fields in the field set.
  • Remove icon (): Indicates that you can remove fields from the field set.
Field / Field set Type Description
Label String

Required. Specify a unique name for the Snap. Modify this to be more appropriate, especially if more than one of the same Snaps is in the pipeline.

Default value: OpenAI Chat Completions

Example: Create customer support chatbots
Model name String/Expression

Required. Specify the model name to use for the chat completion. Learn more about the list of models from OpenAI that are compatible with the completions API.

Default value: N/A

Example: gpt-4
Prompt String/Expression

Appears when you select Document as the Input type.

Required. Specify the prompt to send to the chat completions endpoint as the user message.

Default value: N/A

Example: $msg
Model parameters Configure the parameters to tune the model runtime.
Maximum tokens Integer/Expression

Specify the maximum number of tokens to generate in the chat completion. If left blank, the default value of the endpoint is used.

Default value: N/A

Example: 50

Temperature Number/Expression

Specify the sampling temperature to use a decimal value between 0 and 1. If left blank, the default value of the endpoint is used.

Default value: N/A

Example: 0.2

Top P Number/Expression

Specify the nucleus sampling value, a decimal value between 0 and 1. If left blank, the default value of the endpoint is used.

Default value: N/A

Example: 0.2

Response count Integer/Expression

Specify the number of responses to generate for each input, where 'n' is a model parameter. If left blank, the default value of the endpoint is used.

Default value: N/A

Example: 2

Advanced prompt configuration Configure the prompt settings to guide the model responses and optimize output processing.
System prompt String/Expression
Specify the persona for the model to adopt in the responses. This initial instruction guides the LLM's responses and actions.
Note:
  • If you leave this field blank, null, or an empty string, the Snap processes the request without using any system prompt.
  • When you use the gpt-3.5-turbo-0301 model, system messages might not be followed as precisely as intended.

Default value: N/A

Example:
  • "You are a helpful assistant."
  • "You are an experienced software developer."
  • "You are a customer service representative for a tech company."
JSON mode Checkbox/Expression
Select this checkbox to enable the model to generate strings that can be parsed into valid JSON objects. The output includes the json_output field that contains the parsed JSON object, encapsulating the data.
Note:
  • This field does not support input values from the upstream Snap.
  • When you select this checkbox, ensure the word JSON is included in the prompt, either in the Prompt field or the System prompt field. Otherwise, the Snap results in an error. Learn more.
    OpenAI Chat Completions Prompt field with JSON enabled

Default status: Deselected

Snap execution Dropdown list
Select one of the three modes in which the Snap executes. Available options are:
  • Validate & Execute. Performs limited execution of the Snap and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.
  • Execute only. Performs full execution of the Snap during pipeline execution without generating preview data.
  • Disabled. Disables the Snap and all Snaps that are downstream from it.

Default value: Validate & Execute

Example: Execute only

Troubleshooting

Failure: Request encountered an error while connecting to OpenAI, status code 400

The input model do not support JSON Mode. gpt-4, gpt-4-0613, and gpt-4-0314 models do not support JSON Mode.

Provide a valid model to proceed. Any model released after gpt-4-1106-preview supports JSON Mode. Learn more.

Examples