Skip to content

Commit fbbba12

Browse files
authored
feat: chatPPT plugin (#203)
* feat: chatPPT plugin * feat: add course and input placeholder, handle exception * feat: use smaller logo file * chore: simplify throw error out * chore: simplify request * fix: add optional type
1 parent 699e4fb commit fbbba12

File tree

7 files changed

+185
-0
lines changed

7 files changed

+185
-0
lines changed

bun.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@
157157
"typescript": "^5.0.0",
158158
},
159159
},
160+
"modules/tool/packages/chatPPT": {
161+
"name": "@fastgpt-plugins/tool-chat-ppt",
162+
"dependencies": {
163+
"zod": "^3.24.2",
164+
},
165+
"devDependencies": {
166+
"@types/bun": "latest",
167+
},
168+
"peerDependencies": {
169+
"typescript": "^5.0.0",
170+
},
171+
},
160172
"modules/tool/packages/dalle3": {
161173
"name": "fastgpt-tools-dalle3",
162174
"dependencies": {
@@ -750,6 +762,8 @@
750762

751763
"@fastgpt-plugins/tool-base64-decode": ["@fastgpt-plugins/tool-base64-decode@workspace:modules/tool/packages/base64Decode"],
752764

765+
"@fastgpt-plugins/tool-chat-ppt": ["@fastgpt-plugins/tool-chat-ppt@workspace:modules/tool/packages/chatPPT"],
766+
753767
"@fastgpt-plugins/tool-link-memo": ["@fastgpt-plugins/tool-link-memo@workspace:modules/tool/packages/linkMemo"],
754768

755769
"@fastgpt-plugins/tool-mineru": ["@fastgpt-plugins/tool-mineru@workspace:modules/tool/packages/mineru"],
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { defineTool } from '@tool/type';
2+
import { FlowNodeInputTypeEnum, WorkflowIOValueTypeEnum } from '@tool/type/fastgpt';
3+
import { ToolTypeEnum } from '@tool/type/tool';
4+
5+
export default defineTool({
6+
courseUrl: 'https://wiki.yoo-ai.com/api/guide.html',
7+
name: {
8+
'zh-CN': '必优ChatPPT',
9+
en: 'ChatPPT'
10+
},
11+
type: ToolTypeEnum.tools,
12+
description: {
13+
'zh-CN': '必优ChatPPT,一键生成PPT',
14+
en: 'ChatPPT, one-click generate PPT'
15+
},
16+
toolDescription: 'ChatPPT, one-click generate PPT',
17+
secretInputConfig: [
18+
{
19+
key: 'apiKey',
20+
label: 'API Key',
21+
description: '可以在必优官网获取',
22+
required: true,
23+
inputType: 'secret'
24+
}
25+
],
26+
versionList: [
27+
{
28+
value: '0.1.0',
29+
description: 'Default version',
30+
inputs: [
31+
{
32+
key: 'text',
33+
label: '描述文本',
34+
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
35+
valueType: WorkflowIOValueTypeEnum.string,
36+
description: '生成PPT的描述文本',
37+
toolDescription: '生成PPT的描述文本',
38+
placeholder: '描述PPT内容, 如: 生成一个关于人工智能的PPT',
39+
required: true
40+
},
41+
{
42+
key: 'color',
43+
label: '主题色',
44+
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
45+
valueType: WorkflowIOValueTypeEnum.string,
46+
description: 'PPT的主题色',
47+
toolDescription: 'PPT的主题色',
48+
placeholder: '直接填写自然语言描述主题色, 如: 蓝色'
49+
}
50+
],
51+
outputs: [
52+
{
53+
valueType: WorkflowIOValueTypeEnum.string,
54+
key: 'preview_url',
55+
label: 'PPT的预览URL',
56+
description: 'PPT的预览URL'
57+
}
58+
]
59+
}
60+
]
61+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import config from './config';
2+
import { InputType, OutputType, tool as toolCb } from './src';
3+
import { exportTool } from '@tool/utils/tool';
4+
5+
export default exportTool({
6+
toolCb,
7+
InputType,
8+
OutputType,
9+
config
10+
});
8.08 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@fastgpt-plugins/tool-chat-ppt",
3+
"module": "index.ts",
4+
"type": "module",
5+
"scripts": {
6+
"build": "bun ../../../../scripts/build.ts"
7+
},
8+
"devDependencies": {
9+
"@types/bun": "latest"
10+
},
11+
"peerDependencies": {
12+
"typescript": "^5.0.0"
13+
},
14+
"dependencies": {
15+
"zod": "^3.24.2"
16+
}
17+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { z } from 'zod';
2+
import { POST, GET } from '@tool/utils/request';
3+
4+
export const InputType = z.object({
5+
apiKey: z.string(),
6+
text: z.string(),
7+
color: z.string().optional()
8+
});
9+
10+
export const OutputType = z.object({
11+
preview_url: z.string()
12+
});
13+
14+
type CreatePPTResponse = {
15+
id: string;
16+
images_url: {
17+
url: string;
18+
time: number;
19+
}[];
20+
note_status: number;
21+
introduce: string;
22+
ppt_title: string;
23+
page_count: number;
24+
progress: number;
25+
status: number;
26+
first_image_up_at: string;
27+
created_at: string;
28+
updated_at: string;
29+
state_description: string;
30+
process_url: string;
31+
preview_url: string;
32+
};
33+
34+
export async function tool({ apiKey, text, color }: z.infer<typeof InputType>) {
35+
const token = `Bearer ${apiKey}`;
36+
const CHATPPT_BASE_URL = 'https://saas.api.yoo-ai.com';
37+
38+
const createPPTRes = await POST<{ data: { id: string } }>(
39+
`${CHATPPT_BASE_URL}/apps/ppt-create`,
40+
{
41+
text,
42+
color
43+
},
44+
{
45+
headers: {
46+
Authorization: token,
47+
'Content-Type': 'application/json'
48+
}
49+
}
50+
);
51+
const id = createPPTRes?.data?.data?.id;
52+
if (!id || typeof id !== 'string') {
53+
return Promise.reject('Failed to create PPT: empty id');
54+
}
55+
56+
const getPPTUrlRes = await GET<{ data: CreatePPTResponse }>(
57+
`${CHATPPT_BASE_URL}/apps/ppt-result`,
58+
{
59+
params: {
60+
id
61+
},
62+
headers: {
63+
Authorization: token
64+
}
65+
}
66+
);
67+
const preview_url = getPPTUrlRes?.data?.data?.preview_url;
68+
if (!preview_url || typeof preview_url !== 'string') {
69+
return Promise.reject('Failed to fetch PPT preview url');
70+
}
71+
72+
return {
73+
preview_url
74+
};
75+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { expect, test } from 'vitest';
2+
import tool from '..';
3+
4+
test(async () => {
5+
expect(tool.name).toBeDefined();
6+
expect(tool.description).toBeDefined();
7+
expect(tool.cb).toBeDefined();
8+
});

0 commit comments

Comments
 (0)