uno-final / uno /utils /prompt_router.py
Manireddy1508's picture
Upload 5 files
a4075b9 verified
import os
import openai
# === OpenAI Client ===
client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# === System Message ===
INTENT_SYSTEM_MESSAGE = """
You are an intent classification engine for Flux Pro's AI prompt enhancement system.
Given a short user prompt, your job is to classify the *underlying marketing or creative intent* behind it using a single lowercase label that reflects the intent category.
You must:
- Respond with only one concise intent label (a single word or hyphenated phrase)
- Avoid using punctuation, explanations, or examples
- Infer intent intelligently using your understanding of marketing and creative goals
- You may return previously unseen or new intent labels if appropriate
Some valid label types might include (but are not limited to): product-ad, service-promotion, public-awareness, brand-storytelling, social-trend, artistic-expression, educational-content, campaign-launch, or experimental-style.
Only return the label. Do not echo the prompt or add any commentary.
""".strip()
def classify_prompt_intent(user_prompt: str) -> str:
"""
Uses GPT-4 to classify the user's prompt into a marketing or creative intent label.
Returns a lowercase intent string (e.g., 'product-ad', 'artistic-expression').
"""
user_msg = f"Prompt: {user_prompt}\nReturn only the label."
try:
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": INTENT_SYSTEM_MESSAGE},
{"role": "user", "content": user_msg}
],
temperature=0,
max_tokens=10,
)
label = response.choices[0].message.content.strip().lower()
print(f"πŸ“Œ [DEBUG] Inferred intent label: {label}")
return label
except Exception as e:
print(f"❌ [ERROR] Failed to classify prompt intent: {e}")
return "unknown"