Yapay Zeka ve LLM
1 dakika okuma
LLM Prompt Muhendisligi: İleri Teknikler
Chain-of-thought, few-shot prompting, RAG ve sistem prompt tasarimi ileri teknikleri.
E
Emre Cihan Prompt Muhendisligi Neden Onemli
Ayni model, farkli prompt ile cok farkli sonuclar uretir. Iyi prompt = daha az maliyet + daha iyi cikti.
Zero-Shot vs Few-Shot
# Zero-shot: Ornek verilmeden
prompt_zero = 'Su cumleyi Turkce'ye cevir: The quick brown fox'
# Few-shot: Orneklerle
prompt_few = '''Asagidaki orneklere gore cevir:
Ingilizce: Hello, how are you?
Turkce: Merhaba, nasilsiniz?
Ingilizce: Good morning!
Turkce: Gunaydin!
Ingilizce: The quick brown fox
Turkce:'''
Chain-of-Thought (CoT)
# Direkt soru - hatali sonuclar
prompt_direkt = '13 * 17 + 45 kactir?'
# CoT - adim adim dusun
prompt_cot = '''13 * 17 + 45 kactir? Adim adim dusun:
Once carpmayi yap, sonra toplami hesapla.'''
# Zero-shot CoT
prompt_zero_cot = '13 * 17 + 45 kactir? Adim adim dusunelim:'
Sistem Prompt Tasarimi
from openai import OpenAI
client = OpenAI()
SISTEM = '''Sen bir kıdemli PHP guvenlik uzmanisin.
Kod incelediginde:
1. Guvenlik acıklarini (SQL injection, XSS, CSRF) tespit et
2. Her bulguu CVSS 3.1 puaniyla degerlendir
3. Duzeltme onerisini kod ornekle goster
4. Asla aciklari nasil exploit edileceğini aciklama
Yanit formati:
## Bulgular
- [YUKSEK/ORTA/DUSUK] Acik adi: Aciklama
## Duzeltmeler
Duzeltilmis kod
def kod_incele(kod: str) -> str:
r = client.chat.completions.create(
model='gpt-4o',
messages=[
{'role': 'system', 'content': SISTEM},
{'role': 'user', 'content': f'Su kodu incele:
{kod}
],
temperature=0.1 # Tutarli cikti icin dusuk
)
return r.choices[0].message.content
Structured Output
from pydantic import BaseModel
class Guvenlik(BaseModel):
risk_seviyesi: str
aciklar: list[str]
puan: float
r = client.beta.chat.completions.parse(
model='gpt-4o',
messages=[{'role':'user','content':'Kodu degerlendir: ...'}],
response_format=Guvenlik
)
print(r.choices[0].message.parsed.puan)
Iyi prompt tasarimi, LLM ciktisini tahmin edilebilir ve gercek anlamda faydali kilar.
Paylaş:
Twitter / X
E
Emre Cihan
Sistem Yöneticisi · Maker · Elektronik Meraklısı
İlgili yazılar