Context: I explored "AI-first documentation" as a prompt engineering strategy to get an AI to write and edit code that represents math and programming diagrams. In my case, the AI used a python library still-manim, which has associated docs.
In my approach, the unique features of AI-first documentation are:
Here's my approach in more detail:
gpt-4o
doesn't have my custom library still-manim in its weights, so I must inject the relevant info into the context (RAG).
Unlike typical RAG, the RAG strategy I use does not using embeddings.
For smaller text corpuses an AI can be used for retrieval too, not just generation.
mdx
files for these filenames.mdx
files injected into its context, the AI generates a final plan and SEARCH/REPLACE code blocks to execute this plan (see an example of these blocks below)Notes:
Here is a high-level overview of the prompts as of 5/31/24:
Planning Prompt:
"""
SMANIM CHEATSHEET:
...
DIAGRAM CODE:
...
SELECTED MOBJECTS (which the user likely refers to in their instruction):
0. A vmobject mobject, accessed as `graph.vertices[2]`, defined on line 6
1. A vmobject mobject, accessed as `graph.vertices[3]`, defined on line 6
USER INSTRUCTION:
set these to red
"""
Planning Result:
"""
Plan:
Access the vertices 2 and 3 from the graph and use the `set_color` method to set their color to red.
Relevant Files:
- graph.mdx
- mobject-overview.mdx
"""
(Cheatsheet, graph.mdx, mobject-overview.mdx)
Editing Prompt:
"""
SMANIM DOCUMENTATION:
...
DIAGRAM CODE:
...
SELECTED MOBJECTS (which the user likely refers to in their instruction):
0. A vmobject mobject, accessed as `graph.vertices[2]`, defined on line 6
1. A vmobject mobject, accessed as `graph.vertices[3]`, defined on line 6
USER INSTRUCTION:
set these to red
INITIAL PLAN:
Access the vertices 2 and 3 from the graph and use the `set_color` method to set their color to red.
"""
Editing Result:
"""
test
### Updated Plan:
1. Access the vertices 2 and 3 from the graph.
2. Use the `set_color` method to set their color to red.
3. Add the modified vertices back to the canvas to ensure the changes are rendered.
Now let's implement this updated plan with SEARCH/REPLACE blocks:
'''python
# ==== SEARCH START ====
canvas.add(graph)
# ==== SEARCH END ====
# ==== REPLACE START ====
graph.vertices[2].set_color(RED)
graph.vertices[3].set_color(RED)
canvas.add(graph)
# ==== REPLACE END ====
'''
"""
The docs serve mdx
files, not just HTML files.
mdx
files are well-structured with clear headings, code blocks, lists, etc.Each mdx
file covers either a concept or an overview and these pages types each have a consistent layout.
The docs generate a total overview that reasonably fits into a single AI context window.
mdx
file (since AIs are familiar with mdx
files).