Skip to content

Create Chat or Text Completion (OpenAI) v1.0.0 Help

Creates a completion for a chat or single message.

How can I use the Step?

You can use this Step to automate customer interactions in chatbots, generate dynamic content, and facilitate AI-driven conversations within the Flow. It's suitable for customer service automation, educational tools, and enhancing user engagement on websites or applications.

How does the Step work?

The Step utilizes the OpenAI Chat Completions API and operates in two following modes:

  • Chat Completion: Designed for multi-turn conversations and can maintain a conversation history. Uses system and user messages to form an array of message objects to create requests to the Chat Completion API.
  • Text Completion: Tailored for single-turn tasks without conversation, this mode requires only user messages. It bypasses the need for conversation history and system messages, focusing solely on generating a response to the immediate input.

This approach ensures flexibility, allowing the Step to handle both complex, context-driven interactions and straightforward, single-query responses efficiently.

For more details, visit the Chat Completions guide.

Prerequisites

  • Before using this Step, ensure you have an OpenAI API key. If you don't have one, obtain it from your API Keys page.

Authorization

To authorize the Step, you can inherit authorization from the previous Step or select/create a new authorization in the current step.

To create a new authorization, follow these steps:

  1. For the authorization options, pick Select authorization in current Step.
  2. In the list of authorizations, select the Create a new authorization option.
  3. In the Add authorization modal, do the following:
    • Name your new authorization.
    • Enter your OpenAI API key.
    • Click Add to confirm.

Request settings

Configure the request settings as per the Create chat completion endpoint:

  • Mode: Determines whether the Step operates in Chat completion or Text completion mode.
  • System message (only for Chat completion mode): Defines the assistant's behavior, including its personality and any specific instructions for interaction.
  • User message: The text contents of the user message. Contains the requests or comments directed towards the assistant for response.
  • History capacity (only for Chat completion mode): Specifies the number of past messages retained in the conversation history.
  • Model: Identifies the AI model selected for generating responses.
  • Temperature: Controls the level of creativity exhibited in the assistant's responses.
  • Max tokens: The maximum number of tokens in the generated response.
  • Frequency penalty: Encourages the model to generate unique responses.
  • Presence penalty: Encourages the model to stay on-topic.
  • Stop: A sequence where the model should stop generating tokens.
  • Top P: Controls the diversity of the generated response.

Advanced settings

Specify additional optional parameters:

  • Stream: Toggle for streaming API response.
  • N: Number of completions to generate.
  • Result example: Defines output structure for accessing specific properties in the Merge field.

Merge field settings

The Step returns the result as a JSON object and stores it under the Merge field name. To learn more about Merge fields and how to work with them, see our Merge fields guide.

Output example

The output example shows the structure of the generated completion object:

json
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-3.5-turbo-0613",
  "system_fingerprint": "fp_44709d6fcb",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "\n\nHello there, how may I assist you today?",
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-3.5-turbo-0613",
  "system_fingerprint": "fp_44709d6fcb",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "\n\nHello there, how may I assist you today?",
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}

For more details, see the Сhat completion object API reference.

Error Handling

By default, the Step handles errors using a separate exit. So if any error occurs during the Step execution, the Flow proceeds down the error exit. For more information, see Error and timeout handling.

Reporting

The Step automatically generates Reporting events during its execution, allowing for real-time tracking and analysis of its performance and user interactions. To learn more, see Reporting events

Service dependencies

  • flow builder - v2.28.3
  • event-manager - v2.3.0
  • deployer - v2.6.0
  • library v2.11.3
  • studio v2.64.1

Release notes

v1.0.0

  • Initial release