Prompt con ruoli e persona
Scopra come assegnare ruoli o persona specifici agli LLM per guidarne le risposte e generare output più pertinenti.
Prompt con ruoli e persona è una lezione Prompt Engineering & LLM Optimization for Developers gratuita su CoddyKit. Questa è la lezione 1 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Prompt Engineering & LLM Optimization for Developers, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Prompt Engineering & LLM Optimization for Developers include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Intro: Role-Playing Prompts
Welcome to Role-Playing & Persona Prompts! This technique helps you guide Large Language Models (LLMs) to generate more specific and relevant outputs.
Think of it as giving the LLM a job description before it starts working on your request.
What are Persona Prompts?
A persona prompt assigns a specific identity, role, or character to an LLM. This can include:
- An expert (e.g., 'senior software engineer')
- A specific type of assistant (e.g., 'friendly travel agent')
- A fictional character (e.g., 'wise old wizard')
- A specific interface (e.g., 'Linux terminal')
By defining a persona, you influence the LLM's tone, style, and even its knowledge focus.
Why Use Persona Prompts?
Using personas offers several key advantages:
- Consistent Output: Ensures the LLM maintains a specific tone and style throughout the conversation.
- Targeted Knowledge: Helps the LLM focus on relevant information for the assigned role.
- Improved Relevance: Generates answers tailored to the perspective of the persona.
- Controlled Format: Can guide the LLM to output information in a specific structure.
Crafting a Role Statement
To assign a role, simply state it clearly at the beginning of your prompt. Use phrases like:
Act as a [role]...You are a [role]...Simulate a [role]...
Be explicit about the role and any key characteristics.
Example: The Expert Engineer
Here's how you might prompt an LLM to act as a senior software engineer. Notice how the role sets the context for the advice.
Act as a senior software engineer.
Explain the importance of code readability for junior developers in a simple way.Run: Expert Engineer Prompt
Let's see this in action! This Python snippet simulates sending a prompt to an LLM API. The key is the 'engineer_prompt' string.
import os
def get_llm_response(prompt_text):
# In a real app, this would be an actual API call (e.g., OpenAI, Anthropic)
print(f"--- Sending Prompt ---\n{prompt_text}\n--- LLM Response (simulated) ---")
if "senior software engineer" in prompt_text.lower():
return "As a senior software engineer, I'd say good variable names are key for readable code. Also, break down complex functions into smaller, focused units. It makes maintenance and collaboration much easier!"
else:
return "I processed your request."
def main():
engineer_prompt = (
"Act as a senior software engineer. "
"Explain the importance of clean code in a simple way."
)
print("Engineer's advice:")
print(get_llm_response(engineer_prompt))
if __name__ == "__main__":
main()Example: The Creative Storyteller
Personas aren't just for experts! You can also use them for creative tasks. Here, we'll ask the LLM to act as a storyteller.
You are a whimsical storyteller. Write a very short tale about a tiny robot who dreams of flying, using no more than 50 words.Combining Roles & Constraints
You can make persona prompts even more powerful by adding specific constraints or instructions. For example:
Act as a JSON API that returns user data. Only output JSON.You are a helpful coding assistant. Provide Python code examples only.Simulate a debugging console. Only respond with error messages and suggestions.
This ensures both the role and the desired output format are met.
Best Practices for Personas
To get the most out of persona prompts:
- Be Specific: A clear role is better than a vague one.
- Keep it Concise: Don't overload the role description.
- Test & Iterate: Experiment to see which roles work best for your task.
- Avoid Over-constraining: Give the LLM enough room to generate useful responses within the role.
Quick Check: Persona Power
You've learned about the power of persona prompts. Which of the following are key benefits of assigning a role to an LLM?
Recap: Mastering Personas
Great job! You've mastered the basics of Role-Playing & Persona Prompts.
- You learned how to assign a specific identity to an LLM.
- You saw how personas ensure consistent tone, focused knowledge, and relevant output.
- You practiced crafting clear role statements and combining them with constraints.
Next, we'll dive into Instruction Following & Constraints to further refine your LLM interactions!
Impara Prompt Engineering & LLM Optimization for Developers con un tutor IA — gratis
Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.
- Corsi
- 12
- Lezioni
- 48
Domande Frequenti
La lezione «Prompt con ruoli e persona» è gratuita?
Sì — il testo completo di «Prompt con ruoli e persona» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Prompt Engineering & LLM Optimization for Developers, passa a CoddyKit PRO. Il corso Prompt Engineering & LLM Optimization for Developers include 4 lezioni in totale.
Cosa imparerò in «Prompt con ruoli e persona»?
Scopra come assegnare ruoli o persona specifici agli LLM per guidarne le risposte e generare output più pertinenti. Eserciti Prompt Engineering & LLM Optimization for Developers con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Prompt Engineering & LLM Optimization for Developers?
Non è richiesta alcuna esperienza precedente. Prompt Engineering & LLM Optimization for Developers su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 1 di 4.
Quanto tempo richiede la lezione «Prompt con ruoli e persona»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Prompt Engineering & LLM Optimization for Developers?
Sì. Ogni lezione Prompt Engineering & LLM Optimization for Developers include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Prompt con ruoli e persona
- Rispetto delle istruzioni e vincoli
- Affinamento iterativo dei prompt
- Delimitatori e prompt strutturati