OpenAI Chat Action
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Preview"
Sends each message as a question to a chat model of OpenAI, or of any server with the same API such as Ollama, vLLM or LM Studio, and gives back the answer.
Use it to summarize, classify, translate or answer questions about text as it flows, for example to sort support emails by topic or to pull the fields out of an order. Set jsonSchema to get the answer as JSON that has the fields you ask for. For a model in Amazon Bedrock or Google Vertex AI, use aws-bedrock-text-sink or google-vertexai-sink.
Input: the body is the user message, as text; bytes and streams are read as text, whatever their Content-Type.
Output: the body is the answer of the model, as text. With jsonSchema, it is the JSON text of the answer. The CamelOpenAIFinishReason header says why the model stopped, such as stop or length, CamelOpenAIResponseModel and CamelOpenAIResponseId are the model and the id the server gives for the answer, and the token counts are in the CamelOpenAIPromptTokens, CamelOpenAICompletionTokens and CamelOpenAITotalTokens headers.
Good to know: each message is one question on its own: the Kamelet keeps no history of the conversation, and the model cannot call tools, so the text of a message cannot make it act. Headers that start with CamelOpenAI are removed from the message first, so a message cannot change the model, the system message or the request. An error answer from the server fails the message with an error of the package com.openai.errors, such as UnauthorizedException for a wrong API key (status 401) or InternalServerException for a status 5xx. A request that gets the status 408, 409, 429 or 5xx is first sent again, maxRetries times.
Configuration Options
The following table summarizes the configuration options available for the openai-chat-action Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
Model | Required The name of the model to ask, as the server names it. | string | gpt-4.1-mini | ||
API Key | The API key to send to the server, as a Bearer token. Create it in the OpenAI platform under API keys. When it is not set, the | string | |||
Base URL | The URL of the API of the server, up to and without | string | http://localhost:11434/v1 | ||
JSON Schema | The JSON schema of the answer: JSON text, or | string | resource:file:/etc/camel/ticket-schema.json | ||
JSON Schema Strict | Whether the model must follow | boolean | false | ||
Max Retries | How many more times a request is sent when the server answers with the status 408, 409, 429 or 5xx, before the message fails. A | integer | 2 | ||
Max Tokens | The most tokens (pieces of words) the answer may have, sent as | integer | 500 | ||
Strip Thinking | Whether to remove the | boolean | false | ||
System Message | Instructions for the model, sent before each user message, such as the role it plays, the language or the length of the answer. | string | You sort support emails. Answer with one word: billing, technical or other. | ||
Temperature | How random the answer is, from 0.0 to 2.0. Lower values give more focused and repeatable answers. When it is not set, the server chooses. | number | 0.2 |
Dependencies
At runtime, the openai-chat-action Kamelet relies upon the presence of the following dependencies:
-
camel:kamelet
-
camel:openai
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:timer-source"
parameters:
period: 10000
message: 'test'
steps:
- to:
uri: "kamelet:openai-chat-action"
parameters:
.
.
.
- to:
uri: "kamelet:log-sink" You can now run it directly through the following command
camel run route.yaml