Skip to content

OpenAI - Chat Tools #15900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "openai-analyze-image-content",
name: "Analyze Image Content",
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)",
version: "0.1.4",
version: "0.1.5",
type: "action",
props: {
openai,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/cancel-run/cancel-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "openai-cancel-run",
name: "Cancel Run (Assistants)",
description: "Cancels a run that is in progress. [See the documentation](https://platform.openai.com/docs/api-reference/runs/cancelRun)",
version: "0.0.13",
version: "0.0.14",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import openai from "../../openai.app.mjs";
import common from "../common/common.mjs";
import constants from "../../common/constants.mjs";

export default {
...common,
name: "Chat using File Search",
version: "0.0.1",
key: "openai-chat-using-file-search",
description: "Chat with your files knowledge base (vector stores). [See the documentation](https://platform.openai.com/docs/guides/tools-file-search)",
type: "action",
props: {
openai,
alert: {

Check warning on line 14 in components/openai/actions/chat-using-file-search/chat-using-file-search.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 14 in components/openai/actions/chat-using-file-search/chat-using-file-search.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "info",
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).",
},
Comment on lines +14 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add a label and description to the alert prop.

The static analysis flagged that alert props must have both a label and description. This omission may cause lint or pipeline failures based on your project's guidelines.

Here is a proposed fix:

 alert: {
   type: "alert",
+  label: "Alert",
+  description: "Provides additional context on how to set up a knowledge base in a vector store",
   alertType: "info",
   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).",
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
alert: {
type: "alert",
alertType: "info",
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).",
},
alert: {
type: "alert",
label: "Alert",
description: "Provides additional context on how to set up a knowledge base in a vector store",
alertType: "info",
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).",
},
🧰 Tools
🪛 GitHub Check: Lint Code Base

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

modelId: {
propDefinition: [
openai,
"chatCompletionModelId",
],
},
vectorStoreId: {
propDefinition: [
openai,
"vectorStoreId",
],
description: "The identifier of a vector store. Currently supports only one vector store at a time",
},
input: {
type: "string",
label: "Chat Input",
description: "Text, image, or file inputs to the model, used to generate a response",
},
instructions: {
type: "string",
label: "Instructions",
description: "Inserts a system (or developer) message as the first item in the model's context",
optional: true,
},
includeSearchResults: {
type: "boolean",
label: "Include Search Results",
description: "Include the search results in the response",
default: false,
optional: true,
},
maxNumResults: {
type: "integer",
label: "Max Number of Results",
description: "Customize the number of results you want to retrieve from the vector store",
optional: true,
},
metadataFiltering: {
type: "boolean",
label: "Metadata Filtering",
description: "Configure how the search results are filtered based on file metadata",
optional: true,
reloadProps: true,
},
previousResponseId: {
type: "string",
label: "Previous Response ID",
description: "The unique ID of the previous response to the model. Use this to create multi-turn conversations",
optional: true,
},
truncation: {
type: "string",
label: "Truncation",
description: "Specifies the truncation mode for the response if it's larger than the context window size",
optional: true,
default: "auto",
options: [
"auto",
"disabled",
],
},
responseFormat: {
type: "string",
label: "Response Format",
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).",
options: [
"text",
"json_schema",
],
default: "text",
optional: true,
reloadProps: true,
},
skipThisStep: {
type: "boolean",
label: "Skip This Step",
description: "Pass in a boolean custom expression to skip this step's execution at runtime",
optional: true,
default: false,
},
},
additionalProps() {
const {
modelId,
metadataFiltering,
responseFormat,
} = this;
const props = {};

if (this.openai.isReasoningModel(modelId)) {
props.reasoningEffort = {
type: "string",
label: "Reasoning Effort",
description: "Constrains effort on reasoning for reasoning models",
optional: true,
options: [
"low",
"medium",
"high",
],
};

// aparrently not supported yet as of 12/march/2025
// props.generateSummary = {
// type: "string",
// label: "Generate Reasoning Summary",
// description: "A summary of the reasoning performed by the model",
// optional: true,
// options: [
// "concise",
// "detailed",
// ],
// };
}

// TODO: make this configuration user-friendly
// https://platform.openai.com/docs/guides/retrieval?attributes-filter-example=region#attribute-filtering
if (metadataFiltering) {
props.filters = {
type: "object",
label: "Filters",
description: "Filter the search results based on file metadata. [See the documentation here](https://platform.openai.com/docs/guides/retrieval#attribute-filtering)",
};
}

if (responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
props.jsonSchema = {
type: "string",
label: "JSON Schema",
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).",
};
}

return props;
},
methods: {
...common.methods,
},
async run({ $ }) {
if (this.skipThisStep) {
$.export("$summary", "Step execution skipped");
return;
}

const data = {
model: this.modelId,
input: this.input,
instructions: this.instructions,
previous_response_id: this.previousResponseId,
truncation: this.truncation,
tools: [
{
type: "file_search",
vector_store_ids: [
this.vectorStoreId,
],
max_num_results: this.maxNumResults,
},
],
};

if (this.includeSearchResults) {
data.include = [
"output[*].file_search_call.search_results",
];
}

if (this.filters) {
data.tools[0].filters = this.filters;
}

if (this.openai.isReasoningModel(this.modelId) && this.reasoningEffort) {
data.reasoning = {
...data.reasoning,
effort: this.reasoningEffort,
};
}

if (this.openai.isReasoningModel(this.modelId) && this.generateSummary) {
data.reasoning = {
...data.reasoning,
generate_summary: this.generateSummary,
};
}

if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
try {
data.text = {
format: {
type: this.responseFormat,
...JSON.parse(this.jsonSchema),
},
};
} catch (error) {
throw new Error("Invalid JSON format in the provided JSON Schema");
}
}

const response = await this.openai.responses({
$,
data,
});

if (response) {
$.export("$summary", `Successfully sent chat with id ${response.id}`);
$.export("chat_responses", response.output);
}

return response;
},
};
Loading
Loading