-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
OpenAI - Chat Tools #15900
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3f58591
initial chat with tools action
andrewjschuang f43c085
add app responses method
andrewjschuang 663bdde
add chat using web search action
andrewjschuang f7f210a
add chat file search action
andrewjschuang 10f33b7
add chat functions action
andrewjschuang 37ba7a7
method for checking if reasoning model
andrewjschuang 9693a65
add skip step execution
andrewjschuang 1e1dfcc
rename actions
andrewjschuang e164d5b
delete chat with tools action
andrewjschuang a62828e
add alert for chat actions
andrewjschuang 979e997
pnpm
andrewjschuang 11dc862
bump versions
andrewjschuang ff384b2
add json schema to request
andrewjschuang 3523ba0
fix description
andrewjschuang 35d1467
add try catch to json parse
andrewjschuang 82c914d
add chat_responses output
andrewjschuang a05ef4d
Merge branch 'master' into openai-chat-updates
andrewjschuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
229 changes: 229 additions & 0 deletions
229
components/openai/actions/chat-using-file-search/chat-using-file-search.mjs
This file contains hidden or 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,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
|
||
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).", | ||
}, | ||
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; | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
📝 Committable suggestion
🧰 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