Actions2
Chat Completion
AI-generatedOverview
This node enables interaction with OpenAI-compatible language models to generate text completions or chat-based completions. It supports two main operations:
- Chat Completion: Generate conversational responses based on a sequence of messages with roles such as system, user, and assistant.
- Text Completion: Generate text continuations from a given prompt.
Common use cases include building chatbots, generating creative writing, drafting emails, summarizing content, or any scenario requiring AI-generated natural language text.
For example, you can feed a conversation history to the Chat Completion operation to get an AI assistant's reply, or provide a prompt to the Text Completion operation to continue a story or complete a sentence.
Properties
| Name | Meaning |
|---|---|
| Model | The AI model to use for completion (e.g., "gpt-3.5-turbo"). |
| Messages | A collection of messages for chat completion, each with: |
| - Role: one of System, User, or Assistant | |
| - Content: the text content of the message | |
| Additional Fields | Optional parameters to customize generation: |
| - Temperature | Controls randomness; lower values produce more deterministic results (range 0 to 2). |
| - Max Tokens | Maximum number of tokens to generate in the response (minimum 1). |
| - Top P | Controls diversity via nucleus sampling (range 0 to 1). |
| - Frequency Penalty | Penalizes new tokens based on their existing frequency (range -2 to 2). |
| - Presence Penalty | Penalizes new tokens based on whether they appear in the text (range -2 to 2). |
| - Stop | Up to 4 sequences where the API will stop generating further tokens (string). |
Output
The node outputs an array of JSON objects corresponding to each input item processed. Each output JSON contains the full response from the OpenAI-compatible API under the json field.
For chat completions, this includes the generated message(s) with roles and content. For text completions, it includes the generated text continuation.
No binary data output is produced by this node.
Dependencies
- Requires an API key credential for an OpenAI-compatible service.
- Requires the base URL of the OpenAI-compatible API endpoint.
- The node makes HTTP POST requests to either
/v1/chat/completionsor/v1/completionsdepending on the operation. - Proper configuration of credentials with the API key and base URL is necessary.
Troubleshooting
- Missing Base URL or API Key: The node throws an error if either the base URL or API key is not provided. Ensure these are correctly set in the credentials.
- Empty Messages for Chat Completion: An error occurs if no messages are provided for chat completion. Add at least one message.
- Empty Prompt for Text Completion: An error occurs if the prompt is empty for text completion. Provide a valid prompt.
- API Request Failures: Network issues or invalid credentials may cause request failures. Verify network connectivity and credential validity.
- Continue On Fail: If enabled, errors for individual items will be returned as JSON error messages instead of stopping execution.