feat: Add per-pet-type prompt templates for song generation
Replace the generic song generation prompt with pet-specific prompt templates. Each pet type (Dog, Cat, Fish, Bird, Hamster, Gerbil, Guinea Pig, Rabbit, Bearded Dragon, Leopard Gecko, Corn Snake) now has its own tailored prompt with pet-specific behaviors and content restrictions. Also fix typo: "Beared Dragon" → "Bearded Dragon" in schemas.py and home.js. The prompts.py file includes backwards compatibility for the old spelling to handle any pending database records. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
59357cff06
commit
a447994375
4 changed files with 150 additions and 8 deletions
|
|
@ -1,4 +1,4 @@
|
|||
const petCategory = ["Dog", "Cat", "Fish", "Bird", "Hamster", "Gerbil", "Guinea Pig", "Rabbit", "Beared Dragon", "Leopard Gecko", "Corn Snake"];
|
||||
const petCategory = ["Dog", "Cat", "Fish", "Bird", "Hamster", "Gerbil", "Guinea Pig", "Rabbit", "Bearded Dragon", "Leopard Gecko", "Corn Snake"];
|
||||
const musicGenre = ["Boy Band", "Soul", "Country & Western", "Hip-Hop", "K-Pop", "New Romantic"]
|
||||
const MAX_SUBMISSIONS = 10;
|
||||
|
||||
|
|
|
|||
136
backend/app/prompts.py
Normal file
136
backend/app/prompts.py
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
"""Per-pet-type prompt templates for Sonauto song generation."""
|
||||
|
||||
# Default fallback prompt for unknown pet types
|
||||
DEFAULT_PROMPT = """Create a heartfelt Valentine's Day love song in a {music_vibe} style celebrating the special bond between {owner_name} and their beloved pet {pet_name}. Make it warm, genuine, and mention both names in the lyrics."""
|
||||
|
||||
# Pet-specific prompt templates
|
||||
# Each template uses {owner_name}, {pet_name}, and {music_vibe} placeholders
|
||||
PET_PROMPTS = {
|
||||
"Dog": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet dog called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrics focus on behaviour iconic to a dog like tail wagging, barks and woofs, jumping up to say hello, chasing its own tail. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention of chasing or catching other animals.
|
||||
|
||||
Do not mention sticks, fetching or bones.
|
||||
|
||||
Do not mention licking faces or hands
|
||||
|
||||
Do not mention hanging out of car window""",
|
||||
|
||||
"Cat": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet cat called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a cat like purring, meowing, wrapping round legs, liking being stroked. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention rubbing tummy.
|
||||
|
||||
Do not mention balls of wool.
|
||||
|
||||
Do not mention licking faces or hands""",
|
||||
|
||||
"Fish": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet fish called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a fish like gliding through water, swimming in circles, waggling fins, blowing bubbles and having a short memory. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention goldfish.
|
||||
|
||||
Do not mention fish bowls.
|
||||
|
||||
Do not mention tapping on the tank or glass.""",
|
||||
|
||||
"Bird": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet bird called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a bird like chirps, squawks, whistles, head bobbing, fluttering, spreading wings, splashing in water dish. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention cages.
|
||||
|
||||
Do not mention clipping wings.
|
||||
|
||||
Do not mention flying free.""",
|
||||
|
||||
"Hamster": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet hamster called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a hamster like squeaking, twitching whiskers, storing food in cheeks, building a nest. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention cages.
|
||||
|
||||
Do not mention hamster wheels.
|
||||
|
||||
Do not mention nibbling faces, fingers or hands.""",
|
||||
|
||||
"Gerbil": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet gerbil called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a gerbil like obsessive digging and tunnel building, relentless chewing of cardboard or wood, popping up on hind legs, perked up ears, getting a fruit treat. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention cages.
|
||||
|
||||
Do not mention wheels.
|
||||
|
||||
Do not mention nibbling faces, fingers or hands.""",
|
||||
|
||||
"Guinea Pig": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet guinea pig called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a guinea pig like wheeking, pop-corning, zooming. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention cages.
|
||||
|
||||
Do not mention wheels.
|
||||
|
||||
Do not mention nibbling faces, fingers or hands.""",
|
||||
|
||||
"Rabbit": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet rabbit called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour and features iconic to a rabbit like hopping, jumping, having long ears, shaking their fluffy tail, doe eyes. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention carrots.
|
||||
|
||||
Do not mention nibbling faces, fingers or hands.
|
||||
|
||||
Do not mention licking faces or hands""",
|
||||
|
||||
"Bearded Dragon": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet bearded dragon called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a bearded dragon like basking, head bobbing, tongue flicking, being a reptile, having a dandelion treat. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Mention that the temperature in the vivarium is just right in centigrade.
|
||||
|
||||
Mention perfect UVB light.
|
||||
|
||||
Mention the humidity is ideal.
|
||||
|
||||
Do not mention cuddles.
|
||||
|
||||
Do not mention tapping on the tank or glass.
|
||||
|
||||
Do not use any lyrics that indicate gender.""",
|
||||
|
||||
"Leopard Gecko": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet leopard gecko called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a leopard gecko like splooting, slow tail waving, licking eyes, shedding skin. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Mention that the heating pad is a perfect 24 degrees centigrade.
|
||||
|
||||
Mention crickets as a treat.
|
||||
|
||||
Mention humidity is ideal.
|
||||
|
||||
Do not use any lyrics that indicate gender.
|
||||
|
||||
Do not mention cuddles, holding or squeezing.
|
||||
|
||||
Do not mention tapping on the tank or glass.""",
|
||||
|
||||
"Corn Snake": """Create a funny Valentine's love ballad in a {music_vibe} style celebrating the love between {owner_name} and a pet corn snake called {pet_name}. Song should be no more than 3 minutes long and with an intro length of no more than 10 seconds. For the lyrical content focus on behaviour iconic to a corn snake like coiling, tongue flicking, corn pattern on belly scales being a reptile. Mention the owners name and the pets name in every verse and the chorus. Have the phrase "this is our Valentine's" in the chorus.
|
||||
|
||||
Mention that the temperature is just right in centigrade.
|
||||
|
||||
Mention the humidity is ideal.
|
||||
|
||||
Mention the vivarium is a perfect size.
|
||||
|
||||
Do not mention cuddles.
|
||||
|
||||
Do not mention tapping on the tank or glass.
|
||||
|
||||
Do not use any lyrics that indicate gender.""",
|
||||
}
|
||||
|
||||
# Add backwards compatibility for the old typo "Beared Dragon"
|
||||
# to handle any pending database records with the old spelling
|
||||
PET_PROMPTS["Beared Dragon"] = PET_PROMPTS["Bearded Dragon"]
|
||||
|
|
@ -8,7 +8,7 @@ from pydantic import BaseModel, Field, field_validator, ConfigDict
|
|||
|
||||
|
||||
# Allowed values (must match frontend home.js)
|
||||
PET_TYPES = ["Dog", "Cat", "Fish", "Bird", "Hamster", "Gerbil", "Guinea Pig", "Rabbit", "Beared Dragon", "Leopard Gecko", "Corn Snake"]
|
||||
PET_TYPES = ["Dog", "Cat", "Fish", "Bird", "Hamster", "Gerbil", "Guinea Pig", "Rabbit", "Bearded Dragon", "Leopard Gecko", "Corn Snake"]
|
||||
MUSIC_VIBES = ["Boy Band", "Soul", "Country & Western", "Hip-Hop", "K-Pop", "New Romantic"]
|
||||
ENTRY_STATUSES = ["pending", "processing", "success", "fail"]
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|||
from app.config import settings
|
||||
from app.database import SessionLocal
|
||||
from app.models import Submission
|
||||
from app.prompts import PET_PROMPTS, DEFAULT_PROMPT
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -226,13 +227,18 @@ def send_to_sonauto(self, session_id: str):
|
|||
logger.error(f"Submission {session_id} not found")
|
||||
return {"error": "not_found"}
|
||||
|
||||
# Get pet-specific prompt template or fall back to default
|
||||
prompt_template = PET_PROMPTS.get(submission.pet_type, DEFAULT_PROMPT)
|
||||
|
||||
# Substitute variables
|
||||
prompt = prompt_template.format(
|
||||
owner_name=submission.owner_name,
|
||||
pet_name=submission.pet_name,
|
||||
music_vibe=submission.music_vibe,
|
||||
)
|
||||
|
||||
payload = {
|
||||
"prompt": (
|
||||
f"Create a heartfelt Valentine's Day love song in a {submission.music_vibe} style "
|
||||
f"celebrating the special bond between {submission.owner_name} and their beloved "
|
||||
f"{submission.pet_type} {submission.pet_name}. Make it warm, genuine, and mention "
|
||||
f"both names in the lyrics."
|
||||
),
|
||||
"prompt": prompt,
|
||||
"instrumental": False,
|
||||
"output_format": "mp3",
|
||||
"webhook_url": f"{settings.WEBHOOK_BASE_URL}/api/webhook",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue