I’m working on a project that uses Claude to dynamically create powerpoint presentations and this entire project:
The source files, package.json, tsconfig.json, .env, .gitignore, and README.md files were created from this convo file as a seed:
Section: Initialize Presentation Generation
To initialize presentation generation:
Load stored api_key from a secure source.
Read the contents of "topic.txt" into a variable called presentation_data.
Read the contents of "theme.json" into a variable called presentation_theme.
Read the contents of "templates.json" into a variable called slide_templates.
Set up the system prompt as follows:
```
<CONTEXT>
Date: ${current date in ISO format}
<PRESENTATION_THEME>
${presentation_theme}
<SLIDE_TEMPLATES>
${slide_templates}
<PRESENTATION_SCHEMA>
{"title":"<presentation title>","layout":"wide","sections":[{"id":"<section_id>","title":"<section title>","slides":[]}]}
<PRESENTATION_INSTRUCTIONS>
Long lists should be split across multiple slides to avoid being truncated.
Markdown blocks only support bulleted & numbered lists, bold, and italics.
<PRESENTATION_DATA>
${presentation_data}
```
Define an empty JSON structure called presentation_schema that follows <PRESENTATION_SCHEMA> format.
Initialize presentation_schema with a title of "Generated Presentation", layout "wide", and an empty sections list.
Section: Generate Presentation Outline
To generate presentation outline:
Define a user message saying:
"Let's create a presentation for the provided PRESENTATION_DATA as a JSON object that follows the PRESENTATION_SCHEMA. We'll use the PRESENTATION_INSTRUCTIONS and the provided PRESENTATION_THEME and SLIDE_TEMPLATES when generating slides. Before creating the presentation, let's start by creating an outline of the presentation we want to create."
Call "send message to Claude with model 'claude-3-5-sonnet-20241022', using message content that returns text" with the user message.
Capture the response from Claude as outline_text.
Add outline_text to the conversation history.
Note: outline_text serves as a guide for Claude's slide generation in subsequent steps.
Section: Slide Generation Loop
To generate all slides:
Define a variable called completed with a value of False.
While completed is not True, perform the following steps:
If this is the first iteration, define a user message saying:
"We'll need to create the presentation in chunks. Let's start by creating the first set of slides as a complete presentation object. Return <DONE> after the last section is returned."
Otherwise, define a user message saying:
"Return the next set of slides as a complete presentation object. The slides will be merged into the existing presentation. Return <DONE> after the last set of slides is returned."
Call "send message to Claude with model 'claude-3-5-sonnet-20241022', using message content that returns JSON" with the user message and conversation history.
Capture the JSON response from Claude as slide_chunk.
Check if the response contains "<DONE>":
If "<DONE>" is found, set completed to True.
Remove "<DONE>" from slide_chunk to clean the JSON.
Extract the "sections" list from slide_chunk and append each section to the "sections" list in presentation_schema.
Add the JSON response from Claude (slide_chunk) to the conversation history as:
"```JSON\n<slide_chunk JSON>\n```"
Section: Save and Convert
To save final JSON and convert to PPTX:
Write presentation_schema to a file named "output.pptx.json".
Call convertToPptx("output.pptx.json", "output.pptx").
Note: This function converts the JSON schema to a PowerPoint file using predefined logic.
Section: Re-Generate PPTX from Existing JSON
To regenerate PPTX from existing JSON:
Check if "output.pptx.json" exists.
If it exists,
Load "output.pptx.json" into presentation_schema.
Call convertToPptx("output.pptx.json", "output.pptx").
Display "Regeneration complete. The file output.pptx has been updated."
Otherwise,
Display "Error: output.pptx.json not found. Please run the presentation generation process first."
Section: Main Program Flow
To create presentation from input files:
Check if the "--regenerate" flag is passed as a command line argument.
If "--regenerate" flag is passed,
Call regenerate PPTX from existing JSON.
Otherwise,
Call initialize presentation generation.
Call generate presentation outline.
Call generate all slides.
Call save final JSON and convert to PPTX.
Display "Presentation generation complete. The file output.pptx has been created."
Section: Claude Sonnet Model Calls
To send message to Claude with model "claude-3-5-sonnet-20241022", using message content that returns text:
Make an HTTP POST request to "https://api.anthropic.com/v1/messages".
Set headers to:
x-api-key as stored api_key,
anthropic-version as "2023-06-01",
content-type as "application/json".
Set the body of the request to:
```
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 8182,
"system": "<system prompt>",
"messages": [
{"role": "user", "content": "<user message>"},
... conversation history
]
}
```
Return the response from Claude.
To send message to Claude with model "claude-3-5-sonnet-20241022", using message content that returns JSON:
Make an HTTP POST request to "https://api.anthropic.com/v1/messages".
Set headers to:
x-api-key as stored api_key,
anthropic-version as "2023-06-01",
content-type as "application/json".
Use the "assistant prefill" support of Claude to condition to return JSON.
Set the body of the request to:
```
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 8182,
"system": "<system prompt>",
"messages": [
{"role": "user", "content": "<user message>"},
{"role": "assistant", "content": "```JSON"},
... conversation history
]
}
```
Parse the response by extracting everything up to the closing ``` and then parse as JSON.
Return the response from Claude.
The conversation history should be updated to include the returned JSON object formatted as "```JSON\n${object}\n```"
I ran Sonnet in an agentic loop to design the project and then write all of the files. I just compiled things and fed errors and bugs back into sonnet for debugging. It took an hour or two but Sonnet got everything to a working state without me having to directly touch a line of code. I ended up re-writing its logic for parsing JSON responses from the model to be less brittle but the bulk of the code Sonnet wrote and thanks to the convo program i gave it as input it was super close functionality wise on the first shot.
Here’s an example of the types of presentations it can generate…
I just simply asked for a presentation to update me on the elections. ** The data comes from my reasoning engine, Awareness. This is just a new artifact projection for that data.