Skip to content

Commit ac352db

Browse files
committed
OpenAI: Added support for structured outputs in Chat action
1 parent 6c012d0 commit ac352db

File tree

37 files changed

+96
-41
lines changed

37 files changed

+96
-41
lines changed

components/openai/actions/analyze-image-content/analyze-image-content.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
key: "openai-analyze-image-content",
99
name: "Analyze Image Content",
1010
description: "Send a message or question about an image and receive a response. [See the documentation](https://platform.openai.com/docs/api-reference/runs/createThreadAndRun)",
11-
version: "0.0.2",
11+
version: "0.0.3",
1212
type: "action",
1313
props: {
1414
openai,

components/openai/actions/cancel-run/cancel-run.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "openai-cancel-run",
55
name: "Cancel Run (Assistants)",
66
description: "Cancels a run that is in progress. [See the documentation](https://platform.openai.com/docs/api-reference/runs/cancelRun)",
7-
version: "0.0.8",
7+
version: "0.0.9",
88
type: "action",
99
props: {
1010
openai,

components/openai/actions/chat-with-assistant/chat-with-assistant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "openai-chat-with-assistant",
77
name: "Chat with Assistant",
88
description: "Sends a message and generates a response, storing the message history for a continuous conversation. [See the documentation](https://platform.openai.com/docs/api-reference/runs/createThreadAndRun)",
9-
version: "0.0.3",
9+
version: "0.0.4",
1010
type: "action",
1111
props: {
1212
openai,

components/openai/actions/chat/chat.mjs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import constants from "../../common/constants.mjs";
55
export default {
66
...common,
77
name: "Chat",
8-
version: "0.1.11",
8+
version: "0.1.12",
99
key: "openai-chat",
1010
description: "The Chat API, using the `gpt-3.5-turbo` or `gpt-4` model. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
1111
type: "action",
@@ -43,13 +43,27 @@ export default {
4343
responseFormat: {
4444
type: "string",
4545
label: "Response Format",
46-
description: "Specify the format that the model must output. [Setting to `json_object` guarantees the message the model generates is valid JSON](https://platform.openai.com/docs/api-reference/chat/create#chat-create-response_format). Defaults to `text`",
47-
options: constants.CHAT_RESPONSE_FORMATS,
46+
description: "Specify the format that the model must output. \n- **Text** (default): Returns unstructured text output.\n- **JSON Object**: Ensures the model's output is a valid JSON object.\n- **JSON Schema** (GPT-4o and later): Enables you to define a specific structure for the model's output using a JSON schema. Supported with models `gpt-4o-2024-08-06` and later, and `gpt-4o-mini-2024-07-18` and later.",
47+
options: Object.values(constants.CHAT_RESPONSE_FORMAT),
4848
optional: true,
4949
default: "text",
50+
reloadProps: true,
5051
},
5152
...common.props,
5253
},
54+
additionalProps() {
55+
const { responseFormat } = this;
56+
if (responseFormat !== constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
57+
return {};
58+
}
59+
return {
60+
jsonSchema: {
61+
type: "string",
62+
label: "JSON Schema",
63+
description: "Define the schema that the model's output must adhere to. [See the documentation here](https://platform.openai.com/docs/guides/structured-outputs/supported-schemas).",
64+
},
65+
};
66+
},
5367
async run({ $ }) {
5468
const args = this._getChatArgs();
5569

components/openai/actions/classify-items-into-categories/classify-items-into-categories.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import common from "../common/common-helper.mjs";
33
export default {
44
...common,
55
name: "Classify Items into Categories",
6-
version: "0.0.12",
6+
version: "0.0.13",
77
key: "openai-classify-items-into-categories",
88
description: "Classify items into specific categories using the Chat API. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
99
type: "action",

components/openai/actions/common/common.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { ConfigurationError } from "@pipedream/platform";
2+
import constants from "../../common/constants.mjs";
3+
import { parse } from "../../common/helpers.mjs";
24

35
const CHAT_DOCS_MESSAGE_FORMAT_URL = "https://platform.openai.com/docs/guides/chat/introduction";
46

@@ -148,9 +150,17 @@ export default {
148150

149151
const responseFormat = {};
150152

153+
const jsonSchemaObj =
154+
this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value
155+
? {
156+
json_schema: parse(this.jsonSchema),
157+
}
158+
: {};
159+
151160
if (this.modelId != "gpt-4-vision-preview") {
152161
responseFormat["response_format"] = {
153162
type: this.responseFormat,
163+
...jsonSchemaObj,
154164
};
155165
}
156166

components/openai/actions/convert-text-to-speech/convert-text-to-speech.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "openai-convert-text-to-speech",
66
name: "Convert Text to Speech (TTS)",
77
description: "Generates audio from the input text. [See the documentation](https://platform.openai.com/docs/api-reference/audio/createSpeech)",
8-
version: "0.0.7",
8+
version: "0.0.8",
99
type: "action",
1010
props: {
1111
openai,

components/openai/actions/create-assistant/create-assistant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "openai-create-assistant",
77
name: "Create Assistant",
88
description: "Creates an assistant with a model and instructions. [See the documentation](https://platform.openai.com/docs/api-reference/assistants/createAssistant)",
9-
version: "0.1.5",
9+
version: "0.1.6",
1010
type: "action",
1111
props: {
1212
openai,

components/openai/actions/create-batch/create-batch.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
key: "openai-create-batch",
99
name: "Create Batch",
1010
description: "Creates and executes a batch from an uploaded file of requests. [See the documentation](https://platform.openai.com/docs/api-reference/batch/create)",
11-
version: "0.0.2",
11+
version: "0.0.3",
1212
type: "action",
1313
props: {
1414
openai,

components/openai/actions/create-embeddings/create-embeddings.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import common from "../common/common.mjs";
44

55
export default {
66
name: "Create Embeddings",
7-
version: "0.0.10",
7+
version: "0.0.11",
88
key: "openai-create-embeddings",
99
description: "Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. [See the documentation](https://platform.openai.com/docs/api-reference/embeddings)",
1010
type: "action",

0 commit comments

Comments
 (0)