@pipedream/openai 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ export default {
8
8
  key: "openai-analyze-image-content",
9
9
  name: "Analyze Image Content",
10
10
  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)",
11
- version: "0.1.1",
11
+ version: "0.1.2",
12
12
  type: "action",
13
13
  props: {
14
14
  openai,
@@ -6,7 +6,7 @@ import { ConfigurationError } from "@pipedream/platform";
6
6
  export default {
7
7
  ...common,
8
8
  name: "Chat",
9
- version: "0.2.2",
9
+ version: "0.2.3",
10
10
  key: "openai-chat",
11
11
  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)",
12
12
  type: "action",
@@ -57,19 +57,87 @@ export default {
57
57
  optional: true,
58
58
  reloadProps: true,
59
59
  },
60
+ toolTypes: {
61
+ type: "string[]",
62
+ label: "Tool Types",
63
+ description: "The types of tools to enable on the assistant",
64
+ options: constants.TOOL_TYPES.filter((toolType) => toolType === "function"),
65
+ optional: true,
66
+ reloadProps: true,
67
+ },
60
68
  },
61
69
  additionalProps() {
62
- const { responseFormat } = this;
63
- if (responseFormat !== constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
64
- return {};
65
- }
66
- return {
67
- jsonSchema: {
70
+ const {
71
+ responseFormat,
72
+ toolTypes,
73
+ numberOfFunctions,
74
+ } = this;
75
+ const props = {};
76
+
77
+ if (responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
78
+ props.jsonSchema = {
68
79
  type: "string",
69
80
  label: "JSON Schema",
70
81
  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).",
71
- },
72
- };
82
+ };
83
+ }
84
+
85
+ if (toolTypes?.includes("function")) {
86
+ props.numberOfFunctions = {
87
+ type: "integer",
88
+ label: "Number of Functions",
89
+ description: "The number of functions to define",
90
+ optional: true,
91
+ reloadProps: true,
92
+ default: 1,
93
+ };
94
+
95
+ for (let i = 0; i < (numberOfFunctions || 1); i++) {
96
+ props[`functionName_${i}`] = {
97
+ type: "string",
98
+ label: `Function Name ${i + 1}`,
99
+ 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.",
100
+ };
101
+ props[`functionDescription_${i}`] = {
102
+ type: "string",
103
+ label: `Function Description ${i + 1}`,
104
+ description: "A description of what the function does, used by the model to choose when and how to call the function.",
105
+ optional: true,
106
+ };
107
+ props[`functionParameters_${i}`] = {
108
+ type: "object",
109
+ label: `Function Parameters ${i + 1}`,
110
+ 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.",
111
+ optional: true,
112
+ };
113
+ }
114
+ }
115
+
116
+ return props;
117
+ },
118
+ methods: {
119
+ ...common.methods,
120
+ _buildTools() {
121
+ const tools = this.toolTypes?.filter((toolType) => toolType !== "function")?.map((toolType) => ({
122
+ type: toolType,
123
+ })) || [];
124
+ if (this.toolTypes?.includes("function")) {
125
+ const numberOfFunctions = this.numberOfFunctions || 1;
126
+ for (let i = 0; i < numberOfFunctions; i++) {
127
+ tools.push({
128
+ type: "function",
129
+ function: {
130
+ name: this[`functionName_${i}`],
131
+ description: this[`functionDescription_${i}`],
132
+ parameters: this[`functionParameters_${i}`],
133
+ },
134
+ });
135
+ }
136
+ }
137
+ return tools.length
138
+ ? tools
139
+ : undefined;
140
+ },
73
141
  },
74
142
  async run({ $ }) {
75
143
  if (this.audio && !this.modelId.includes("gpt-4o-audio-preview")) {
@@ -80,7 +148,10 @@ export default {
80
148
 
81
149
  const response = await this.openai.createChatCompletion({
82
150
  $,
83
- data: args,
151
+ data: {
152
+ ...args,
153
+ tools: this._buildTools(),
154
+ },
84
155
  });
85
156
 
86
157
  if (response) {
@@ -6,7 +6,7 @@ export default {
6
6
  key: "openai-chat-with-assistant",
7
7
  name: "Chat with Assistant",
8
8
  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)",
9
- version: "0.0.6",
9
+ version: "0.0.7",
10
10
  type: "action",
11
11
  props: {
12
12
  openai,
@@ -16,7 +16,20 @@ export default {
16
16
  if (!this.toolTypes?.length) {
17
17
  return props;
18
18
  }
19
- return this.getToolProps();
19
+ if (this.toolTypes.includes("function")) {
20
+ props.numberOfFunctions = {
21
+ type: "integer",
22
+ label: "Number of Functions",
23
+ description: "The number of functions to define.",
24
+ optional: true,
25
+ reloadProps: true,
26
+ default: 1,
27
+ };
28
+ }
29
+ return {
30
+ ...props,
31
+ ...(await this.getToolProps()),
32
+ };
20
33
  },
21
34
  methods: {
22
35
  async getToolProps() {
@@ -58,23 +71,26 @@ export default {
58
71
  };
59
72
  }
60
73
  if (this.toolTypes.includes("function")) {
61
- props.functionName = {
62
- type: "string",
63
- label: "Function Name",
64
- 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.",
65
- };
66
- props.functionDescription = {
67
- type: "string",
68
- label: "Function Description",
69
- description: "A description of what the function does, used by the model to choose when and how to call the function.",
70
- optional: true,
71
- };
72
- props.functionParameters = {
73
- type: "object",
74
- label: "Function Parameters",
75
- 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.",
76
- optional: true,
77
- };
74
+ const numberOfFunctions = this.numberOfFunctions || 1;
75
+ for (let i = 0; i < numberOfFunctions; i++) {
76
+ props[`functionName_${i}`] = {
77
+ type: "string",
78
+ label: `Function Name ${i + 1}`,
79
+ 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.",
80
+ };
81
+ props[`functionDescription_${i}`] = {
82
+ type: "string",
83
+ label: `Function Description ${i + 1}`,
84
+ description: "A description of what the function does, used by the model to choose when and how to call the function.",
85
+ optional: true,
86
+ };
87
+ props[`functionParameters_${i}`] = {
88
+ type: "object",
89
+ label: `Function Parameters ${i + 1}`,
90
+ 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.",
91
+ optional: true,
92
+ };
93
+ }
78
94
  }
79
95
  return props;
80
96
  },
@@ -83,14 +99,17 @@ export default {
83
99
  type: toolType,
84
100
  })) || [];
85
101
  if (this.toolTypes?.includes("function")) {
86
- tools.push({
87
- type: "function",
88
- function: {
89
- name: this.functionName,
90
- description: this.functionDescription,
91
- parameters: this.functionParameters,
92
- },
93
- });
102
+ const numberOfFunctions = this.numberOfFunctions || 1;
103
+ for (let i = 0; i < numberOfFunctions; i++) {
104
+ tools.push({
105
+ type: "function",
106
+ function: {
107
+ name: this[`functionName_${i}`],
108
+ description: this[`functionDescription_${i}`],
109
+ parameters: this[`functionParameters_${i}`],
110
+ },
111
+ });
112
+ }
94
113
  }
95
114
  return tools.length
96
115
  ? tools
@@ -6,7 +6,7 @@ export default {
6
6
  key: "openai-create-assistant",
7
7
  name: "Create Assistant",
8
8
  description: "Creates an assistant with a model and instructions. [See the documentation](https://platform.openai.com/docs/api-reference/assistants/createAssistant)",
9
- version: "0.1.8",
9
+ version: "0.1.9",
10
10
  type: "action",
11
11
  props: {
12
12
  openai,
@@ -6,7 +6,7 @@ export default {
6
6
  key: "openai-create-thread",
7
7
  name: "Create Thread (Assistants)",
8
8
  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)",
9
- version: "0.0.10",
9
+ version: "0.0.11",
10
10
  type: "action",
11
11
  props: {
12
12
  openai,
@@ -6,7 +6,7 @@ export default {
6
6
  key: "openai-modify-assistant",
7
7
  name: "Modify an Assistant",
8
8
  description: "Modifies an existing OpenAI assistant. [See the documentation](https://platform.openai.com/docs/api-reference/assistants/modifyAssistant)",
9
- version: "0.1.8",
9
+ version: "0.1.9",
10
10
  type: "action",
11
11
  props: {
12
12
  openai,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/openai",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Pipedream OpenAI Components",
5
5
  "main": "openai.app.mjs",
6
6
  "keywords": [