diff --git a/components/openai/actions/analyze-image-content/analyze-image-content.mjs b/components/openai/actions/analyze-image-content/analyze-image-content.mjs index 037c5ba568331..f106bf656f01e 100644 --- a/components/openai/actions/analyze-image-content/analyze-image-content.mjs +++ b/components/openai/actions/analyze-image-content/analyze-image-content.mjs @@ -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.1", + version: "0.1.2", type: "action", props: { openai, diff --git a/components/openai/actions/chat-with-assistant/chat-with-assistant.mjs b/components/openai/actions/chat-with-assistant/chat-with-assistant.mjs index 16d9c25d819f5..dc11b7ef09dcc 100644 --- a/components/openai/actions/chat-with-assistant/chat-with-assistant.mjs +++ b/components/openai/actions/chat-with-assistant/chat-with-assistant.mjs @@ -6,7 +6,7 @@ export default { key: "openai-chat-with-assistant", name: "Chat with Assistant", 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)", - version: "0.0.6", + version: "0.0.7", type: "action", props: { openai, diff --git a/components/openai/actions/chat/chat.mjs b/components/openai/actions/chat/chat.mjs index 0d139f6922e76..ce9c55b1cecab 100644 --- a/components/openai/actions/chat/chat.mjs +++ b/components/openai/actions/chat/chat.mjs @@ -6,7 +6,7 @@ import { ConfigurationError } from "@pipedream/platform"; export default { ...common, name: "Chat", - version: "0.2.2", + version: "0.2.3", key: "openai-chat", 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)", type: "action", @@ -57,19 +57,87 @@ export default { optional: true, reloadProps: true, }, + toolTypes: { + type: "string[]", + label: "Tool Types", + description: "The types of tools to enable on the assistant", + options: constants.TOOL_TYPES.filter((toolType) => toolType === "function"), + optional: true, + reloadProps: true, + }, }, additionalProps() { - const { responseFormat } = this; - if (responseFormat !== constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) { - return {}; - } - return { - jsonSchema: { + const { + responseFormat, + toolTypes, + numberOfFunctions, + } = this; + const props = {}; + + 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. [See the documentation here](https://platform.openai.com/docs/guides/structured-outputs/supported-schemas).", - }, - }; + }; + } + + if (toolTypes?.includes("function")) { + props.numberOfFunctions = { + type: "integer", + label: "Number of Functions", + description: "The number of functions to define", + optional: true, + reloadProps: true, + default: 1, + }; + + for (let i = 0; i < (numberOfFunctions || 1); i++) { + props[`functionName_${i}`] = { + type: "string", + label: `Function Name ${i + 1}`, + description: "The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.", + }; + props[`functionDescription_${i}`] = { + type: "string", + label: `Function Description ${i + 1}`, + description: "A description of what the function does, used by the model to choose when and how to call the function.", + optional: true, + }; + props[`functionParameters_${i}`] = { + type: "object", + label: `Function Parameters ${i + 1}`, + description: "The parameters the functions accepts, described as a JSON Schema object. See the [guide](https://platform.openai.com/docs/guides/text-generation/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.", + optional: true, + }; + } + } + + return props; + }, + methods: { + ...common.methods, + _buildTools() { + const tools = this.toolTypes?.filter((toolType) => toolType !== "function")?.map((toolType) => ({ + type: toolType, + })) || []; + if (this.toolTypes?.includes("function")) { + const numberOfFunctions = this.numberOfFunctions || 1; + for (let i = 0; i < numberOfFunctions; i++) { + tools.push({ + type: "function", + function: { + name: this[`functionName_${i}`], + description: this[`functionDescription_${i}`], + parameters: this[`functionParameters_${i}`], + }, + }); + } + } + return tools.length + ? tools + : undefined; + }, }, async run({ $ }) { if (this.audio && !this.modelId.includes("gpt-4o-audio-preview")) { @@ -80,7 +148,10 @@ export default { const response = await this.openai.createChatCompletion({ $, - data: args, + data: { + ...args, + tools: this._buildTools(), + }, }); if (response) { diff --git a/components/openai/actions/common/common-assistants.mjs b/components/openai/actions/common/common-assistants.mjs index f0e19c1dc209e..f6c1e26684f22 100644 --- a/components/openai/actions/common/common-assistants.mjs +++ b/components/openai/actions/common/common-assistants.mjs @@ -16,7 +16,20 @@ export default { if (!this.toolTypes?.length) { return props; } - return this.getToolProps(); + if (this.toolTypes.includes("function")) { + props.numberOfFunctions = { + type: "integer", + label: "Number of Functions", + description: "The number of functions to define.", + optional: true, + reloadProps: true, + default: 1, + }; + } + return { + ...props, + ...(await this.getToolProps()), + }; }, methods: { async getToolProps() { @@ -58,23 +71,26 @@ export default { }; } if (this.toolTypes.includes("function")) { - props.functionName = { - type: "string", - label: "Function Name", - description: "The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.", - }; - props.functionDescription = { - type: "string", - label: "Function Description", - description: "A description of what the function does, used by the model to choose when and how to call the function.", - optional: true, - }; - props.functionParameters = { - type: "object", - label: "Function Parameters", - description: "The parameters the functions accepts, described as a JSON Schema object. See the [guide](https://platform.openai.com/docs/guides/text-generation/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.", - optional: true, - }; + const numberOfFunctions = this.numberOfFunctions || 1; + for (let i = 0; i < numberOfFunctions; i++) { + props[`functionName_${i}`] = { + type: "string", + label: `Function Name ${i + 1}`, + description: "The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.", + }; + props[`functionDescription_${i}`] = { + type: "string", + label: `Function Description ${i + 1}`, + description: "A description of what the function does, used by the model to choose when and how to call the function.", + optional: true, + }; + props[`functionParameters_${i}`] = { + type: "object", + label: `Function Parameters ${i + 1}`, + description: "The parameters the functions accepts, described as a JSON Schema object. See the [guide](https://platform.openai.com/docs/guides/text-generation/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.", + optional: true, + }; + } } return props; }, @@ -83,14 +99,17 @@ export default { type: toolType, })) || []; if (this.toolTypes?.includes("function")) { - tools.push({ - type: "function", - function: { - name: this.functionName, - description: this.functionDescription, - parameters: this.functionParameters, - }, - }); + const numberOfFunctions = this.numberOfFunctions || 1; + for (let i = 0; i < numberOfFunctions; i++) { + tools.push({ + type: "function", + function: { + name: this[`functionName_${i}`], + description: this[`functionDescription_${i}`], + parameters: this[`functionParameters_${i}`], + }, + }); + } } return tools.length ? tools diff --git a/components/openai/actions/create-assistant/create-assistant.mjs b/components/openai/actions/create-assistant/create-assistant.mjs index da3d212fc2522..c88071a627ecf 100644 --- a/components/openai/actions/create-assistant/create-assistant.mjs +++ b/components/openai/actions/create-assistant/create-assistant.mjs @@ -6,7 +6,7 @@ export default { key: "openai-create-assistant", name: "Create Assistant", description: "Creates an assistant with a model and instructions. [See the documentation](https://platform.openai.com/docs/api-reference/assistants/createAssistant)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { openai, diff --git a/components/openai/actions/create-thread/create-thread.mjs b/components/openai/actions/create-thread/create-thread.mjs index 6047fd0ff7c53..885471417ce58 100644 --- a/components/openai/actions/create-thread/create-thread.mjs +++ b/components/openai/actions/create-thread/create-thread.mjs @@ -6,7 +6,7 @@ export default { key: "openai-create-thread", name: "Create Thread (Assistants)", description: "Creates a thread with optional messages and metadata, and optionally runs the thread using the specified assistant. [See the documentation](https://platform.openai.com/docs/api-reference/threads/createThread)", - version: "0.0.10", + version: "0.0.11", type: "action", props: { openai, diff --git a/components/openai/actions/modify-assistant/modify-assistant.mjs b/components/openai/actions/modify-assistant/modify-assistant.mjs index 9af7ac17a7a1a..6333623d53c1e 100644 --- a/components/openai/actions/modify-assistant/modify-assistant.mjs +++ b/components/openai/actions/modify-assistant/modify-assistant.mjs @@ -6,7 +6,7 @@ export default { key: "openai-modify-assistant", name: "Modify an Assistant", description: "Modifies an existing OpenAI assistant. [See the documentation](https://platform.openai.com/docs/api-reference/assistants/modifyAssistant)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { openai, diff --git a/components/openai/package.json b/components/openai/package.json index 37800efcf05e4..77591f70f54b0 100644 --- a/components/openai/package.json +++ b/components/openai/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/openai", - "version": "0.7.0", + "version": "0.7.1", "description": "Pipedream OpenAI Components", "main": "openai.app.mjs", "keywords": [