Skip to content

Commit 5f26519

Browse files
luancazarinecoderabbitai[bot]vunguyenhung
authored
13311 components customgptai (#19112)
* Implement CustomGPT component enhancements: added new actions for creating projects and conversations, sending messages, and emitting events for new conversations and messages. Updated app structure with new prop definitions and methods for improved functionality. Bump version to 0.1.0 in package.json and added necessary dependencies. * pnpm update * Update components/customgpt/actions/create-project/create-project.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Refactor create-project and send-message actions: removed unused streamToBuffer method in create-project and added conditional checks for appending data in send-message to prevent undefined values. * Make `prompt` prop required --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Leo Vu <vunguyenhung@outlook.com>
1 parent b6ee3e0 commit 5f26519

File tree

12 files changed

+564
-6
lines changed

12 files changed

+564
-6
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import customgpt from "../../customgpt.app.mjs";
2+
3+
export default {
4+
key: "customgpt-create-conversation",
5+
name: "Create Conversation",
6+
description: "Create a new conversation for an agent (formerly known as project) identified by its unique projectId. [See the documentation](https://docs.customgpt.ai/reference/post_api-v1-projects-projectid-conversations)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
customgpt,
16+
projectId: {
17+
propDefinition: [
18+
customgpt,
19+
"projectId",
20+
],
21+
},
22+
name: {
23+
type: "string",
24+
label: "Name",
25+
description: "The name of the conversation",
26+
},
27+
},
28+
async run({ $ }) {
29+
const response = await this.customgpt.createConversation({
30+
$,
31+
projectId: this.projectId,
32+
data: {
33+
name: this.name,
34+
},
35+
});
36+
37+
$.export("$summary", `Successfully created conversation with ID "${response.data.project_id}"`);
38+
39+
return response;
40+
},
41+
};
42+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { getFileStreamAndMetadata } from "@pipedream/platform";
2+
import FormData from "form-data";
3+
import customgpt from "../../customgpt.app.mjs";
4+
5+
export default {
6+
key: "customgpt-create-project",
7+
name: "Create Project (Agent)",
8+
description: "Create a new agent by importing data either from a sitemap or an uploaded file. The system will process the provided data and generate a new agent based on the imported or uploaded information. [See the documentation](https://docs.customgpt.ai/reference/post_api-v1-projects)",
9+
version: "0.0.1",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: false,
14+
},
15+
type: "action",
16+
props: {
17+
customgpt,
18+
name: {
19+
type: "string",
20+
label: "Project Name",
21+
description: "The name of the project (agent)",
22+
},
23+
sitemapPath: {
24+
type: "string",
25+
label: "Sitemap Path",
26+
description: "The path to the sitemap path to import data from. This is an optional prop and can be omitted if you want to upload a file instead.",
27+
optional: true,
28+
},
29+
file: {
30+
type: "string",
31+
label: "File Path",
32+
description: "The path to the file saved to the `/tmp` directory (e.g. `tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).",
33+
optional: true,
34+
},
35+
},
36+
async run({ $ }) {
37+
if (this.sitemapPath && this.file) {
38+
$.export("$error", "You cannot use both sitemap path and file at the same time.");
39+
return;
40+
}
41+
42+
const data = new FormData();
43+
data.append("project_name", this.name);
44+
if (this.sitemapPath) data.append("sitemap_path", this.sitemapPath);
45+
if (this.file) {
46+
const {
47+
stream, metadata,
48+
} = await getFileStreamAndMetadata(this.file);
49+
data.append("file", stream, {
50+
filename: metadata.name,
51+
contentType: metadata.contentType,
52+
knownLength: metadata.size,
53+
});
54+
}
55+
56+
const response = await this.customgpt.createProject({
57+
$,
58+
maxBodyLength: Infinity,
59+
data,
60+
headers: data.getHeaders(),
61+
});
62+
63+
$.export(
64+
"$summary",
65+
`Successfully created project with ID: "${response.data.id}"`,
66+
);
67+
68+
return response;
69+
},
70+
};
71+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { getFileStreamAndMetadata } from "@pipedream/platform";
2+
import FormData from "form-data";
3+
import {
4+
CHATBOT_MODEL_OPTIONS,
5+
RESPONSE_SOURCE_OPTIONS,
6+
} from "../../common/constants.mjs";
7+
import customgpt from "../../customgpt.app.mjs";
8+
9+
export default {
10+
key: "customgpt-send-message",
11+
name: "Send Message",
12+
description: "Sends a message to an existing conversation within a project. [See the documentation](https://docs.customgpt.ai/reference/post_api-v1-projects-projectid-conversations-sessionid-messages)",
13+
version: "0.0.1",
14+
annotations: {
15+
destructiveHint: false,
16+
openWorldHint: true,
17+
readOnlyHint: false,
18+
},
19+
type: "action",
20+
props: {
21+
customgpt,
22+
projectId: {
23+
propDefinition: [
24+
customgpt,
25+
"projectId",
26+
],
27+
},
28+
conversationId: {
29+
propDefinition: [
30+
customgpt,
31+
"conversationId",
32+
({ projectId }) => ({
33+
projectId,
34+
fieldId: "session_id",
35+
}),
36+
],
37+
},
38+
externalId: {
39+
type: "string",
40+
label: "External ID",
41+
description: "The external ID of the message",
42+
optional: true,
43+
},
44+
prompt: {
45+
type: "string",
46+
label: "Prompt",
47+
description: "Prompt to send to OpenAI",
48+
},
49+
customPersona: {
50+
type: "string",
51+
label: "Custom Persona",
52+
description: "Custom persona to use for the conversation",
53+
optional: true,
54+
},
55+
chatbotModel: {
56+
type: "string",
57+
label: "Chatbot Model",
58+
description: "The model to use for the conversation",
59+
options: CHATBOT_MODEL_OPTIONS,
60+
},
61+
responseSource: {
62+
type: "string",
63+
label: "Response Source",
64+
description: "By default, CustomGPT asks ChatGPT to use only your content in its response (recommended). If you wish ChatGPT to improvise and use its own knowledgebase as well, you can set this to \"openai_content\".",
65+
options: RESPONSE_SOURCE_OPTIONS,
66+
},
67+
customContent: {
68+
type: "string",
69+
label: "Custom Content",
70+
description: "Custom content to use for the conversation",
71+
optional: true,
72+
},
73+
file: {
74+
type: "string",
75+
label: "File Path",
76+
description: "The path to the file saved to the `/tmp` directory (e.g. `tmp/example.pdf`). Allowed types: **pdf, docx, doc, odt, txt, jpg, jpeg, png, webp**. [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).",
77+
optional: true,
78+
},
79+
},
80+
async run({ $ }) {
81+
const data = new FormData();
82+
if (this.prompt) data.append("prompt", this.prompt);
83+
if (this.customPersona) data.append("custom_persona", this.customPersona);
84+
data.append("chatbot_model", this.chatbotModel);
85+
data.append("response_source", this.responseSource);
86+
if (this.customContent) data.append("custom_content", this.customContent);
87+
88+
if (this.file) {
89+
const {
90+
stream, metadata,
91+
} = await getFileStreamAndMetadata(this.file);
92+
data.append("file", stream, {
93+
filename: metadata.name,
94+
contentType: metadata.contentType,
95+
});
96+
}
97+
const response = await this.customgpt.sendMessage({
98+
$,
99+
conversationId: this.conversationId,
100+
projectId: this.projectId,
101+
data,
102+
headers: data.getHeaders(),
103+
params: {
104+
external_id: this.externalId,
105+
},
106+
});
107+
108+
$.export("$summary", `Successfully sent message to conversation ${this.conversationId}`);
109+
110+
return response;
111+
},
112+
};
113+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const CHATBOT_MODEL_OPTIONS = [
2+
"gpt-4-o",
3+
"gpt-5-chat",
4+
"gpt-4-1",
5+
"gpt-4o-mini",
6+
"gpt-4-1-mini",
7+
"claude-4.5-sonnet",
8+
"claude-4-sonnet",
9+
"claude-3.5-haiku",
10+
"claude-3.5-sonnet",
11+
"gpt-o4-mini-low",
12+
"gpt-o4-mini-medium",
13+
"gpt-o4-mini-high",
14+
];
15+
16+
export const RESPONSE_SOURCE_OPTIONS = [
17+
"default",
18+
"own_content",
19+
"openai_content",
20+
];

0 commit comments

Comments
 (0)