๐Ÿ“ Documentation Guideยถ

This guide explains how to write documentation for CellMage, with a focus on code examples and formatting.

๐Ÿงฉ Markdown Structureยถ

CellMage documentation uses MyST Markdown, which is an extension of standard Markdown with additional features for technical documentation.

Headers Structureยถ

  • # Level 1 - Top-level page title

  • ## Level 2 - Major sections

  • ### Level 3 - Subsections

  • #### Level 4 - Additional headings as needed

๐Ÿ“Š Code Blocks and Examplesยถ

When including code examples:

For IPython/Magic Command Examplesยถ

%%llm
What is the capital of France?

Notice that weโ€™re using the ipython language specifier above, not python. This is critical for all code blocks containing:

  • Magic commands (%llm_config, %%llm, etc.)

  • Question marks in prompts

  • Dollar signs (e.g., in financial examples)

  • Exclamation marks for shell commands

  • Triple backtick code blocks within code blocks

For Regular Python Codeยถ

def calculate_metrics(data):
    """Calculate basic statistics on the data."""
    return {
        "mean": sum(data) / len(data),
        "max": max(data),
        "min": min(data)
    }

For Shell Commandsยถ

pip install cellmage

๐ŸŽญ Including Personas and Snippets Examplesยถ

When documenting the creation of persona or snippet files:

Create a file `llm_personas/data_analyst.md`:

```markdown
---
name: Data Analyst
model: gpt-4o
temperature: 0.3
---
You are a data analyst expert who specializes in interpreting data, finding patterns,
and creating visualizations to communicate insights.
```

๐Ÿ–ผ๏ธ Including Imagesยถ

To include images:

![CellMage Workflow](../_static/images/cellmage_workflow.png)

๐Ÿ“‹ Tablesยถ

Tables are created with pipe syntax:

| Parameter | Description | Default |
|-----------|-------------|---------|
| `model` | The LLM model to use | `gpt-4o-mini` |
| `temperature` | Creativity setting | 0.7 |

๐Ÿง  Tips for Clear Documentationยถ

  1. Start with a clear introduction - Explain what the page covers and who itโ€™s for.

  2. Use consistent terminology - Stick to the same terms throughout.

  3. Progressive disclosure - Start with simple examples, then show more complex ones.

  4. Show real-world use cases - Demonstrate practical applications.

  5. Include error handling - Show what happens when things go wrong.

  6. Use callouts for important notes - Highlight key information.

Callout Exampleยถ

โš ๏ธ Warning: Make sure you have set your API key before running this command.

๐Ÿ”„ Fixing Lexer Errors in Documentationยถ

If you encounter syntax highlighting errors when building the documentation:

  1. For code blocks with CellMage magic commands, use ipython instead of python:

    ```ipython
    %%llm
    What is the capital of France?
    ```
    
  2. For nested code blocks (code inside code examples), add an extra level of backticks:

    ````ipython
    %%llm
    ```ipython
    def example():
        return "This is nested code"
    ```
    ````
    
  3. If you still encounter errors, consider using plain text blocks that donโ€™t attempt syntax highlighting:

    ```text
    %llm_config --model gpt-4o
    ```
    

Common Symbols Causing Lexer Errorsยถ

The following characters/symbols often cause lexer errors in Python code blocks but work correctly with ipython language specifier:

Symbol

Example

Solution

Question marks (?)

%%llm What is the capital of France?

Use ipython language

Dollar signs ($)

Price: $25.99

Use ipython language

Exclamation marks (!)

!pip install cellmage

Use ipython language

Triple backticks (```)

Code blocks inside prompts

Add extra backtick level

Mathematical symbols (ยฒ, ฯ€)

O(nยฒ) complexity

Use ipython or text

Adding Code Examples to Documentationยถ

When adding example code blocks to tutorials:

  1. For magic commands and prompts with questions:

    ```ipython
    %%llm
    Compare the advantages of SQL and NoSQL databases?
    ```
    
  2. For shell commands in IPython:

    ```ipython
    !mkdir -p llm_snippets
    !pip install "cellmage[all]"
    ```
    
  3. For data that contains special characters:

    ```ipython
    %%llm
    The price dropped from $50 to $42.50. What's the percentage decrease?
    ```
    

Including Documentation in TOCยถ

Make sure your documentation files are included in a table of contents (toctree) in an appropriate parent file. For example, to include this guide in the developer documentation toctree, add it to docs/source/developer/index.md:

```{toctree}
:maxdepth: 2
documentation_guide