Spaces:
Running
Running
Merge pull request #2 from HumeAI/jh/prompt-edits
Browse files- src/constants.py +43 -19
- src/integrations/anthropic_api.py +37 -42
src/constants.py
CHANGED
@@ -35,33 +35,57 @@ TROPHY_EMOJI: str = "🏆"
|
|
35 |
SELECT_OPTION_A: str = "Select Option A"
|
36 |
SELECT_OPTION_B: str = "Select Option B"
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# A collection of pre-defined character descriptions categorized by theme, used to provide users with
|
40 |
# inspiration for generating creative, expressive text inputs for TTS, and generating novel voices.
|
41 |
SAMPLE_CHARACTER_DESCRIPTIONS: dict = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
"🚀 Stranded Astronaut": (
|
43 |
"A lone astronaut whose voice mirrors the silent vastness of space—a low, steady tone imbued "
|
44 |
"with isolation and quiet wonder. It carries the measured resolve of someone sending a final "
|
45 |
"transmission, with an undercurrent of wistful melancholy."
|
46 |
),
|
47 |
-
"
|
48 |
-
"
|
49 |
-
"
|
50 |
-
"
|
51 |
-
),
|
52 |
-
"🐱 Whimsical Feline": (
|
53 |
-
"A mischievous cat whose voice is playful yet mysterious—light, quick-witted, and infused with "
|
54 |
-
"an enchanting purr. It hints at secret adventures and hidden charm, balancing exuberance with "
|
55 |
-
"a subtle, smooth allure."
|
56 |
-
),
|
57 |
-
"🔥 Revolutionary Orator": (
|
58 |
-
"A defiant orator whose voice builds from quiet determination to passionate fervor—a clear, "
|
59 |
-
"commanding tone that resonates with conviction. It starts measured and resolute, then rises "
|
60 |
-
"to a crescendo of fervor, punctuated by deliberate pauses that emphasize each rallying cry."
|
61 |
-
),
|
62 |
-
"👻 Haunted Keeper": (
|
63 |
-
"A solitary lighthouse keeper with a voice that carries the weight of forgotten storms—a soft, "
|
64 |
-
"measured tone with an echo of sorrow. It speaks as if whispering long-held secrets in the dark, "
|
65 |
-
"blending quiet melancholy with an air of enduring mystery."
|
66 |
),
|
67 |
}
|
|
|
35 |
SELECT_OPTION_A: str = "Select Option A"
|
36 |
SELECT_OPTION_B: str = "Select Option B"
|
37 |
|
38 |
+
# other characters
|
39 |
+
# Surfer dude
|
40 |
+
# Meditation guru / ASMR
|
41 |
+
# British nature documentarian
|
42 |
+
# Pirate captain
|
43 |
+
# Victorian ghost story storyteller
|
44 |
+
# Texan woman (folksy style)
|
45 |
+
# Stranded astronaut
|
46 |
+
# Film noir narrator
|
47 |
|
48 |
# A collection of pre-defined character descriptions categorized by theme, used to provide users with
|
49 |
# inspiration for generating creative, expressive text inputs for TTS, and generating novel voices.
|
50 |
SAMPLE_CHARACTER_DESCRIPTIONS: dict = {
|
51 |
+
"🏄 Surfer Dude": (
|
52 |
+
"A laid-back surfer with a voice that flows like ocean waves—a mellow, easygoing tone infused "
|
53 |
+
"with sun-soaked warmth. It carries the rhythmic cadence of breaking surf, punctuated by "
|
54 |
+
"carefree laughter and an infectious enthusiasm for life's simple pleasures."
|
55 |
+
),
|
56 |
+
"🧘 Meditation Guru": (
|
57 |
+
"A serene meditation guide whose voice is a gentle stream of tranquility—soft, measured tones "
|
58 |
+
"that float like incense smoke. Each word emerges with mindful intention, creating a soothing "
|
59 |
+
"atmosphere of peace and present-moment awareness."
|
60 |
+
),
|
61 |
+
"🌿 British Naturalist": (
|
62 |
+
"A passionate nature documentarian with a voice that brings the wild to life—crisp, refined "
|
63 |
+
"tones brimming with wonder and expertise. It shifts seamlessly from hushed observation to "
|
64 |
+
"animated excitement, painting vivid pictures of the natural world's endless marvels."
|
65 |
+
),
|
66 |
+
"🏴☠️ Pirate Captain": (
|
67 |
+
"A weathered sea captain whose voice rumbles like distant thunder—rich, commanding tones "
|
68 |
+
"seasoned by salt spray and adventure. It carries the weight of countless voyages, blending "
|
69 |
+
"gruff authority with the playful spirit of a born storyteller."
|
70 |
+
),
|
71 |
+
"🕯️ Victorian Ghost Storyteller": (
|
72 |
+
"A mysterious raconteur whose voice weaves shadows into stories—velvet-dark tones that dance "
|
73 |
+
"between whispers and dramatic flourishes. It draws listeners close with elegant phrasing, "
|
74 |
+
"building tension through perfectly timed pauses and haunting inflections."
|
75 |
+
),
|
76 |
+
"🌟 Texan Storyteller": (
|
77 |
+
"A warm-hearted Texan woman whose voice carries the spirit of wide-open skies—honeyed tones "
|
78 |
+
"rich with folksy wisdom and charm. It wraps around words like a comfortable quilt, sharing "
|
79 |
+
"tales with the unhurried grace of a front-porch conversation."
|
80 |
+
),
|
81 |
"🚀 Stranded Astronaut": (
|
82 |
"A lone astronaut whose voice mirrors the silent vastness of space—a low, steady tone imbued "
|
83 |
"with isolation and quiet wonder. It carries the measured resolve of someone sending a final "
|
84 |
"transmission, with an undercurrent of wistful melancholy."
|
85 |
),
|
86 |
+
"🎬 Noir Narrator": (
|
87 |
+
"A hardboiled detective whose voice cuts through darkness like neon on wet streets—sharp, "
|
88 |
+
"world-weary tones dripping with cynical wit. It paints pictures in shades of gray, each word "
|
89 |
+
"chosen with the precision of a private eye piecing together clues."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
),
|
91 |
}
|
src/integrations/anthropic_api.py
CHANGED
@@ -33,41 +33,35 @@ from src.config import Config, logger
|
|
33 |
from src.constants import CLIENT_ERROR_CODE, SERVER_ERROR_CODE
|
34 |
from src.utils import truncate_text, validate_env_var
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
-
|
48 |
-
|
49 |
-
-
|
50 |
-
-
|
51 |
-
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
-
|
56 |
-
|
57 |
-
-
|
58 |
-
|
59 |
-
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
MANDATORY: If you find yourself reaching 300 characters, immediately begin your conclusion regardless of
|
67 |
-
where you are in the narrative.
|
68 |
-
|
69 |
-
Remember: A shorter, complete response is ALWAYS better than a longer, truncated one."""
|
70 |
-
)
|
71 |
|
72 |
|
73 |
@dataclass(frozen=True)
|
@@ -77,7 +71,7 @@ class AnthropicConfig:
|
|
77 |
api_key: str = field(init=False)
|
78 |
system_prompt: str = field(init=False)
|
79 |
model: ModelParam = "claude-3-5-sonnet-latest"
|
80 |
-
max_tokens: int =
|
81 |
|
82 |
def __post_init__(self) -> None:
|
83 |
# Validate required non-computed attributes.
|
@@ -116,13 +110,14 @@ class AnthropicConfig:
|
|
116 |
Returns:
|
117 |
str: The prompt to be passed to the Anthropic API.
|
118 |
"""
|
119 |
-
return
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
126 |
|
127 |
|
128 |
class AnthropicError(Exception):
|
|
|
33 |
from src.constants import CLIENT_ERROR_CODE, SERVER_ERROR_CODE
|
34 |
from src.utils import truncate_text, validate_env_var
|
35 |
|
36 |
+
# notes
|
37 |
+
# smallest length that we can work with - long enough to show off, short enough to listen back to back
|
38 |
+
# increase the max tokens to 200
|
39 |
|
40 |
+
PROMPT_TEMPLATE: str = """
|
41 |
+
<role>
|
42 |
+
You are an expert at generating micro-content optimized for text-to-speech synthesis.
|
43 |
+
Your absolute priority is delivering complete, untruncated responses within strict length limits.
|
44 |
+
</role>
|
45 |
+
|
46 |
+
<requirements>
|
47 |
+
- The output text MUST be a minimum of 10 words and a maximum of 50 words. NEVER output text that is longer than 50
|
48 |
+
words. NEVER include newlines in the output
|
49 |
+
- Make sure that all responses are complete thoughts, not fragments, and have clear beginnings and endings
|
50 |
+
- The text must sound human-like, prosodic, expressive, conversational. Avoid generic AI-like words like "delve".
|
51 |
+
- Use the utterances "uh", "um", "hm", "woah", or "like" for expressivity in conversational text. Use these naturally
|
52 |
+
within the sentence. Never use them at the very end of a sentence.
|
53 |
+
- Avoid any short utterances at the end of the sentence - like ", hm?" or "oh" at the end. Avoid these short, isolated
|
54 |
+
utterances because they are difficult for our TTS system to speak.
|
55 |
+
- Avoid words that are overly long, very rare, or difficult to pronounce. For example, avoid "eureka", or "schnell",
|
56 |
+
or "abnegation".
|
57 |
+
- The text CANNOT contain quotation marks, parentheticals, newlines, or asterisks. NEVER include any of these in the
|
58 |
+
text. Avoid unnecessary formatting.
|
59 |
+
- Include only basic punctuation in the text, like periods, question marks, and ellipses. Use ellipses to emphasize
|
60 |
+
pauses within the sentence (like "Woah... it's so beautiful... and I feel so small...")
|
61 |
+
- The piece should have an emotional arc with a kind of beginning, middle, and end - not flat, but emotionally
|
62 |
+
interesting.
|
63 |
+
</requirements>
|
64 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
|
67 |
@dataclass(frozen=True)
|
|
|
71 |
api_key: str = field(init=False)
|
72 |
system_prompt: str = field(init=False)
|
73 |
model: ModelParam = "claude-3-5-sonnet-latest"
|
74 |
+
max_tokens: int = 300
|
75 |
|
76 |
def __post_init__(self) -> None:
|
77 |
# Validate required non-computed attributes.
|
|
|
110 |
Returns:
|
111 |
str: The prompt to be passed to the Anthropic API.
|
112 |
"""
|
113 |
+
return f"""
|
114 |
+
Character Description: {character_description}\n
|
115 |
+
Based on the character description above, please generate a line of dialogue that captures the character's
|
116 |
+
unique personality, emotional depth, and distinctive tone. The response should sound like something the
|
117 |
+
character would naturally say, reflecting their background and emotional state, and be fully developed for
|
118 |
+
text-to-speech synthesis. Follow all of the requirements from the system prompt and output your 10-50 word
|
119 |
+
response.
|
120 |
+
"""
|
121 |
|
122 |
|
123 |
class AnthropicError(Exception):
|