This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git


The following commit(s) were added to refs/heads/main by this push:
     new b0f8931  Regen for commit e896dfa5ace635f761ea6bf4ac5769534a917327
b0f8931 is described below

commit b0f8931e25775cee9249dceee500a3ef4efef56b
Author: nicolaferraro <[email protected]>
AuthorDate: Tue May 11 10:02:35 2021 +0000

    Regen for commit e896dfa5ace635f761ea6bf4ac5769534a917327
    
    Signed-off-by: GitHub <[email protected]>
---
 .../openai-classification-action.kamelet.yaml      | 125 +++++++++++++++++++++
 1 file changed, 125 insertions(+)

diff --git 
a/library/camel-kamelets-catalog/src/main/resources/kamelets/openai-classification-action.kamelet.yaml
 
b/library/camel-kamelets-catalog/src/main/resources/kamelets/openai-classification-action.kamelet.yaml
new file mode 100644
index 0000000..51f0c0f
--- /dev/null
+++ 
b/library/camel-kamelets-catalog/src/main/resources/kamelets/openai-classification-action.kamelet.yaml
@@ -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,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iODk0IiBoZWlnaHQ9IjE3MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNjI1LjU1IDM1LjIyYy0xMy43NSAwLTIzLjU3IDQuNy0yOC4zOSAxMy41OWwtMi41OSA0Ljc5VjM3LjU0aC0yMi40djk3Ljg1aDIzLjU2Vjc3LjE4YzAtMTMuOTEgNy41NS0yMS44OSAyMC43My0yMS44OSAxMi41NiAwIDE5Ljc2IDcuNzYgMTkuNzYgMjEuMzF2NTguNzloMjMuNTZ2LTYzYzAtMjMuMjYtMTIuOC0zNy4xNy0zNC4yMy0zNy4xN3ptLTExNC4yMiAwYy0yNy
 [...]
+    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"

Reply via email to