-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9359635
commit e896dfa
Showing
4 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
docs/modules/ROOT/assets/images/kamelets/openai-classification-action.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT | ||
= image:kamelets/openai-classification-action.svg[] OpenAI Classification Action | ||
|
||
*Provided by: "Apache Software Foundation"* | ||
|
||
Classifies a sentence using the OpenAI API. | ||
|
||
It requires an OpenAI account (beta accounts available at https://beta.openai.com/). | ||
|
||
Training data for classification can be provided in advance by uploading a file with purpose="classifications", see: https://beta.openai.com/docs/api-reference/files/upload. | ||
|
||
The Kamelet accepts data in: | ||
- `text/plain` format (default) | ||
- `application/json` format: see reference at https://beta.openai.com/docs/api-reference/classifications/create | ||
|
||
|
||
== Configuration Options | ||
|
||
The following table summarizes the configuration options available for the `openai-classification-action` Kamelet: | ||
[width="100%",cols="2,^2,3,^2,^2,^3",options="header"] | ||
|=== | ||
| Property| Name| Description| Type| Default| Example | ||
| *authorizationToken {empty}* *| Authorization Token| The authorization token to use to contact the openAI API| string| | | ||
| engine| Engine| The OpenAI engine to use| string| `"davinci"`| | ||
| file| Examples File| The ID of an uploaded file containing examples for classification| string| | `"file-9HbeJXxtG7pg1YTXRx1v1fmn"` | ||
| format| Format| The response format ('text/plain' or 'application/json' are supported)| string| `"text/plain"`| | ||
|=== | ||
|
||
NOTE: Fields marked with ({empty}*) are mandatory. | ||
|
||
== Usage | ||
|
||
This section summarizes how the `openai-classification-action` can be used in various contexts. | ||
|
||
=== Knative Action | ||
|
||
The `openai-classification-action` Kamelet can be used as intermediate step in a binding. | ||
|
||
.openai-classification-action-binding.yaml | ||
[source,yaml] | ||
---- | ||
apiVersion: camel.apache.org/v1alpha1 | ||
kind: KameletBinding | ||
metadata: | ||
name: openai-classification-action-binding | ||
spec: | ||
source: | ||
ref: | ||
kind: Kamelet | ||
apiVersion: camel.apache.org/v1alpha1 | ||
name: timer-source | ||
properties: | ||
message: "Hello" | ||
steps: | ||
- ref: | ||
kind: Kamelet | ||
apiVersion: camel.apache.org/v1alpha1 | ||
name: openai-classification-action | ||
properties: | ||
authorizationToken: "The Authorization Token" | ||
sink: | ||
ref: | ||
kind: InMemoryChannel | ||
apiVersion: messaging.knative.dev/v1 | ||
name: mychannel | ||
---- | ||
|
||
Make sure you have xref:latest@camel-k::installation/installation.adoc[Camel K installed] into the Kubernetes cluster you're connected to. | ||
|
||
Save the `openai-classification-action-binding.yaml` file into your hard drive, then configure it according to your needs. | ||
|
||
You can run the action using the following command: | ||
|
||
[source,shell] | ||
---- | ||
kubectl apply -f openai-classification-action-binding.yaml | ||
---- | ||
// THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
apiVersion: camel.apache.org/v1alpha1 | ||
kind: Kamelet | ||
metadata: | ||
name: openai-classification-action | ||
annotations: | ||
camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iODk0IiBoZWlnaHQ9IjE3MCIgeG1sbnM9Imh0dHA6Ly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cuMTZsLTQxLjA5LTIzLjg2MSAxNC4xOTYtOC4xOThhLjUzMy41MzMgMCAwIDEgLjUgMGwzNC4wMjYgMTkuNjYyYTMxLjY2IDMxLjY2IDAgMCAxLTQuNzY2IDU3LjA4N1Y4Ny40NzhhNS41NjUgNS41NjUgMCAwIDAtMi44NjYtNC42OTl6bTE0LjE2My0yMS4yOTVsLTEtLjYtMzMuNjI1LTE5LjU5NWE1LjQ2NSA1LjQ2NSAwIDAgMC01LjUzMiAwTDY1LjEyOSA2NS4wMTZ2LTE2LjQzYS40NjcuNDY3IDAgMCAxIC4yLS40MzJsMzQuMDI1LTE5LjYzYTMxLjY5MyAzMS42OTMgMCAwIDEgNDcuMDU2IDMyLjgyN3YuMTMzek01Ny4zNjQgOTAuNjExbC0xNC4yMy04LjE5OGEuNTY3LjU2NyAwIDAgMS0uMjY3LS40VjQyLjc4OEEzMS42OTMgMzEuNjkzIDAgMCAxIDk0LjgyMiAxOC40NmwtMSAuNTY3LTMzLjY1OSAxOS40MjlhNS41OTkgNS41OTkgMCAwIDAtMi43NjYgNC43OTlsLS4wMzMgNDcuMzU2em03LjczMi0xNi42NjNsMTguMzI5LTEwLjU2NCAxOC4zNjIgMTAuNTY0djIxLjEyOGwtMTguMjk2IDEwLjU2NUw2NS4xMyA5NS4wNzZsLS4wMzMtMjEuMTI4eiIvPjwvc3ZnPg==" | ||
camel.apache.org/provider: "Apache Software Foundation" | ||
camel.apache.org/kamelet.group: "OpenAI" | ||
labels: | ||
camel.apache.org/kamelet.type: "action" | ||
spec: | ||
definition: | ||
title: "OpenAI Classification Action" | ||
description: | | ||
Classifies a sentence using the OpenAI API. | ||
It requires an OpenAI account (beta accounts available at https://beta.openai.com/). | ||
Training data for classification can be provided in advance by uploading a file with purpose="classifications", see: https://beta.openai.com/docs/api-reference/files/upload. | ||
The Kamelet accepts data in: | ||
- `text/plain` format (default) | ||
- `application/json` format: see reference at https://beta.openai.com/docs/api-reference/classifications/create | ||
required: | ||
- authorizationToken | ||
type: object | ||
properties: | ||
authorizationToken: | ||
title: Authorization Token | ||
description: The authorization token to use to contact the openAI API | ||
type: string | ||
format: | ||
title: Format | ||
description: The response format ('text/plain' or 'application/json' are supported) | ||
type: string | ||
default: text/plain | ||
engine: | ||
title: Engine | ||
description: The OpenAI engine to use | ||
type: string | ||
default: davinci | ||
file: | ||
title: Examples File | ||
description: The ID of an uploaded file containing examples for classification | ||
type: string | ||
example: "file-9HbeJXxtG7pg1YTXRx1v1fmn" | ||
types: | ||
in: | ||
mediaType: text/plain | ||
out: | ||
mediaType: text/plain | ||
dependencies: | ||
- "github:apache.camel-kamelets:camel-kamelets-utils:main-SNAPSHOT" | ||
- "camel:jackson" | ||
- "camel:jsonpath" | ||
- "camel:core" | ||
- "camel:kamelet" | ||
- "camel:http" | ||
flow: | ||
from: | ||
uri: kamelet:source | ||
steps: | ||
- choice: | ||
when: | ||
- simple: "${header[Content-Type]} == null || ${header[Content-Type]} == 'text/plain'" | ||
steps: | ||
- convert-body-to: | ||
type: "java.lang.String" | ||
- transform: | ||
simple: "${bean:type:java.util.Map?method=of('query', ${body})}" | ||
- marshal: | ||
json: {} | ||
- unmarshal: | ||
json: | ||
library: Jackson | ||
unmarshalTypeName: com.fasterxml.jackson.databind.JsonNode | ||
- choice: | ||
when: | ||
- simple: "${body.has('model')} == false" | ||
steps: | ||
- set-property: | ||
name: "field" | ||
constant: "model" | ||
- set-property: | ||
name: "value" | ||
constant: "{{engine}}" | ||
- bean: "org.apache.camel.kamelets.utils.transform.InsertField" | ||
- set-property: | ||
name: "file" | ||
constant: "{{file:}}" | ||
- choice: | ||
when: | ||
- simple: "${body.has('file')} == false && ${exchangeProperty.file} != null" | ||
steps: | ||
- set-property: | ||
name: "field" | ||
constant: "file" | ||
- set-property: | ||
name: "value" | ||
simple: "${exchangeProperty.file}" | ||
- bean: "org.apache.camel.kamelets.utils.transform.InsertField" | ||
- marshal: | ||
json: {} | ||
- set-header: | ||
name: "Authorization" | ||
simple: "Bearer {{authorizationToken}}" | ||
- set-header: | ||
name: "Content-Type" | ||
constant: "application/json" | ||
- to: "https://api.openai.com/v1/classifications" | ||
- remove-header: | ||
header-name: "Authorization" | ||
- set-property: | ||
name: format | ||
constant: "{{format}}" | ||
- choice: | ||
when: | ||
- simple: "${exchangeProperty.format} == 'text/plain'" | ||
steps: | ||
- transform: | ||
jsonpath: "$.label" | ||
- set-header: | ||
name: "Content-Type" | ||
constant: "text/plain" |