Skip to content
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.1",
version: "0.1.2",
type: "action",
props: {
openai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
91 changes: 81 additions & 10 deletions components/openai/actions/chat/chat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")) {
Expand All @@ -80,7 +148,10 @@ export default {

const response = await this.openai.createChatCompletion({
$,
data: args,
data: {
...args,
tools: this._buildTools(),
},
});

if (response) {
Expand Down
71 changes: 45 additions & 26 deletions components/openai/actions/common/common-assistants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
},
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/actions/create-thread/create-thread.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/openai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/openai",
"version": "0.7.0",
"version": "0.7.1",
"description": "Pipedream OpenAI Components",
"main": "openai.app.mjs",
"keywords": [
Expand Down
Loading