Skip to content

Commit 37de5d2

Browse files
committed
fix: address PR feedback (JSON output, docstrings, extensions)
1 parent 3d0228d commit 37de5d2

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

camel/toolkits/pptx_node_toolkit.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,41 @@ def create_presentation(
5656
filename: str,
5757
) -> str:
5858
r"""Create a PowerPoint presentation (PPTX) file using PptxGenJS.
59+
60+
The filename MUST end with ".pptx". If it does not, the toolkit will
61+
automatically append it, but the agent should strive to provide the
62+
correct extension.
5963
6064
Args:
6165
content (str): The content to write to the PPTX file as a JSON
62-
string.
63-
filename (str): The name or path of the file.
66+
string. It must be a list of dictionaries representing slides.
67+
68+
JSON Schema Example:
69+
[
70+
{
71+
"title": "Main Title",
72+
"subtitle": "Subtitle text"
73+
},
74+
{
75+
"heading": "Slide Heading",
76+
"bullet_points": [
77+
"Point 1",
78+
"Point 2"
79+
]
80+
},
81+
{
82+
"heading": "Table Slide",
83+
"table": {
84+
"headers": ["Col 1", "Col 2"],
85+
"rows": [["A", "B"], ["C", "D"]]
86+
}
87+
}
88+
]
89+
filename (str): The name of the file to save. MUST end in .pptx.
6490
6591
Returns:
66-
str: A success message indicating the file was created.
92+
str: A JSON string containing the result status, file path, and
93+
number of slides generated.
6794
"""
6895
if not filename.lower().endswith('.pptx'):
6996
filename += '.pptx'
@@ -90,12 +117,20 @@ def create_presentation(
90117
text=True,
91118
check=True
92119
)
93-
res = result.stdout.strip()
94-
return res
120+
121+
# Parse JSON output from script
122+
try:
123+
script_output = json.loads(result.stdout.strip())
124+
if script_output.get("success"):
125+
return f"Presentation created successfully. Path: {script_output.get('path')}, Slides: {script_output.get('slides')}"
126+
else:
127+
return f"Error creating presentation: {script_output.get('error')}"
128+
except json.JSONDecodeError:
129+
return f"Error parsing script output: {result.stdout.strip()}"
95130

96131
except subprocess.CalledProcessError as e:
97132
logger.error(f"Error creating presentation: {e.stderr}")
98-
return f"Error creating presentation: {e.stderr}"
133+
return f"Error creating presentation subprocess: {e.stderr}"
99134
except Exception as e:
100135
logger.error(f"Error creating presentation: {str(e)}")
101136
return f"Error creating presentation: {str(e)}"

camel/toolkits/scripts/generate_pptx.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,18 @@ if (Array.isArray(slidesData)) {
7171
// Save File
7272
pres.writeFile({ fileName: filename })
7373
.then((fileName) => {
74-
console.log(`PowerPoint presentation successfully created: ${fileName}`);
74+
const result = {
75+
success: true,
76+
path: fileName,
77+
slides: Array.isArray(slidesData) ? slidesData.length : 0
78+
};
79+
console.log(JSON.stringify(result));
7580
})
7681
.catch((err) => {
77-
console.error("Error saving file:", err);
82+
const result = {
83+
success: false,
84+
error: err.toString()
85+
};
86+
console.log(JSON.stringify(result));
7887
process.exit(1);
7988
});

0 commit comments

Comments
 (0)