-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[ACTION] OpenAI Responses API #17475
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
Open
jcortes
wants to merge
1
commit into
master
Choose a base branch
from
pr/jeevikasirwani/17052
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
161 changes: 161 additions & 0 deletions
161
components/openai/actions/chat-with-responses-api/chat-with-responses-api.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,161 @@ | ||
import openai from "../../openai.app.mjs"; | ||
import common from "../common/common.mjs"; | ||
import constants from "../../common/constants.mjs"; | ||
import { parseArray } from "../../common/helpers.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "openai-chat-with-responses-api", | ||
name: "Chat With Responses API", | ||
version: "0.0.1", | ||
description: "Send a chat via the Responses API, mixing built-in tools and MCP server tools. [See the documentation](https://platform.openai.com/docs/guides/tools?api-mode=responses).", | ||
type: "action", | ||
props: { | ||
openai, | ||
modelId: { | ||
description: "Model used to generate the response", | ||
propDefinition: [ | ||
openai, | ||
"chatCompletionModelId", | ||
], | ||
}, | ||
input: { | ||
description: "Text input to the model used to generate a response", | ||
propDefinition: [ | ||
openai, | ||
"input", | ||
], | ||
}, | ||
instructions: { | ||
description: "Inserts a system (or developer) message as the first item in the model's context", | ||
propDefinition: [ | ||
openai, | ||
"instructions", | ||
], | ||
}, | ||
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 exceeds the context window", | ||
default: "auto", | ||
options: [ | ||
"auto", | ||
"disabled", | ||
], | ||
optional: true, | ||
}, | ||
responseFormat: { | ||
type: "string", | ||
label: "Response Format", | ||
description: "- `text`: Returns unstructured text output.\n- `json_schema`: Enforces a specific structure using a JSON schema.", | ||
options: [ | ||
"text", | ||
"json_schema", | ||
], | ||
default: "text", | ||
optional: true, | ||
reloadProps: true, | ||
}, | ||
builtInTools: { | ||
type: "string[]", | ||
label: "Built-In Tools", | ||
description: "Which of OpenAI's first-party tools to enable (web search, file search, code interpreter).", | ||
options: [ | ||
{ | ||
label: "Web Search", | ||
value: "web_search_preview", | ||
}, | ||
{ | ||
label: "File Search", | ||
value: "file_search", | ||
}, | ||
{ | ||
label: "Code Interpreter", | ||
value: "code_interpreter", | ||
}, | ||
], | ||
default: [], | ||
}, | ||
otherTools: { | ||
type: "string[]", | ||
label: "Other Tools", | ||
description: "Other tools to include in the chat. [See the documentation](https://platform.openai.com/docs/guides/tools-remote-mcp). Example: `{ type: \"mcp\", server_label: \"gmail\", server_url: \"https://remote.mcp.pipedream.net\", headers: {}, require_approval: \"never\" }`", | ||
optional: true, | ||
}, | ||
}, | ||
additionalProps() { | ||
const props = {}; | ||
if (this.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.", | ||
}; | ||
} | ||
return props; | ||
}, | ||
async run({ $ }) { | ||
const { | ||
builtInTools, | ||
otherTools, | ||
modelId, | ||
input, | ||
instructions, | ||
previousResponseId, | ||
truncation, | ||
responseFormat, | ||
jsonSchema, | ||
} = this; | ||
|
||
const tools = builtInTools.map((tool) => ({ | ||
type: tool, | ||
})); | ||
|
||
if (otherTools) { | ||
tools.push(...parseArray(otherTools)); | ||
} | ||
|
||
const data = { | ||
model: modelId, | ||
input, | ||
instructions, | ||
previous_response_id: previousResponseId, | ||
truncation, | ||
tools, | ||
}; | ||
|
||
if (responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) { | ||
try { | ||
data.text = { | ||
format: { | ||
type: responseFormat, | ||
...JSON.parse(jsonSchema), | ||
}, | ||
}; | ||
} catch { | ||
throw new Error("Invalid JSON format in the provided JSON Schema"); | ||
} | ||
} | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const response = await this.openai.responses({ | ||
$, | ||
data, | ||
debug: true, | ||
}); | ||
|
||
if (response) { | ||
$.export("$summary", `Successfully sent chat to OpenAI Responses API with ID \`${response.id}\`.`); | ||
$.export("chat_responses", response.output); | ||
} | ||
|
||
return response; | ||
}, | ||
}; |
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.