पाठ 3 / 29

अच्छे Prompt की संरचना

Prompt को भूमिका, कार्य, दर्शक, नियम, format और इनपुट में बाँटें।

छह निर्माण-खंड

भरोसेमंद prompts में आम तौर पर होता है: (1) भूमिका या दृष्टिकोण ("support analyst"); (2) एक स्पष्ट वाक्य में कार्य; (3) दर्शक और उद्देश्य; (4) नियम और बाधाएँ (लंबाई, लहजा, क्या न करें, अनिश्चित हों तो क्या करें); (5) output format; और (6) इनपुट स्वयं, निर्देशों से साफ़ अलग। हर prompt को सब छह नहीं चाहिए, पर आउटपुट निराश करे तो इस सूची की त्वरित जाँच बताती है कि क्या छूटा है। Template टीम भर में prompts को एकसमान भी बनाता है।

पुनः उपयोग योग्य template, चलाकर

मैंने यह सादा-Python (सिर्फ़ standard library) उदाहरण चलाया। Template भूमिका, कार्य, दर्शक, नियम, format और इनपुट भरता है और अंतिम prompt छापता है (259 अक्षर, मोटे 4-अक्षर-प्रति-token नियम से लगभग 65 tokens)।

from string import Template

PROMPT = Template("""You are a $role.
Task: $task
Audience: $audience
Rules:
$rules
Output format: $fmt

Input:
$text""")

rules = ["Use only the input text.", "Max 2 sentences.", "If unsure, say 'unknown'."]
p = PROMPT.substitute(
    role="support analyst",
    task="summarise the customer's complaint",
    audience="a busy manager",
    rules="\n".join(f"- {r}" for r in rules),
    fmt="plain text",
    text="My order 4821 arrived late and the box was damaged.",
)
print(p)
print("characters:", len(p), "| rough tokens:", round(len(p) / 4))

Output:

You are a support analyst.
Task: summarise the customer's complaint
Audience: a busy manager
Rules:
- Use only the input text.
- Max 2 sentences.
- If unsure, say 'unknown'.
Output format: plain text

Input:
My order 4821 arrived late and the box was damaged.
characters: 259 | rough tokens: 65

त्वरित जाँच: इनपुट को निर्देशों से अलग क्यों रखें?

  • क्योंकि मॉडल इनपुट नहीं पढ़ सकते
  • Prompt छिपाने के लिए
  • एक token बचाने के लिए
  • ताकि मॉडल समझे कि क्या करना है और क्या प्रोसेस करना है
Answer

ताकि मॉडल समझे कि क्या करना है और क्या प्रोसेस करना है — साफ़ अलगाव भ्रम से बचाता है और injection जोखिम घटाता है।