File size: 1,928 Bytes
a4075b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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"