@pipedream/openai 0.7.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/analyze-image-content/analyze-image-content.mjs +1 -1
- package/actions/cancel-run/cancel-run.mjs +1 -1
- package/actions/chat/chat.mjs +6 -1
- package/actions/chat-using-file-search/chat-using-file-search.mjs +229 -0
- package/actions/chat-using-functions/chat-using-functions.mjs +255 -0
- package/actions/chat-using-web-search/chat-using-web-search.mjs +200 -0
- package/actions/chat-with-assistant/chat-with-assistant.mjs +6 -1
- package/actions/classify-items-into-categories/classify-items-into-categories.mjs +1 -1
- package/actions/convert-text-to-speech/convert-text-to-speech.mjs +1 -1
- package/actions/create-assistant/create-assistant.mjs +1 -1
- package/actions/create-batch/create-batch.mjs +1 -1
- package/actions/create-embeddings/create-embeddings.mjs +1 -1
- package/actions/create-fine-tuning-job/create-fine-tuning-job.mjs +1 -1
- package/actions/create-image/create-image.mjs +1 -1
- package/actions/create-moderation/create-moderation.mjs +1 -1
- package/actions/create-thread/create-thread.mjs +1 -1
- package/actions/create-vector-store/create-vector-store.mjs +1 -1
- package/actions/create-vector-store-file/create-vector-store-file.mjs +1 -1
- package/actions/delete-file/delete-file.mjs +1 -1
- package/actions/delete-vector-store/delete-vector-store.mjs +1 -1
- package/actions/delete-vector-store-file/delete-vector-store-file.mjs +1 -1
- package/actions/list-files/list-files.mjs +1 -1
- package/actions/list-messages/list-messages.mjs +1 -1
- package/actions/list-run-steps/list-run-steps.mjs +1 -1
- package/actions/list-runs/list-runs.mjs +1 -1
- package/actions/list-vector-store-files/list-vector-store-files.mjs +1 -1
- package/actions/list-vector-stores/list-vector-stores.mjs +1 -1
- package/actions/modify-assistant/modify-assistant.mjs +1 -1
- package/actions/retrieve-file/retrieve-file.mjs +1 -1
- package/actions/retrieve-file-content/retrieve-file-content.mjs +1 -1
- package/actions/retrieve-run/retrieve-run.mjs +1 -1
- package/actions/retrieve-run-step/retrieve-run-step.mjs +1 -1
- package/actions/retrieve-vector-store/retrieve-vector-store.mjs +1 -1
- package/actions/retrieve-vector-store-file/retrieve-vector-store-file.mjs +1 -1
- package/actions/send-prompt/send-prompt.mjs +1 -1
- package/actions/submit-tool-outputs-to-run/submit-tool-outputs-to-run.mjs +1 -1
- package/actions/summarize/summarize.mjs +1 -1
- package/actions/translate-text/translate-text.mjs +1 -1
- package/actions/upload-file/upload-file.mjs +1 -1
- package/openai.app.mjs +10 -0
- package/package.json +1 -2
- package/sources/new-batch-completed/new-batch-completed.mjs +1 -1
- package/sources/new-file-created/new-file-created.mjs +1 -1
- package/sources/new-fine-tuning-job-created/new-fine-tuning-job-created.mjs +1 -1
- package/sources/new-run-state-changed/new-run-state-changed.mjs +1 -1
- package/actions/create-transcription/create-transcription.mjs +0 -264
|
@@ -8,7 +8,7 @@ export default {
|
|
|
8
8
|
key: "openai-analyze-image-content",
|
|
9
9
|
name: "Analyze Image Content",
|
|
10
10
|
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.1.
|
|
11
|
+
version: "0.1.5",
|
|
12
12
|
type: "action",
|
|
13
13
|
props: {
|
|
14
14
|
openai,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "openai-cancel-run",
|
|
5
5
|
name: "Cancel Run (Assistants)",
|
|
6
6
|
description: "Cancels a run that is in progress. [See the documentation](https://platform.openai.com/docs/api-reference/runs/cancelRun)",
|
|
7
|
-
version: "0.0.
|
|
7
|
+
version: "0.0.14",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
openai,
|
package/actions/chat/chat.mjs
CHANGED
|
@@ -6,12 +6,17 @@ import { ConfigurationError } from "@pipedream/platform";
|
|
|
6
6
|
export default {
|
|
7
7
|
...common,
|
|
8
8
|
name: "Chat",
|
|
9
|
-
version: "0.2.
|
|
9
|
+
version: "0.2.6",
|
|
10
10
|
key: "openai-chat",
|
|
11
11
|
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)",
|
|
12
12
|
type: "action",
|
|
13
13
|
props: {
|
|
14
14
|
openai,
|
|
15
|
+
alert: {
|
|
16
|
+
type: "alert",
|
|
17
|
+
alertType: "info",
|
|
18
|
+
content: "Looking to chat with your tools? Check out our individual actions: [Chat using Web Search](https://pipedream.com/apps/openai/actions/chat-using-web-search), [Chat using File Search](https://pipedream.com/apps/openai/actions/chat-using-file-search), and [Chat using Functions](https://pipedream.com/apps/openai/actions/chat-using-functions).",
|
|
19
|
+
},
|
|
15
20
|
modelId: {
|
|
16
21
|
propDefinition: [
|
|
17
22
|
openai,
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import openai from "../../openai.app.mjs";
|
|
2
|
+
import common from "../common/common.mjs";
|
|
3
|
+
import constants from "../../common/constants.mjs";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
...common,
|
|
7
|
+
name: "Chat using File Search",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
key: "openai-chat-using-file-search",
|
|
10
|
+
description: "Chat with your files knowledge base (vector stores). [See the documentation](https://platform.openai.com/docs/guides/tools-file-search)",
|
|
11
|
+
type: "action",
|
|
12
|
+
props: {
|
|
13
|
+
openai,
|
|
14
|
+
alert: {
|
|
15
|
+
type: "alert",
|
|
16
|
+
alertType: "info",
|
|
17
|
+
content: "To use this action, you need to have set up a knowledge base in a vector store and uploaded files to it. [More infomation here](https://platform.openai.com/docs/guides/tools-file-search?lang=javascript#overview).",
|
|
18
|
+
},
|
|
19
|
+
modelId: {
|
|
20
|
+
propDefinition: [
|
|
21
|
+
openai,
|
|
22
|
+
"chatCompletionModelId",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
vectorStoreId: {
|
|
26
|
+
propDefinition: [
|
|
27
|
+
openai,
|
|
28
|
+
"vectorStoreId",
|
|
29
|
+
],
|
|
30
|
+
description: "The identifier of a vector store. Currently supports only one vector store at a time",
|
|
31
|
+
},
|
|
32
|
+
input: {
|
|
33
|
+
type: "string",
|
|
34
|
+
label: "Chat Input",
|
|
35
|
+
description: "Text, image, or file inputs to the model, used to generate a response",
|
|
36
|
+
},
|
|
37
|
+
instructions: {
|
|
38
|
+
type: "string",
|
|
39
|
+
label: "Instructions",
|
|
40
|
+
description: "Inserts a system (or developer) message as the first item in the model's context",
|
|
41
|
+
optional: true,
|
|
42
|
+
},
|
|
43
|
+
includeSearchResults: {
|
|
44
|
+
type: "boolean",
|
|
45
|
+
label: "Include Search Results",
|
|
46
|
+
description: "Include the search results in the response",
|
|
47
|
+
default: false,
|
|
48
|
+
optional: true,
|
|
49
|
+
},
|
|
50
|
+
maxNumResults: {
|
|
51
|
+
type: "integer",
|
|
52
|
+
label: "Max Number of Results",
|
|
53
|
+
description: "Customize the number of results you want to retrieve from the vector store",
|
|
54
|
+
optional: true,
|
|
55
|
+
},
|
|
56
|
+
metadataFiltering: {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
label: "Metadata Filtering",
|
|
59
|
+
description: "Configure how the search results are filtered based on file metadata",
|
|
60
|
+
optional: true,
|
|
61
|
+
reloadProps: true,
|
|
62
|
+
},
|
|
63
|
+
previousResponseId: {
|
|
64
|
+
type: "string",
|
|
65
|
+
label: "Previous Response ID",
|
|
66
|
+
description: "The unique ID of the previous response to the model. Use this to create multi-turn conversations",
|
|
67
|
+
optional: true,
|
|
68
|
+
},
|
|
69
|
+
truncation: {
|
|
70
|
+
type: "string",
|
|
71
|
+
label: "Truncation",
|
|
72
|
+
description: "Specifies the truncation mode for the response if it's larger than the context window size",
|
|
73
|
+
optional: true,
|
|
74
|
+
default: "auto",
|
|
75
|
+
options: [
|
|
76
|
+
"auto",
|
|
77
|
+
"disabled",
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
responseFormat: {
|
|
81
|
+
type: "string",
|
|
82
|
+
label: "Response Format",
|
|
83
|
+
description: "Specify the format that the model must output. \n- **Text**: Returns unstructured text output.\n- **JSON Schema**: Enables you to define a [specific structure for the model's output using a JSON schema](https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses).",
|
|
84
|
+
options: [
|
|
85
|
+
"text",
|
|
86
|
+
"json_schema",
|
|
87
|
+
],
|
|
88
|
+
default: "text",
|
|
89
|
+
optional: true,
|
|
90
|
+
reloadProps: true,
|
|
91
|
+
},
|
|
92
|
+
skipThisStep: {
|
|
93
|
+
type: "boolean",
|
|
94
|
+
label: "Skip This Step",
|
|
95
|
+
description: "Pass in a boolean custom expression to skip this step's execution at runtime",
|
|
96
|
+
optional: true,
|
|
97
|
+
default: false,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
additionalProps() {
|
|
101
|
+
const {
|
|
102
|
+
modelId,
|
|
103
|
+
metadataFiltering,
|
|
104
|
+
responseFormat,
|
|
105
|
+
} = this;
|
|
106
|
+
const props = {};
|
|
107
|
+
|
|
108
|
+
if (this.openai.isReasoningModel(modelId)) {
|
|
109
|
+
props.reasoningEffort = {
|
|
110
|
+
type: "string",
|
|
111
|
+
label: "Reasoning Effort",
|
|
112
|
+
description: "Constrains effort on reasoning for reasoning models",
|
|
113
|
+
optional: true,
|
|
114
|
+
options: [
|
|
115
|
+
"low",
|
|
116
|
+
"medium",
|
|
117
|
+
"high",
|
|
118
|
+
],
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// aparrently not supported yet as of 12/march/2025
|
|
122
|
+
// props.generateSummary = {
|
|
123
|
+
// type: "string",
|
|
124
|
+
// label: "Generate Reasoning Summary",
|
|
125
|
+
// description: "A summary of the reasoning performed by the model",
|
|
126
|
+
// optional: true,
|
|
127
|
+
// options: [
|
|
128
|
+
// "concise",
|
|
129
|
+
// "detailed",
|
|
130
|
+
// ],
|
|
131
|
+
// };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// TODO: make this configuration user-friendly
|
|
135
|
+
// https://platform.openai.com/docs/guides/retrieval?attributes-filter-example=region#attribute-filtering
|
|
136
|
+
if (metadataFiltering) {
|
|
137
|
+
props.filters = {
|
|
138
|
+
type: "object",
|
|
139
|
+
label: "Filters",
|
|
140
|
+
description: "Filter the search results based on file metadata. [See the documentation here](https://platform.openai.com/docs/guides/retrieval#attribute-filtering)",
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
|
|
145
|
+
props.jsonSchema = {
|
|
146
|
+
type: "string",
|
|
147
|
+
label: "JSON Schema",
|
|
148
|
+
description: "Define the schema that the model's output must adhere to. [Generate one here](https://platform.openai.com/docs/guides/structured-outputs/supported-schemas).",
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return props;
|
|
153
|
+
},
|
|
154
|
+
methods: {
|
|
155
|
+
...common.methods,
|
|
156
|
+
},
|
|
157
|
+
async run({ $ }) {
|
|
158
|
+
if (this.skipThisStep) {
|
|
159
|
+
$.export("$summary", "Step execution skipped");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const data = {
|
|
164
|
+
model: this.modelId,
|
|
165
|
+
input: this.input,
|
|
166
|
+
instructions: this.instructions,
|
|
167
|
+
previous_response_id: this.previousResponseId,
|
|
168
|
+
truncation: this.truncation,
|
|
169
|
+
tools: [
|
|
170
|
+
{
|
|
171
|
+
type: "file_search",
|
|
172
|
+
vector_store_ids: [
|
|
173
|
+
this.vectorStoreId,
|
|
174
|
+
],
|
|
175
|
+
max_num_results: this.maxNumResults,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
if (this.includeSearchResults) {
|
|
181
|
+
data.include = [
|
|
182
|
+
"output[*].file_search_call.search_results",
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (this.filters) {
|
|
187
|
+
data.tools[0].filters = this.filters;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (this.openai.isReasoningModel(this.modelId) && this.reasoningEffort) {
|
|
191
|
+
data.reasoning = {
|
|
192
|
+
...data.reasoning,
|
|
193
|
+
effort: this.reasoningEffort,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (this.openai.isReasoningModel(this.modelId) && this.generateSummary) {
|
|
198
|
+
data.reasoning = {
|
|
199
|
+
...data.reasoning,
|
|
200
|
+
generate_summary: this.generateSummary,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
|
|
205
|
+
try {
|
|
206
|
+
data.text = {
|
|
207
|
+
format: {
|
|
208
|
+
type: this.responseFormat,
|
|
209
|
+
...JSON.parse(this.jsonSchema),
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
} catch (error) {
|
|
213
|
+
throw new Error("Invalid JSON format in the provided JSON Schema");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const response = await this.openai.responses({
|
|
218
|
+
$,
|
|
219
|
+
data,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
if (response) {
|
|
223
|
+
$.export("$summary", `Successfully sent chat with id ${response.id}`);
|
|
224
|
+
$.export("chat_responses", response.output);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return response;
|
|
228
|
+
},
|
|
229
|
+
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import openai from "../../openai.app.mjs";
|
|
2
|
+
import common from "../common/common.mjs";
|
|
3
|
+
import constants from "../../common/constants.mjs";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
...common,
|
|
7
|
+
name: "Chat using Functions",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
key: "openai-chat-using-functions",
|
|
10
|
+
description: "Chat with your models and allow them to invoke functions. Optionally, you can build and invoke workflows as functions. [See the documentation](https://platform.openai.com/docs/guides/function-calling)",
|
|
11
|
+
type: "action",
|
|
12
|
+
props: {
|
|
13
|
+
openai,
|
|
14
|
+
alert: {
|
|
15
|
+
type: "alert",
|
|
16
|
+
alertType: "info",
|
|
17
|
+
content: "Provide function names and parameters, and the model will either answer the question directly or decide to invoke one of the functions, returning a function call that adheres to your specified schema. Add a custom code step that includes all available functions which can be invoked based on the model's response - [you can even build an entire workflow as a function](https://pipedream.com/docs/workflows/building-workflows/code/nodejs/#invoke-another-workflow)! Once the appropriate function or workflow is executed, continue the overall execution or pass the result back to the model for further analysis. For more details, [see this guide](https://platform.openai.com/docs/guides/function-calling?api-mode=responses#overview).",
|
|
18
|
+
},
|
|
19
|
+
modelId: {
|
|
20
|
+
propDefinition: [
|
|
21
|
+
openai,
|
|
22
|
+
"chatCompletionModelId",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
input: {
|
|
26
|
+
type: "string",
|
|
27
|
+
label: "Chat Input",
|
|
28
|
+
description: "Text, image, or file inputs to the model, used to generate a response",
|
|
29
|
+
},
|
|
30
|
+
functions: {
|
|
31
|
+
type: "string",
|
|
32
|
+
label: "Functions",
|
|
33
|
+
description: "A valid JSON array of functions using OpenAI's function schema definition. [See guide here](https://platform.openai.com/docs/guides/function-calling?api-mode=responses&example=search-knowledge-base#defining-functions).",
|
|
34
|
+
default:
|
|
35
|
+
`[
|
|
36
|
+
{
|
|
37
|
+
"type": "function",
|
|
38
|
+
"name": "your_function_name",
|
|
39
|
+
"description": "Details on when and how to use the function",
|
|
40
|
+
"strict": true,
|
|
41
|
+
"parameters": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"properties": {
|
|
44
|
+
"property_name": {
|
|
45
|
+
"type": "property_type",
|
|
46
|
+
"description": "A description for this property"
|
|
47
|
+
},
|
|
48
|
+
"another_property_name": {
|
|
49
|
+
"type": "property_type",
|
|
50
|
+
"description": "A description for this property"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"required": [
|
|
54
|
+
"list",
|
|
55
|
+
"of",
|
|
56
|
+
"required",
|
|
57
|
+
"properties",
|
|
58
|
+
"for",
|
|
59
|
+
"this",
|
|
60
|
+
"object"
|
|
61
|
+
],
|
|
62
|
+
"additionalProperties": false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]`,
|
|
66
|
+
},
|
|
67
|
+
instructions: {
|
|
68
|
+
type: "string",
|
|
69
|
+
label: "Instructions",
|
|
70
|
+
description: "Inserts a system (or developer) message as the first item in the model's context",
|
|
71
|
+
optional: true,
|
|
72
|
+
},
|
|
73
|
+
toolChoice: {
|
|
74
|
+
type: "string",
|
|
75
|
+
label: "Tool Choice",
|
|
76
|
+
description: "- **auto**: The model decides whether and how many functions to call.\n- **required**: The model must call one or more functions.\n- **function_name**: Enter a custom expression to force the model to call this specific function.",
|
|
77
|
+
optional: true,
|
|
78
|
+
default: "auto",
|
|
79
|
+
options: [
|
|
80
|
+
"auto",
|
|
81
|
+
"required",
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
parallelToolCalls: {
|
|
85
|
+
type: "boolean",
|
|
86
|
+
label: "Parallel Function Calling",
|
|
87
|
+
description: "Allow or prevent the model to call multiple functions in a single turn",
|
|
88
|
+
optional: true,
|
|
89
|
+
default: true,
|
|
90
|
+
},
|
|
91
|
+
previousResponseId: {
|
|
92
|
+
type: "string",
|
|
93
|
+
label: "Previous Response ID",
|
|
94
|
+
description: "The unique ID of the previous response to the model. Use this to create multi-turn conversations",
|
|
95
|
+
optional: true,
|
|
96
|
+
},
|
|
97
|
+
truncation: {
|
|
98
|
+
type: "string",
|
|
99
|
+
label: "Truncation",
|
|
100
|
+
description: "Specifies the truncation mode for the response if it's larger than the context window size",
|
|
101
|
+
optional: true,
|
|
102
|
+
default: "auto",
|
|
103
|
+
options: [
|
|
104
|
+
"auto",
|
|
105
|
+
"disabled",
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
responseFormat: {
|
|
109
|
+
type: "string",
|
|
110
|
+
label: "Response Format",
|
|
111
|
+
description: "Specify the format that the model must output. \n- **Text**: Returns unstructured text output.\n- **JSON Schema**: Enables you to define a [specific structure for the model's output using a JSON schema](https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses).",
|
|
112
|
+
options: [
|
|
113
|
+
"text",
|
|
114
|
+
"json_schema",
|
|
115
|
+
],
|
|
116
|
+
default: "text",
|
|
117
|
+
optional: true,
|
|
118
|
+
reloadProps: true,
|
|
119
|
+
},
|
|
120
|
+
skipThisStep: {
|
|
121
|
+
type: "boolean",
|
|
122
|
+
label: "Skip This Step",
|
|
123
|
+
description: "Pass in a boolean custom expression to skip this step's execution at runtime",
|
|
124
|
+
optional: true,
|
|
125
|
+
default: false,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
additionalProps() {
|
|
129
|
+
const {
|
|
130
|
+
modelId,
|
|
131
|
+
responseFormat,
|
|
132
|
+
} = this;
|
|
133
|
+
const props = {};
|
|
134
|
+
|
|
135
|
+
if (this.openai.isReasoningModel(modelId)) {
|
|
136
|
+
props.reasoningEffort = {
|
|
137
|
+
type: "string",
|
|
138
|
+
label: "Reasoning Effort",
|
|
139
|
+
description: "Constrains effort on reasoning for reasoning models",
|
|
140
|
+
optional: true,
|
|
141
|
+
options: [
|
|
142
|
+
"low",
|
|
143
|
+
"medium",
|
|
144
|
+
"high",
|
|
145
|
+
],
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// aparrently not supported yet as of 12/march/2025
|
|
149
|
+
// props.generateSummary = {
|
|
150
|
+
// type: "string",
|
|
151
|
+
// label: "Generate Reasoning Summary",
|
|
152
|
+
// description: "A summary of the reasoning performed by the model",
|
|
153
|
+
// optional: true,
|
|
154
|
+
// options: [
|
|
155
|
+
// "concise",
|
|
156
|
+
// "detailed",
|
|
157
|
+
// ],
|
|
158
|
+
// };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
|
|
162
|
+
props.jsonSchema = {
|
|
163
|
+
type: "string",
|
|
164
|
+
label: "JSON Schema",
|
|
165
|
+
description: "Define the schema that the model's output must adhere to. [Generate one here](https://platform.openai.com/docs/guides/structured-outputs/supported-schemas).",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return props;
|
|
170
|
+
},
|
|
171
|
+
methods: {
|
|
172
|
+
...common.methods,
|
|
173
|
+
},
|
|
174
|
+
async run({ $ }) {
|
|
175
|
+
if (this.skipThisStep) {
|
|
176
|
+
$.export("$summary", "Step execution skipped");
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const data = {
|
|
181
|
+
model: this.modelId,
|
|
182
|
+
input: this.input,
|
|
183
|
+
instructions: this.instructions,
|
|
184
|
+
previous_response_id: this.previousResponseId,
|
|
185
|
+
truncation: this.truncation,
|
|
186
|
+
parallel_tool_calls: this.parallelToolCalls,
|
|
187
|
+
tools: [],
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
let functions = this.functions;
|
|
191
|
+
if (typeof functions === "string") {
|
|
192
|
+
try {
|
|
193
|
+
functions = JSON.parse(functions);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
throw new Error("Invalid JSON format in the provided Functions Schema");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (Array.isArray(functions)) {
|
|
200
|
+
data.tools.push(...functions);
|
|
201
|
+
} else {
|
|
202
|
+
data.tools.push(functions);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (this.toolChoice) {
|
|
206
|
+
if (this.toolChoice === "auto" || this.toolChoice === "required") {
|
|
207
|
+
data.tool_choice = this.toolChoice;
|
|
208
|
+
} else {
|
|
209
|
+
data.tool_choice = {
|
|
210
|
+
type: "function",
|
|
211
|
+
name: this.toolChoice,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (this.openai.isReasoningModel(this.modelId) && this.reasoningEffort) {
|
|
217
|
+
data.reasoning = {
|
|
218
|
+
...data.reasoning,
|
|
219
|
+
effort: this.reasoningEffort,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (this.openai.isReasoningModel(this.modelId) && this.generateSummary) {
|
|
224
|
+
data.reasoning = {
|
|
225
|
+
...data.reasoning,
|
|
226
|
+
generate_summary: this.generateSummary,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
|
|
231
|
+
try {
|
|
232
|
+
data.text = {
|
|
233
|
+
format: {
|
|
234
|
+
type: this.responseFormat,
|
|
235
|
+
...JSON.parse(this.jsonSchema),
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
} catch (error) {
|
|
239
|
+
throw new Error("Invalid JSON format in the provided JSON Schema");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const response = await this.openai.responses({
|
|
244
|
+
$,
|
|
245
|
+
data,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
if (response) {
|
|
249
|
+
$.export("$summary", `Successfully sent chat with id ${response.id}`);
|
|
250
|
+
$.export("chat_responses", response.output);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return response;
|
|
254
|
+
},
|
|
255
|
+
};
|