๐ญ Crafting Your Own Spells: Creating Custom Personasยถ
Personas are one of CellMageโs most powerful features, allowing you to shape how the LLM behaves by providing tailored system instructions and default parameters. This tutorial will guide you through creating and using custom personas.
๐งฉ What is a Persona?ยถ
A persona in CellMage consists of:
System Instructions: Guidance for how the LLM should behave
Default Parameters: Model settings like temperature, model name, etc.
Metadata: Name, description, and other information about the persona
Personas allow you to quickly switch between different LLM โpersonalitiesโ optimized for different tasks without rewriting your prompts each time.
๐ Persona File Structureยถ
Personas are stored as Markdown files with YAML frontmatter. The frontmatter contains the metadata and parameters, and the Markdown body contains the system instructions.
Hereโs a basic example:
---
name: Python Expert
model: gpt-4o
temperature: 0.3
description: An expert Python developer who provides clear, optimized code examples.
---
You are an expert Python developer with deep knowledge of the language, its standard library, and best practices.
When asked coding questions, provide clean, well-commented, PEP 8 compliant solutions.
Always consider edge cases, performance, and readability.
Explain your reasoning and offer suggestions for improvements.
๐๏ธ Persona Directory Structureยถ
By default, CellMage looks for personas in a directory called llm_personas under your base directory. You can control the base directory for all working files (including personas) using the CELLMAGE_BASE_DIR environment variable:
# Set the base directory for all CellMage working files
export CELLMAGE_BASE_DIR=/path/to/your/project
Personas will then be stored in $CELLMAGE_BASE_DIR/llm_personas.
You can also specify additional persona directories using the CELLMAGE_PERSONAS_DIR and CELLMAGE_PERSONAS_DIRS environment variables (these paths can be absolute or relative to the base directory).
# In your .env file
CELLMAGE_PERSONAS_DIRS=~/global_personas,./project_specific_personas
โจ Creating Your First Custom Personaยถ
Letโs create a simple data analyst persona:
# First, create the personas directory if it doesn't exist
!mkdir -p $CELLMAGE_BASE_DIR/llm_personas
Now create the file $CELLMAGE_BASE_DIR/llm_personas/data_analyst.md:
---
name: Data Analyst
model: gpt-4o
temperature: 0.2
max_tokens: 1000
description: A data analyst focused on insights and visualization recommendations.
---
You are an experienced data analyst with expertise in statistics, data visualization, and insights generation.
When presented with data or data-related questions:
1. Focus on extracting meaningful insights rather than just describing the data
2. Recommend appropriate visualization techniques when relevant
3. Consider statistical validity and potential biases
4. Suggest follow-up analyses that might yield additional insights
5. Use clear language that non-technical stakeholders can understand
Avoid making unfounded claims about causality unless explicitly supported by the data.
๐งช Testing Your Personaยถ
Letโs use our new persona:
# Load the CellMage extension if you haven't already
%load_ext cellmage
# List available personas to confirm yours is detected
%llm_config --list-personas
# Activate your persona
%llm_config --persona data_analyst
# Try it out!
%%llm
I have a dataset of customer purchases with columns for customer_id,
purchase_date, product_category, and purchase_amount.
What insights might I look for and how should I visualize them?
๐ง Advanced Persona Featuresยถ
Persona Parameter Referenceยถ
The YAML frontmatter can include:
Parameter |
Description |
Example Value |
|---|---|---|
|
Display name of the persona |
|
|
Brief description |
|
|
Default model to use |
|
|
Creativity level (0.0-2.0) |
|
|
Maximum response length |
|
|
Nucleus sampling parameter |
|
|
Repetition reduction (0.0-2.0) |
|
|
Topic diversity (0.0-2.0) |
|
|
Stop sequences |
|
Creating Specialized Personasยถ
Here are some ideas for specialized personas:
Code Reviewerยถ
---
name: Code Reviewer
model: gpt-4o
temperature: 0.2
description: Analyzes code for bugs, style issues, and optimizations.
---
You are an expert code reviewer with deep knowledge of software engineering principles.
When reviewing code:
1. Identify potential bugs, edge cases, and error handling issues
2. Point out style inconsistencies and readability problems
3. Suggest performance optimizations when appropriate
4. Look for security vulnerabilities
5. Be constructive and specific in your feedback
Organize your review by issue severity (critical, major, minor).
Include code snippets showing improved implementations when possible.
Creative Writerยถ
---
name: Creative Writer
model: gpt-4o
temperature: 0.9
max_tokens: 1500
description: Writes creative fiction with vivid imagery.
---
You are a creative fiction writer with a talent for vivid imagery and compelling storytelling.
When writing fiction:
1. Focus on sensory details and immersive description
2. Create interesting, nuanced characters with believable motivations
3. Balance dialogue, narration, and description
4. Use varied sentence structure and pacing for emotional effect
5. Maintain a consistent tone and point of view
Adapt your style to match the requested genre while maintaining high quality prose.
๐ก Tips for Effective Personasยถ
Be Specific: The more specific your instructions, the more consistent the personaโs behavior.
Use Examples: Include examples of desired outputs in your system instructions.
Set Boundaries: Clearly define what the persona should and shouldnโt do.
Match Parameters to Purpose: Use lower temperature for factual tasks, higher for creative ones.
Iterative Refinement: If your persona isnโt behaving as expected, refine the instructions based on actual outputs.
๐ Switching Between Personasยถ
You can easily switch between personas during a session:
# Switch to the data analyst
%llm_config --persona data_analyst
# Later, switch to a code reviewer
%llm_config --persona code_reviewer
# And if needed, use a one-time persona just for the next prompt
%%llm -p creative_writer
Write a short story about a data scientist who discovers magic in their code.
๐ง Understanding the Current Personaยถ
To see which persona is active and what its system instructions are:
# Show the current persona
%llm_config --show-persona
๐ Next Stepsยถ
Now that youโve learned how to create and use custom personas, explore:
Using Snippets: Learn how to provide reusable context blocks
Advanced Prompting: Combine personas with advanced prompting techniques
Managing Conversations: Save and manage sessions with different personas