Prompt Engineering
AI কে সঠিক ভাবে instructions দেওয়ার বিজ্ঞান।
একই LLM, একই question — দুজন user এর কাছে দুই রকম answer। কেন? Prompt লেখার তফাৎ। 'Write a poem' vs 'Write a 4-line haiku about autumn rain in Tagore style' — দ্বিতীয় টায় quality আকাশ-পাতাল ভালো। Prompt Engineering — AI কে effectively instruct করার বিজ্ঞান এবং art।
Prompt Engineering = LLM থেকে best output বের করার জন্য input design করার practice। Core techniques: Zero-shot (শুধু instruction), Few-shot (কিছু example), Chain-of-Thought (step by step think কর), Role assignment ('You are an expert...'), Constraint specification (format, length, style), Self-consistency (multiple sample, majority pick), ReAct (reason + act loop)।
ভাবুন employee কে instruction দেওয়া — vague বললে ('do something') যা ইচ্ছা করবে। Specific বললে ('write a 300-word product description focused on durability, target audience 30-50 age, in friendly tone, end with CTA') — exact যা চান পাবেন। LLM ও তাই — যত clear, structured, contextual instruction, তত predictable + high-quality output।
import os
from openai import OpenAI
client = OpenAI(
base_url="https://ai.gateway.lovable.dev/v1",
api_key=os.environ["LOVABLE_API_KEY"],
)
def ask(messages, label):
res = client.chat.completions.create(
model="google/gemini-2.5-flash",
messages=messages,
temperature=0.2,
)
print(f"\n--- {label} ---")
print(res.choices[0].message.content)
problem = "If a shop sold 240 apples on Monday and twice as many on Tuesday, how many in total?"
ask([{"role": "user", "content": problem}], "Zero-shot")
ask([
{"role": "system", "content": "You are a math tutor. Think step by step before giving the final answer."},
{"role": "user", "content": problem},
], "Chain-of-Thought")
few_shot = [
{"role": "system", "content": "Convert sentence to JSON with fields: subject, action, object."},
{"role": "user", "content": "Sara reads the book."},
{"role": "assistant", "content": '{"subject": "Sara", "action": "reads", "object": "the book"}'},
{"role": "user", "content": "The cat chased the mouse."},
]
ask(few_shot, "Few-shot Structured Output")তিনটা প্রম্পটিং style demonstrate। Zero-shot — শুধু prompt। Chain-of-Thought — system message এ 'step by step' instruction যোগ। Few-shot — user/assistant pair দিয়ে pattern শেখানো, structured (JSON) output এর জন্য effective।
5টা common task (summarize, translate, code review, email draft, sentiment) এর জন্য optimized prompt template তৈরি করুন। Each template এ system message + few-shot example। CLI দিয়ে template choose করে input দিয়ে output পান।