Spaces:
Running
Running
Agent: deterministische Rückfragen bei vagen Eingaben + ask_user in UI + Tests
Browse files- studio/agent.py +54 -0
studio/agent.py
CHANGED
|
@@ -319,6 +319,10 @@ class ProducerAgent:
|
|
| 319 |
else:
|
| 320 |
proposal = _fallback_proposal(message)
|
| 321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
try:
|
| 323 |
model = self.registry.get(proposal.model_id or "")
|
| 324 |
except KeyError:
|
|
@@ -348,6 +352,56 @@ class ProducerAgent:
|
|
| 348 |
)
|
| 349 |
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
def propose_fields(message: str) -> FieldProposal:
|
| 352 |
"""Compatibility helper using the validated local fallback/provider chain."""
|
| 353 |
|
|
|
|
| 319 |
else:
|
| 320 |
proposal = _fallback_proposal(message)
|
| 321 |
|
| 322 |
+
# Deterministische Absicherung: vage Eingabe -> immer eine Rückfrage
|
| 323 |
+
if proposal.ask_user is None and _is_vague_input(message):
|
| 324 |
+
proposal.ask_user = _default_ask(message)
|
| 325 |
+
|
| 326 |
try:
|
| 327 |
model = self.registry.get(proposal.model_id or "")
|
| 328 |
except KeyError:
|
|
|
|
| 352 |
)
|
| 353 |
|
| 354 |
|
| 355 |
+
def _is_vague_input(message: str) -> bool:
|
| 356 |
+
"""True, wenn die Eingabe keine entscheidenden Produktions-Infos enthält."""
|
| 357 |
+
normalized = message.casefold()
|
| 358 |
+
genre_terms = (
|
| 359 |
+
"riddim", "reggae", "dub", "techno", "club", "rave", "lofi", "lo-fi", "chill",
|
| 360 |
+
"film", "cinematic", "episch", "rock", "gitarre", "guitar", "pop", "hiphop",
|
| 361 |
+
"hip-hop", "house", "drum and bass", "dnb", "ambient", "jazz", "soul", "trap",
|
| 362 |
+
"edm", "trance", "metal", "punk", "blues", "funk", "disco", "country", "folk",
|
| 363 |
+
)
|
| 364 |
+
mood_terms = (
|
| 365 |
+
"dunkel", "dark", "euphorisch", "euphoric", "entspannt", "relaxed", "traurig",
|
| 366 |
+
"sad", "wütend", "angry", "aggressiv", "aggressive", "melancholisch", "melancholic",
|
| 367 |
+
"fröhlich", "happy", "warm", "kalt", "cold", "mysteriös", "mysterious", "episch",
|
| 368 |
+
"cinematic", "energetisch", "energetic", "ruhig", "calm", "böse", "evil", "düster",
|
| 369 |
+
)
|
| 370 |
+
instrument_terms = (
|
| 371 |
+
"bass", "drums", "drum", "gitarre", "guitar", "piano", "keys", "synth", "synthesizer",
|
| 372 |
+
"strings", "streicher", "violine", "saxophon", "sax", "horn", "flöte", "flute",
|
| 373 |
+
"percussion", "schlagzeug", "kick", "snare", "hi-hat", "pad", "lead", "vocal", "gesang",
|
| 374 |
+
"stimme", "choir", "chor", "organ", "orgel", "brass",
|
| 375 |
+
)
|
| 376 |
+
structure_terms = (
|
| 377 |
+
"instrumental", "vocal", "gesang", "lyrics", "text", "sänger", "sängerin",
|
| 378 |
+
"sekunden", "seconds", "minuten", "minutes", "bpm", "tempo", "dauer", "länge",
|
| 379 |
+
"intro", "verse", "chorus", "bridge", "drop", "hook",
|
| 380 |
+
)
|
| 381 |
+
has_info = any(
|
| 382 |
+
term in normalized
|
| 383 |
+
for term in (*genre_terms, *mood_terms, *instrument_terms, *structure_terms)
|
| 384 |
+
)
|
| 385 |
+
return not has_info
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
def _default_ask(message: str) -> str:
|
| 389 |
+
"""Deterministische Rückfrage, wenn die Eingabe zu wenig Info enthält."""
|
| 390 |
+
normalized = message.casefold()
|
| 391 |
+
if "instrumental" not in normalized and not any(
|
| 392 |
+
term in normalized for term in ("vocal", "gesang", "stimme", "lyrics", "text")
|
| 393 |
+
):
|
| 394 |
+
return "Soll es ein Instrumental sein oder mit Gesang?"
|
| 395 |
+
if not any(
|
| 396 |
+
term in normalized
|
| 397 |
+
for term in (
|
| 398 |
+
"bpm", "tempo", "sekunden", "seconds", "minuten", "minutes", "dauer", "länge",
|
| 399 |
+
)
|
| 400 |
+
):
|
| 401 |
+
return "Wie lang soll der Track sein (5–180 Sekunden)?"
|
| 402 |
+
return "Welche Stimmung soll der Track vermitteln (z. B. dunkel, euphorisch, entspannt)?"
|
| 403 |
+
|
| 404 |
+
|
| 405 |
def propose_fields(message: str) -> FieldProposal:
|
| 406 |
"""Compatibility helper using the validated local fallback/provider chain."""
|
| 407 |
|