Skip to main content

Create Chat Completion

Generates chat completions using OpenAI's chat models with support for system prompts, chat history, and image inputs.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Connection Id - The connection ID for the OpenAI service.
  • System - The system prompt that guides the model's behavior. Default is "You are a helpful assistant."
  • Prompt - The user's input prompt for the chat.
  • Chat History - Previous conversation history to maintain context.
  • Tool Message - Tool call responses to include in the conversation.
  • Image Url - URL or file path to a single image to include in the prompt.
  • Images - Array of image URLs or file paths to include in the prompt.

Options

  • Frequency Penalty - Penalty for using frequent tokens. Reduces model verbosity. Number between -2.0 and 2.0.
  • Logit Bias - Modify the likelihood of specified tokens appearing in the completion.
  • Max Tokens - The maximum number of tokens to generate in the completion.
  • Number of Completions - Number of completions to generate. Default is 1.
  • Presence Penalty - Penalty for using new tokens. Increases model verbosity. Number between -2.0 and 2.0.
  • Response Format - Format of the response. Options are "text" or "json_object".
  • Image Detail - Detail level for image processing. Options are "auto", "high", or "low".
  • Seed - Seed for deterministic sampling (Beta feature).
  • Stop - Up to 4 sequences where the API will stop generating further tokens.
  • Temperature - Sampling temperature to use. Lower values like 0.2 make it more focused and deterministic. Between 0 and 2.
  • Top P - Nucleus sampling: top-p cutoff of cumulative probability. Generally recommended to alter this or temperature but not both.
  • User - A unique identifier representing your end-user.
  • Type of Tools - The type of the tool. Currently only "function" is supported.
  • Function of Tools - Function definition for tools that can be called by the model.
  • Tool Choice - Controls which tool the model calls. If tools are provided, defaults to "auto".
  • Model - The OpenAI model to use. Options include:
    • gpt-3.5-turbo
    • gpt-4o
    • gpt-4o-mini
    • o1
    • o1-mini
    • chatgpt-4o-latest
    • gpt-4-turbo
    • Custom Model
  • Custom Model - Specify a custom model name if "Custom Model" is selected.
  • Timeout (sec) - Timeout for the request. Only available with Robomotion Credits. Leave blank for default value (120+).
  • Streaming - Enable streaming of responses as they are generated.

Output

  • Completion Text - The generated completion text from the model.
  • Chat History - Updated conversation history including the new completion.
  • Stream Index - Index counter for streaming responses.

How It Works

The Create Chat Completion node uses OpenAI's chat models to generate conversational responses. When executed, the node:

  1. Validates the provided Connection Id
  2. Prepares the chat messages including system prompt, user prompt, and chat history
  3. Processes any image inputs by encoding them appropriately
  4. Configures all specified options for the model
  5. Sends the request to the selected OpenAI chat model
  6. Processes the response and returns the completion text and updated chat history

Requirements

  • A valid OpenAI API key or Robomotion Credits
  • An active OpenAI connection
  • A user prompt or chat history to process
  • Read access to any local image files if used

Error Handling

The node will return specific errors in the following cases:

  • Empty or invalid Connection Id
  • Empty or invalid Prompt
  • Invalid model selection
  • Invalid option values (frequency penalty, temperature, etc.)
  • OpenAI API errors
  • Timeout errors
  • File access errors for local images
  • Unsupported image formats

Usage Notes

  • The default model is gpt-4o-mini which provides a good balance of performance and cost
  • Image inputs can be provided as URLs or local file paths
  • Supported image formats include JPEG and PNG
  • Chat history allows for maintaining context across multiple interactions
  • Tool calling enables function calling capabilities in supported models
  • Streaming can be enabled for real-time response generation
  • When using Robomotion Credits, the timeout can be customized for better performance
  • The response format can be set to "json_object" for structured JSON responses