์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐Ÿš€ Python + Claude API๋กœ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋„๊ตฌ ๋งŒ๋“ค๊ธฐ

๐Ÿš€ Python + Claude API๋กœ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋„๊ตฌ ๋งŒ๋“ค๊ธฐ

AI ์‹œ๋Œ€, ํ”„๋กฌํ”„ํŠธ ํ’ˆ์งˆ์„ ์ž๋™์œผ๋กœ ์ธก์ •ํ•˜๋Š” ๋˜‘๋˜‘ํ•œ ๋„๊ตฌ ์ œ์ž‘ ๊ฐ€์ด๋“œ
Python Script prompt_evaluator.py API Integration Claude API ๐Ÿค– Prompt Analysis ํ‰๊ฐ€ ๊ฒฐ๊ณผ ๋ช…ํ™•์„ฑ: 8.5 ๊ตฌ์ฒด์„ฑ: 9.0 ์™„์„ฑ๋„: 8.8

๐ŸŽฏ ์™œ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋„๊ตฌ๊ฐ€ ํ•„์š”ํ• ๊นŒ?

์š”์ฆ˜ AI ๊ฐœ๋ฐœ์ž๋ผ๋ฉด ๋ˆ„๊ตฌ๋‚˜ ๊ณ ๋ฏผํ•˜๋Š” ๊ฒŒ ์žˆ์–ด. ๋ฐ”๋กœ "๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ํ”„๋กฌํ”„ํŠธ๊ฐ€ ์ •๋ง ์ข‹์€ ๊ฑธ๊นŒ?"๋ผ๋Š” ์งˆ๋ฌธ์ด์ง€. ๐Ÿ˜…

ChatGPT, Claude, GPT-4 ๊ฐ™์€ ๋Œ€ํ˜• ์–ธ์–ด ๋ชจ๋ธ(LLM)์„ ์‚ฌ์šฉํ•  ๋•Œ, ํ”„๋กฌํ”„ํŠธ์˜ ํ’ˆ์งˆ์ด ๊ฒฐ๊ณผ๋ฌผ์˜ 90%๋ฅผ ์ขŒ์šฐํ•œ๋‹ค๊ณ  ํ•ด๋„ ๊ณผ์–ธ์ด ์•„๋‹ˆ์•ผ. ๊ทผ๋ฐ ๋ฌธ์ œ๋Š” ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ๋งˆ๋‹ค "์ด๊ฒŒ ๋งž๋‚˜?" ์‹ถ์€ ๊ฑฐ์ง€.

๐Ÿ’ก ์‹ค์ œ ๊ฐœ๋ฐœ ํ˜„์žฅ์˜ ๊ณ ๋ฏผ๋“ค: โ€ข ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋„ˆ๋ฌด ์• ๋งคํ•ด์„œ AI๊ฐ€ ์—‰๋šฑํ•œ ๋‹ต๋ณ€์„ ๋‚ด๋†“๋Š” ๊ฒฝ์šฐ
โ€ข ์ง€์‹œ์‚ฌํ•ญ์ด ๋„ˆ๋ฌด ๊ธธ์–ด์„œ ํ•ต์‹ฌ์ด ๋ฌปํžˆ๋Š” ๊ฒฝ์šฐ
โ€ข ์—ฌ๋Ÿฌ ๋ฒ„์ „์˜ ํ”„๋กฌํ”„ํŠธ ์ค‘ ์–ด๋–ค ๊ฒŒ ๋” ๋‚˜์€์ง€ ๊ฐ๊ด€์ ์œผ๋กœ ๋น„๊ตํ•˜๊ธฐ ์–ด๋ ค์šด ๊ฒฝ์šฐ
โ€ข ํŒ€์›๋“ค๊ณผ ํ”„๋กฌํ”„ํŠธ ํ’ˆ์งˆ ๊ธฐ์ค€์„ ๊ณต์œ ํ•˜๊ธฐ ์–ด๋ ค์šด ๊ฒฝ์šฐ
์ด๋Ÿฐ ๊ณ ๋ฏผ๋“ค์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์šฐ๋ฆฌ๋Š” ์ž๋™ํ™”๋œ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค ๊ฑฐ์•ผ! Python๊ณผ Claude API๋ฅผ ํ™œ์šฉํ•ด์„œ ๋ง์ด์ง€. ๐Ÿ› ๏ธ

์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ AI ๊ด€๋ จ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฐœ๋ฐœ์ž๋“ค์—๊ฒŒ๋„ ์ด๋Ÿฐ ๋„๊ตฌ๋Š” ์ •๋ง ์œ ์šฉํ•ด. ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ "์šฐ๋ฆฌ๋Š” ์ด๋ ‡๊ฒŒ ์ฒด๊ณ„์ ์œผ๋กœ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค"๋ผ๊ณ  ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ!

๐Ÿ” ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€์˜ ํ•ต์‹ฌ ์ง€ํ‘œ๋“ค

ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ‰๊ฐ€ํ•œ๋‹ค๋Š” ๊ฑด ๊ตฌ์ฒด์ ์œผ๋กœ ๋ญ˜ ์ธก์ •ํ•œ๋‹ค๋Š” ๊ฑธ๊นŒ? ํ•™๊ณ„์™€ ์—…๊ณ„์—์„œ ํ•ฉ์˜๋œ ๋ช‡ ๊ฐ€์ง€ ํ•ต์‹ฌ ์ง€ํ‘œ๋“ค์ด ์žˆ์–ด.

1๏ธโƒฃ ๋ช…ํ™•์„ฑ (Clarity)

ํ”„๋กฌํ”„ํŠธ๊ฐ€ ์–ผ๋งˆ๋‚˜ ๋ถ„๋ช…ํ•˜๊ณ  ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด๊ฐ€๋ฅผ ์ธก์ •ํ•ด. ์• ๋งค๋ชจํ˜ธํ•œ ํ‘œํ˜„์ด๋‚˜ ์ค‘์˜์ ์ธ ๋ฌธ์žฅ์ด ์žˆ์œผ๋ฉด ์ ์ˆ˜๊ฐ€ ๋‚ฎ์•„์ง€์ง€.

โŒ ๋ช…ํ™•์„ฑ์ด ๋‚ฎ์€ ์˜ˆ์‹œ:
"๊ทธ๊ฒƒ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ด์ค˜"

โœ… ๋ช…ํ™•์„ฑ์ด ๋†’์€ ์˜ˆ์‹œ:
"Python์˜ ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜ ๋ฌธ๋ฒ•์„ ์ดˆ๋ณด์ž๋„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋„๋ก ์˜ˆ์ œ ์ฝ”๋“œ์™€ ํ•จ๊ป˜ ์„ค๋ช…ํ•ด์ค˜"

2๏ธโƒฃ ๊ตฌ์ฒด์„ฑ (Specificity)

์š”์ฒญ์ด ์–ผ๋งˆ๋‚˜ ๊ตฌ์ฒด์ ์ธ์ง€๋ฅผ ํ‰๊ฐ€ํ•ด. ์„ธ๋ถ€ ์กฐ๊ฑด, ์ œ์•ฝ์‚ฌํ•ญ, ์›ํ•˜๋Š” ํ˜•์‹ ๋“ฑ์ด ๋ช…์‹œ๋˜์–ด ์žˆ์„์ˆ˜๋ก ์ข‹์•„.

3๏ธโƒฃ ๋งฅ๋ฝ ์ œ๊ณต (Context)

AI๊ฐ€ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๋ฐฐ๊ฒฝ ์ •๋ณด๊ฐ€ ์ถฉ๋ถ„ํžˆ ์ œ๊ณต๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด. ๋งฅ๋ฝ์ด ํ’๋ถ€ํ• ์ˆ˜๋ก AI๋Š” ๋” ์ •ํ™•ํ•œ ๋‹ต๋ณ€์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์–ด.

4๏ธโƒฃ ๊ตฌ์กฐํ™” (Structure)

ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋…ผ๋ฆฌ์ ์œผ๋กœ ์ž˜ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š”์ง€ ํ‰๊ฐ€ํ•ด. ๋‹จ๊ณ„๋ณ„ ์ง€์‹œ์‚ฌํ•ญ, ๋ฒˆํ˜ธ ๋งค๊ธฐ๊ธฐ, ์„น์…˜ ๊ตฌ๋ถ„ ๋“ฑ์ด ์žˆ์œผ๋ฉด ์ ์ˆ˜๊ฐ€ ์˜ฌ๋ผ๊ฐ€์ง€.

5๏ธโƒฃ ์ œ์•ฝ์กฐ๊ฑด ๋ช…์‹œ (Constraints)

์ถœ๋ ฅ ํ˜•์‹, ๊ธธ์ด ์ œํ•œ, ํ†ค์•ค๋งค๋„ˆ, ๊ธˆ์ง€ ์‚ฌํ•ญ ๋“ฑ์ด ๋ช…ํ™•ํžˆ ์ œ์‹œ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด.

ํ‰๊ฐ€ ์ง€ํ‘œ ์ธก์ • ๋‚ด์šฉ ์ ์ˆ˜ ๋ฒ”์œ„
๋ช…ํ™•์„ฑ ์˜๋ฏธ์˜ ๋ถ„๋ช…ํ•จ, ์• ๋งค๋ชจํ˜ธํ•จ ์ œ๊ฑฐ 0-10
๊ตฌ์ฒด์„ฑ ์„ธ๋ถ€ ์กฐ๊ฑด ๋ฐ ์š”๊ตฌ์‚ฌํ•ญ ๋ช…์‹œ 0-10
๋งฅ๋ฝ ์ œ๊ณต ๋ฐฐ๊ฒฝ ์ •๋ณด ๋ฐ ์ƒํ™ฉ ์„ค๋ช… 0-10
๊ตฌ์กฐํ™” ๋…ผ๋ฆฌ์  ๊ตฌ์„ฑ ๋ฐ ๋‹จ๊ณ„๋ณ„ ์ •๋ฆฌ 0-10
์ œ์•ฝ์กฐ๊ฑด ์ถœ๋ ฅ ํ˜•์‹ ๋ฐ ์ œํ•œ์‚ฌํ•ญ ๋ช…์‹œ 0-10

๐Ÿ› ๏ธ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์ค€๋น„ํ•˜๊ธฐ

์ž, ์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž! ๋จผ์ € ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ์„ธํŒ…ํ•ด์•ผ ํ•ด.

ํ•„์š”ํ•œ ๊ฒƒ๋“ค ์ฒดํฌ๋ฆฌ์ŠคํŠธ โœ…

1. Python 3.8 ์ด์ƒ
์ตœ์‹  ๋ฒ„์ „์„ ๊ถŒ์žฅํ•ด. Python 3.10์ด๋‚˜ 3.11์ด๋ฉด ์™„๋ฒฝํ•ด!

# ๋ฒ„์ „ ํ™•์ธ
python --version
# ๋˜๋Š”
python3 --version
2. Claude API ํ‚ค ๋ฐœ๊ธ‰
Anthropic ์›น์‚ฌ์ดํŠธ(console.anthropic.com)์— ๊ฐ€์ž…ํ•˜๊ณ  API ํ‚ค๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์•„์•ผ ํ•ด. ๋ฌด๋ฃŒ ํฌ๋ ˆ๋”ง๋„ ์ œ๊ณต๋˜๋‹ˆ๊นŒ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์ข‹์•„! ๐Ÿ’ณ

๐Ÿ’ก ํŒ: API ํ‚ค๋Š” ์ ˆ๋Œ€ ์ฝ”๋“œ์— ์ง์ ‘ ํ•˜๋“œ์ฝ”๋”ฉํ•˜์ง€ ๋ง๊ณ , ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋‚˜ ๋ณ„๋„ ์„ค์ • ํŒŒ์ผ๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํ•ด. ๋ณด์•ˆ์ด ์ค‘์š”ํ•˜๊ฑฐ๋“ !
3. ํ•„์ˆ˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

pip install anthropic python-dotenv requests
๊ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์—ญํ• :
โ€ข anthropic: Claude API ๊ณต์‹ Python SDK
โ€ข python-dotenv: ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๊ด€๋ฆฌ
โ€ข requests: HTTP ์š”์ฒญ ์ฒ˜๋ฆฌ (์„ ํƒ์‚ฌํ•ญ)
4. ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ๋งŒ๋“ค๊ธฐ

prompt-evaluator/
โ”œโ”€โ”€ .env                    # API ํ‚ค ์ €์žฅ
โ”œโ”€โ”€ evaluator.py           # ๋ฉ”์ธ ํ‰๊ฐ€ ๋กœ์ง
โ”œโ”€โ”€ prompts.py             # ํ‰๊ฐ€์šฉ ํ”„๋กฌํ”„ํŠธ ํ…œํ”Œ๋ฆฟ
โ”œโ”€โ”€ utils.py               # ์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜๋“ค
โ”œโ”€โ”€ requirements.txt       # ์˜์กด์„ฑ ๋ชฉ๋ก
โ””โ”€โ”€ examples/              # ํ…Œ์ŠคํŠธ์šฉ ํ”„๋กฌํ”„ํŠธ ์˜ˆ์‹œ
    โ”œโ”€โ”€ good_prompts.txt
    โ””โ”€โ”€ bad_prompts.txt

๐Ÿ” API ํ‚ค ์•ˆ์ „ํ•˜๊ฒŒ ๊ด€๋ฆฌํ•˜๊ธฐ

์ฝ”๋”ฉ ์‹œ์ž‘ํ•˜๊ธฐ ์ „์— ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ณด์•ˆ ์„ค์ •๋ถ€ํ„ฐ ํ•ด๋ณด์ž!

Step 1: .env ํŒŒ์ผ ์ƒ์„ฑ

ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ์— .env ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด:

# .env
ANTHROPIC_API_KEY=your_api_key_here
MODEL_NAME=claude-3-sonnet-20240229
MAX_TOKENS=2000
Step 2: .gitignore ์„ค์ •

Git์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋ฐ˜๋“œ์‹œ .env ํŒŒ์ผ์„ ์ œ์™ธ์‹œ์ผœ์•ผ ํ•ด:

# .gitignore
.env
__pycache__/
*.pyc
.vscode/
.idea/
โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ: API ํ‚ค๊ฐ€ GitHub ๊ฐ™์€ ๊ณต๊ฐœ ์ €์žฅ์†Œ์— ์˜ฌ๋ผ๊ฐ€๋ฉด ๋ช‡ ๋ถ„ ์•ˆ์— ๋ด‡๋“ค์ด ์ฐพ์•„๋‚ด์„œ ์•…์šฉํ•  ์ˆ˜ ์žˆ์–ด. ์‹ค์ œ๋กœ ์ด๋Ÿฐ ์‚ฌ๊ณ ๊ฐ€ ์ •๋ง ๋งŽ์ด ์ผ์–ด๋‚˜๊ฑฐ๋“ . ํ•ญ์ƒ ์กฐ์‹ฌํ•˜์ž!
Step 3: Python์—์„œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋กœ๋“œํ•˜๊ธฐ

from dotenv import load_dotenv
import os

# .env ํŒŒ์ผ ๋กœ๋“œ
load_dotenv()

# API ํ‚ค ๊ฐ€์ ธ์˜ค๊ธฐ
api_key = os.getenv('ANTHROPIC_API_KEY')
model_name = os.getenv('MODEL_NAME', 'claude-3-sonnet-20240229')  # ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •

if not api_key:
    raise ValueError("API ํ‚ค๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. .env ํŒŒ์ผ์„ ํ™•์ธํ•˜์„ธ์š”!")

๐ŸŽจ ํ‰๊ฐ€ ํ”„๋กฌํ”„ํŠธ ํ…œํ”Œ๋ฆฟ ์„ค๊ณ„ํ•˜๊ธฐ

์ด์ œ ํ•ต์‹ฌ ๋ถ€๋ถ„์ด์•ผ! Claude์—๊ฒŒ "์ด ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ‰๊ฐ€ํ•ด์ค˜"๋ผ๊ณ  ์š”์ฒญํ•  ๋•Œ ์‚ฌ์šฉํ•  ๋ฉ”ํƒ€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•ด. ๐Ÿ˜„

ํ‰๊ฐ€ ํ”„๋กฌํ”„ํŠธ์˜ ๊ตฌ์กฐ

์ข‹์€ ํ‰๊ฐ€ ํ”„๋กฌํ”„ํŠธ๋Š” ๋‹ค์Œ ์š”์†Œ๋“ค์„ ํฌํ•จํ•ด์•ผ ํ•ด:

1. ์—ญํ•  ์ •์˜ - Claude์—๊ฒŒ "๋„ˆ๋Š” ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ์ „๋ฌธ๊ฐ€์•ผ"๋ผ๊ณ  ์•Œ๋ ค์คŒ
2. ํ‰๊ฐ€ ๊ธฐ์ค€ ๋ช…์‹œ - 5๊ฐ€์ง€ ์ง€ํ‘œ์™€ ๊ฐ๊ฐ์˜ ์˜๋ฏธ ์„ค๋ช…
3. ์ถœ๋ ฅ ํ˜•์‹ ์ง€์ • - JSON์ด๋‚˜ ๊ตฌ์กฐํ™”๋œ ํ˜•์‹์œผ๋กœ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์Œ
4. ์˜ˆ์‹œ ์ œ๊ณต - ์ข‹์€/๋‚˜์œ ํ”„๋กฌํ”„ํŠธ ์˜ˆ์‹œ๋กœ ๊ธฐ์ค€์„ ๋ช…ํ™•ํžˆ ํ•จ

์‹ค์ „ ์ฝ”๋“œ: prompts.py

"""
ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€๋ฅผ ์œ„ํ•œ ํ…œํ”Œ๋ฆฟ ๋ชจ์Œ
"""

EVALUATION_PROMPT_TEMPLATE = """๋‹น์‹ ์€ AI ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ์ „๋ฌธ๊ฐ€์ž…๋‹ˆ๋‹ค. 
์ฃผ์–ด์ง„ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋‹ค์Œ 5๊ฐ€์ง€ ๊ธฐ์ค€์œผ๋กœ ํ‰๊ฐ€ํ•ด์ฃผ์„ธ์š”.

## ํ‰๊ฐ€ ๊ธฐ์ค€ (๊ฐ ํ•ญ๋ชฉ 0-10์ )

1. **๋ช…ํ™•์„ฑ (Clarity)**: ํ”„๋กฌํ”„ํŠธ์˜ ์˜๋„์™€ ์š”๊ตฌ์‚ฌํ•ญ์ด ์–ผ๋งˆ๋‚˜ ๋ถ„๋ช…ํ•œ๊ฐ€?
   - ์• ๋งค๋ชจํ˜ธํ•œ ํ‘œํ˜„์ด ์—†๋Š”๊ฐ€?
   - ์ค‘์˜์  ํ•ด์„์˜ ์—ฌ์ง€๊ฐ€ ์—†๋Š”๊ฐ€?

2. **๊ตฌ์ฒด์„ฑ (Specificity)**: ์„ธ๋ถ€ ์กฐ๊ฑด๊ณผ ์š”๊ตฌ์‚ฌํ•ญ์ด ์ถฉ๋ถ„ํžˆ ๋ช…์‹œ๋˜์—ˆ๋Š”๊ฐ€?
   - ๊ตฌ์ฒด์ ์ธ ์˜ˆ์‹œ๋‚˜ ์กฐ๊ฑด์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”๊ฐ€?
   - ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋ฌผ์˜ ํ˜•ํƒœ๊ฐ€ ๋ช…ํ™•ํ•œ๊ฐ€?

3. **๋งฅ๋ฝ ์ œ๊ณต (Context)**: ์ž‘์—… ์ˆ˜ํ–‰์— ํ•„์š”ํ•œ ๋ฐฐ๊ฒฝ ์ •๋ณด๊ฐ€ ์ถฉ๋ถ„ํ•œ๊ฐ€?
   - ๊ด€๋ จ ๋ฐฐ๊ฒฝ ์ง€์‹์ด๋‚˜ ์ƒํ™ฉ ์„ค๋ช…์ด ์žˆ๋Š”๊ฐ€?
   - AI๊ฐ€ ์ž‘์—…์„ ์ดํ•ดํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์ •๋ณด๊ฐ€ ์ œ๊ณต๋˜์—ˆ๋Š”๊ฐ€?

4. **๊ตฌ์กฐํ™” (Structure)**: ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋…ผ๋ฆฌ์ ์œผ๋กœ ์ž˜ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š”๊ฐ€?
   - ๋‹จ๊ณ„๋ณ„๋กœ ์ •๋ฆฌ๋˜์–ด ์žˆ๋Š”๊ฐ€?
   - ์ฝ๊ธฐ ์‰ฝ๊ฒŒ ํฌ๋งทํŒ…๋˜์–ด ์žˆ๋Š”๊ฐ€?

5. **์ œ์•ฝ์กฐ๊ฑด (Constraints)**: ์ถœ๋ ฅ ํ˜•์‹, ๊ธธ์ด, ํ†ค ๋“ฑ์˜ ์ œ์•ฝ์ด ๋ช…์‹œ๋˜์—ˆ๋Š”๊ฐ€?
   - ์ถœ๋ ฅ ํ˜•์‹์ด ์ง€์ •๋˜์–ด ์žˆ๋Š”๊ฐ€?
   - ๊ธˆ์ง€ ์‚ฌํ•ญ์ด๋‚˜ ์ œํ•œ ์‚ฌํ•ญ์ด ๋ช…ํ™•ํ•œ๊ฐ€?

## ํ‰๊ฐ€ํ•  ํ”„๋กฌํ”„ํŠธ:
```
{prompt_to_evaluate}
```

## ์ถœ๋ ฅ ํ˜•์‹:
๋‹ค์Œ JSON ํ˜•์‹์œผ๋กœ ํ‰๊ฐ€ ๊ฒฐ๊ณผ๋ฅผ ์ œ๊ณตํ•ด์ฃผ์„ธ์š”:

{{
  "scores": {{
    "clarity": <0-10 ์ ์ˆ˜>,
    "specificity": <0-10 ์ ์ˆ˜>,
    "context": <0-10 ์ ์ˆ˜>,
    "structure": <0-10 ์ ์ˆ˜>,
    "constraints": <0-10 ์ ์ˆ˜>
  }},
  "total_score": <์ „์ฒด ํ‰๊ท  ์ ์ˆ˜>,
  "grade": "<A/B/C/D/F ๋“ฑ๊ธ‰>",
  "strengths": [
    "๊ฐ•์  1",
    "๊ฐ•์  2"
  ],
  "weaknesses": [
    "์•ฝ์  1",
    "์•ฝ์  2"
  ],
  "suggestions": [
    "๊ฐœ์„  ์ œ์•ˆ 1",
    "๊ฐœ์„  ์ œ์•ˆ 2"
  ],
  "improved_version": "<๊ฐœ์„ ๋œ ํ”„๋กฌํ”„ํŠธ ๋ฒ„์ „>"
}}

ํ‰๊ฐ€ ์‹œ ๊ฐ๊ด€์ ์ด๊ณ  ๊ฑด์„ค์ ์ธ ํ”ผ๋“œ๋ฐฑ์„ ์ œ๊ณตํ•ด์ฃผ์„ธ์š”.
"""

# ๊ฐ„๋‹จํ•œ ํ‰๊ฐ€์šฉ (๋น ๋ฅธ ์ ์ˆ˜๋งŒ ํ•„์š”ํ•  ๋•Œ)
QUICK_EVALUATION_TEMPLATE = """๋‹ค์Œ ํ”„๋กฌํ”„ํŠธ๋ฅผ 5๊ฐ€์ง€ ๊ธฐ์ค€(๋ช…ํ™•์„ฑ, ๊ตฌ์ฒด์„ฑ, ๋งฅ๋ฝ, ๊ตฌ์กฐํ™”, ์ œ์•ฝ์กฐ๊ฑด)์œผ๋กœ 
๊ฐ๊ฐ 0-10์ ์œผ๋กœ ํ‰๊ฐ€ํ•˜๊ณ , JSON ํ˜•์‹์œผ๋กœ ์ ์ˆ˜๋งŒ ๋ฐ˜ํ™˜ํ•ด์ฃผ์„ธ์š”.

ํ”„๋กฌํ”„ํŠธ: {prompt_to_evaluate}

์ถœ๋ ฅ ํ˜•์‹:
{{"clarity": X, "specificity": X, "context": X, "structure": X, "constraints": X, "total": X}}
"""
๐Ÿ’ก ํ”„๋กฌํ”„ํŠธ ์„ค๊ณ„ ํŒ: โ€ข ํ‰๊ฐ€ ๊ธฐ์ค€์„ ๋ช…ํ™•ํžˆ ์ •์˜ํ• ์ˆ˜๋ก ์ผ๊ด€๋œ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์–ด
โ€ข JSON ์ถœ๋ ฅ ํ˜•์‹์„ ์ง€์ •ํ•˜๋ฉด ํŒŒ์‹ฑ์ด ํ›จ์”ฌ ์‰ฌ์›Œ์ ธ
โ€ข "๊ฐœ์„ ๋œ ๋ฒ„์ „"์„ ์š”์ฒญํ•˜๋ฉด ํ•™์Šต ํšจ๊ณผ๋„ ์žˆ๊ณ  ์‹ค์šฉ์ ์ด์•ผ!

๐Ÿ’ป ํ•ต์‹ฌ ํ‰๊ฐ€ ์—”์ง„ ๊ตฌํ˜„ํ•˜๊ธฐ

์ด์ œ ์‹ค์ œ๋กœ Claude API๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด์ž!

evaluator.py - ๋ฉ”์ธ ํด๋ž˜์Šค

import os
import json
from anthropic import Anthropic
from dotenv import load_dotenv
from prompts import EVALUATION_PROMPT_TEMPLATE, QUICK_EVALUATION_TEMPLATE

class PromptEvaluator:
    """ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋„๊ตฌ ๋ฉ”์ธ ํด๋ž˜์Šค"""
    
    def __init__(self, api_key=None):
        """
        ์ดˆ๊ธฐํ™”
        
        Args:
            api_key (str): Anthropic API ํ‚ค. None์ด๋ฉด ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๋กœ๋“œ
        """
        load_dotenv()
        
        self.api_key = api_key or os.getenv('ANTHROPIC_API_KEY')
        if not self.api_key:
            raise ValueError("API ํ‚ค๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค!")
        
        self.client = Anthropic(api_key=self.api_key)
        self.model = os.getenv('MODEL_NAME', 'claude-3-sonnet-20240229')
        self.max_tokens = int(os.getenv('MAX_TOKENS', 2000))
        
    def evaluate(self, prompt_text, quick_mode=False):
        """
        ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ์‹คํ–‰
        
        Args:
            prompt_text (str): ํ‰๊ฐ€ํ•  ํ”„๋กฌํ”„ํŠธ
            quick_mode (bool): True๋ฉด ๋น ๋ฅธ ํ‰๊ฐ€ (์ ์ˆ˜๋งŒ)
            
        Returns:
            dict: ํ‰๊ฐ€ ๊ฒฐ๊ณผ
        """
        # ํ…œํ”Œ๋ฆฟ ์„ ํƒ
        template = QUICK_EVALUATION_TEMPLATE if quick_mode else EVALUATION_PROMPT_TEMPLATE
        
        # ํ‰๊ฐ€ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
        evaluation_prompt = template.format(prompt_to_evaluate=prompt_text)
        
        try:
            # Claude API ํ˜ธ์ถœ
            response = self.client.messages.create(
                model=self.model,
                max_tokens=self.max_tokens,
                messages=[
                    {
                        "role": "user",
                        "content": evaluation_prompt
                    }
                ]
            )
            
            # ์‘๋‹ต ํ…์ŠคํŠธ ์ถ”์ถœ
            result_text = response.content[0].text
            
            # JSON ํŒŒ์‹ฑ
            result = self._parse_result(result_text)
            
            return {
                'success': True,
                'result': result,
                'raw_response': result_text,
                'usage': {
                    'input_tokens': response.usage.input_tokens,
                    'output_tokens': response.usage.output_tokens
                }
            }
            
        except Exception as e:
            return {
                'success': False,
                'error': str(e)
            }
    
    def _parse_result(self, text):
        """
        Claude ์‘๋‹ต์—์„œ JSON ์ถ”์ถœ ๋ฐ ํŒŒ์‹ฑ
        
        Args:
            text (str): Claude์˜ ์‘๋‹ต ํ…์ŠคํŠธ
            
        Returns:
            dict: ํŒŒ์‹ฑ๋œ ๊ฒฐ๊ณผ
        """
        # JSON ๋ธ”๋ก ์ฐพ๊ธฐ (```json ... ``` ํ˜•์‹์ผ ์ˆ˜ ์žˆ์Œ)
        import re
        
        # JSON ํŒจํ„ด ์ฐพ๊ธฐ
        json_pattern = r'\{[\s\S]*\}'
        matches = re.findall(json_pattern, text)
        
        if matches:
            # ๊ฐ€์žฅ ํฐ JSON ๋ธ”๋ก ์„ ํƒ
            json_str = max(matches, key=len)
            try:
                return json.loads(json_str)
            except json.JSONDecodeError:
                # ํŒŒ์‹ฑ ์‹คํŒจ ์‹œ ์›๋ณธ ํ…์ŠคํŠธ ๋ฐ˜ํ™˜
                return {'raw_text': text}
        
        return {'raw_text': text}
    
    def batch_evaluate(self, prompts_list):
        """
        ์—ฌ๋Ÿฌ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ผ๊ด„ ํ‰๊ฐ€
        
        Args:
            prompts_list (list): ํ‰๊ฐ€ํ•  ํ”„๋กฌํ”„ํŠธ ๋ฆฌ์ŠคํŠธ
            
        Returns:
            list: ๊ฐ ํ”„๋กฌํ”„ํŠธ์˜ ํ‰๊ฐ€ ๊ฒฐ๊ณผ ๋ฆฌ์ŠคํŠธ
        """
        results = []
        
        for i, prompt in enumerate(prompts_list, 1):
            print(f"ํ‰๊ฐ€ ์ค‘... ({i}/{len(prompts_list)})")
            result = self.evaluate(prompt)
            results.append(result)
        
        return results
    
    def compare_prompts(self, prompt1, prompt2):
        """
        ๋‘ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋น„๊ต ํ‰๊ฐ€
        
        Args:
            prompt1 (str): ์ฒซ ๋ฒˆ์งธ ํ”„๋กฌํ”„ํŠธ
            prompt2 (str): ๋‘ ๋ฒˆ์งธ ํ”„๋กฌํ”„ํŠธ
            
        Returns:
            dict: ๋น„๊ต ๊ฒฐ๊ณผ
        """
        result1 = self.evaluate(prompt1)
        result2 = self.evaluate(prompt2)
        
        if result1['success'] and result2['success']:
            score1 = result1['result'].get('total_score', 0)
            score2 = result2['result'].get('total_score', 0)
            
            return {
                'prompt1': {
                    'text': prompt1,
                    'score': score1,
                    'details': result1['result']
                },
                'prompt2': {
                    'text': prompt2,
                    'score': score2,
                    'details': result2['result']
                },
                'winner': 'prompt1' if score1 > score2 else 'prompt2' if score2 > score1 else 'tie',
                'score_difference': abs(score1 - score2)
            }
        
        return {
            'error': 'ํ‰๊ฐ€ ์‹คํŒจ',
            'result1': result1,
            'result2': result2
        }
๐ŸŽฏ ์ฝ”๋“œ ํ•ต์‹ฌ ํฌ์ธํŠธ: 1. ํด๋ž˜์Šค ๊ธฐ๋ฐ˜ ์„ค๊ณ„ - ์žฌ์‚ฌ์šฉ์„ฑ๊ณผ ํ™•์žฅ์„ฑ์„ ๊ณ ๋ คํ•œ ๊ตฌ์กฐ
2. ์—๋Ÿฌ ํ•ธ๋“ค๋ง - try-except๋กœ API ํ˜ธ์ถœ ์‹คํŒจ์— ๋Œ€๋น„
3. JSON ํŒŒ์‹ฑ - ์ •๊ทœํ‘œํ˜„์‹์œผ๋กœ ์‘๋‹ต์—์„œ JSON ์ถ”์ถœ
4. ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ - ์—ฌ๋Ÿฌ ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ•œ ๋ฒˆ์— ํ‰๊ฐ€ ๊ฐ€๋Šฅ
5. ๋น„๊ต ๊ธฐ๋Šฅ - A/B ํ…Œ์ŠคํŠธ์ฒ˜๋Ÿผ ๋‘ ๋ฒ„์ „ ๋น„๊ต

๐ŸŽฎ ์‹ค์ „ ์‚ฌ์šฉ ์˜ˆ์ œ

์ž, ์ด์ œ ๋งŒ๋“  ๋„๊ตฌ๋ฅผ ์‹ค์ œ๋กœ ์‚ฌ์šฉํ•ด๋ณด์ž! ์—ฌ๋Ÿฌ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์ค€๋น„ํ–ˆ์–ด.

์˜ˆ์ œ 1: ๊ธฐ๋ณธ ํ‰๊ฐ€

from evaluator import PromptEvaluator

# ํ‰๊ฐ€๊ธฐ ์ดˆ๊ธฐํ™”
evaluator = PromptEvaluator()

# ํ‰๊ฐ€ํ•  ํ”„๋กฌํ”„ํŠธ
test_prompt = """
Python์œผ๋กœ ์›น ํฌ๋กค๋Ÿฌ๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์–ด์š”.
"""

# ํ‰๊ฐ€ ์‹คํ–‰
result = evaluator.evaluate(test_prompt)

if result['success']:
    scores = result['result']['scores']
    print(f"์ด์ : {result['result']['total_score']}/10")
    print(f"๋“ฑ๊ธ‰: {result['result']['grade']}")
    print("\n์„ธ๋ถ€ ์ ์ˆ˜:")
    for criterion, score in scores.items():
        print(f"  {criterion}: {score}/10")
    
    print("\n๊ฐœ์„  ์ œ์•ˆ:")
    for suggestion in result['result']['suggestions']:
        print(f"  โ€ข {suggestion}")
else:
    print(f"ํ‰๊ฐ€ ์‹คํŒจ: {result['error']}")
์˜ˆ์ƒ ์ถœ๋ ฅ:

์ด์ : 3.2/10
๋“ฑ๊ธ‰: D

์„ธ๋ถ€ ์ ์ˆ˜:
clarity: 4/10
specificity: 2/10
context: 3/10
structure: 4/10
constraints: 3/10

๊ฐœ์„  ์ œ์•ˆ:
โ€ข ํฌ๋กค๋งํ•  ์›น์‚ฌ์ดํŠธ๋ฅผ ๊ตฌ์ฒด์ ์œผ๋กœ ๋ช…์‹œํ•˜์„ธ์š”
โ€ข ์ถ”์ถœํ•˜๊ณ  ์‹ถ์€ ๋ฐ์ดํ„ฐ์˜ ์ข…๋ฅ˜๋ฅผ ์„ค๋ช…ํ•˜์„ธ์š”
โ€ข ์›ํ•˜๋Š” ์ถœ๋ ฅ ํ˜•์‹(CSV, JSON ๋“ฑ)์„ ์ง€์ •ํ•˜์„ธ์š”

์˜ˆ์ œ 2: ๊ฐœ์„ ๋œ ํ”„๋กฌํ”„ํŠธ์™€ ๋น„๊ต

# ๊ฐœ์„  ์ „ ํ”„๋กฌํ”„ํŠธ
bad_prompt = "Python์œผ๋กœ ์›น ํฌ๋กค๋Ÿฌ๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์–ด์š”."

# ๊ฐœ์„  ํ›„ ํ”„๋กฌํ”„ํŠธ
good_prompt = """
Python๊ณผ BeautifulSoup์„ ์‚ฌ์šฉํ•˜์—ฌ ๋„ค์ด๋ฒ„ ๋‰ด์Šค ๊ธฐ์‚ฌ๋ฅผ ํฌ๋กค๋งํ•˜๋Š” 
์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

์š”๊ตฌ์‚ฌํ•ญ:
1. ํŠน์ • ํ‚ค์›Œ๋“œ(์˜ˆ: 'AI ๊ธฐ์ˆ ')๋กœ ๊ฒ€์ƒ‰๋œ ๊ธฐ์‚ฌ ์ œ๋ชฉ, ๋ณธ๋ฌธ, ์ž‘์„ฑ์ผ์ž๋ฅผ ์ถ”์ถœ
2. ์ตœ์‹  ๊ธฐ์‚ฌ 20๊ฐœ๋ฅผ ์ˆ˜์ง‘
3. ๊ฒฐ๊ณผ๋ฅผ CSV ํŒŒ์ผ๋กœ ์ €์žฅ
4. robots.txt๋ฅผ ์ค€์ˆ˜ํ•˜๊ณ  ์ ์ ˆํ•œ ๋”œ๋ ˆ์ด(1์ดˆ) ์ถ”๊ฐ€
5. ์—๋Ÿฌ ํ•ธ๋“ค๋ง ํฌํ•จ

์ถœ๋ ฅ ํ˜•์‹:
- ์ฃผ์„์ด ํฌํ•จ๋œ ์™„์ „ํ•œ Python ์ฝ”๋“œ
- ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜ ๋ช…๋ น์–ด
- ์‚ฌ์šฉ ์˜ˆ์‹œ
"""

# ๋‘ ํ”„๋กฌํ”„ํŠธ ๋น„๊ต
comparison = evaluator.compare_prompts(bad_prompt, good_prompt)

print(f"์Šน์ž: {comparison['winner']}")
print(f"์ ์ˆ˜ ์ฐจ์ด: {comparison['score_difference']:.1f}์ ")
print(f"\nํ”„๋กฌํ”„ํŠธ 1 ์ ์ˆ˜: {comparison['prompt1']['score']}/10")
print(f"ํ”„๋กฌํ”„ํŠธ 2 ์ ์ˆ˜: {comparison['prompt2']['score']}/10")

์˜ˆ์ œ 3: ๋ฐฐ์น˜ ํ‰๊ฐ€๋กœ ์—ฌ๋Ÿฌ ๋ฒ„์ „ ํ…Œ์ŠคํŠธ

# ์—ฌ๋Ÿฌ ๋ฒ„์ „์˜ ํ”„๋กฌํ”„ํŠธ ์ค€๋น„
prompts_to_test = [
    "๋ฐ์ดํ„ฐ ๋ถ„์„ ์ฝ”๋“œ ์ž‘์„ฑํ•ด์ค˜",
    
    "Python pandas๋ฅผ ์‚ฌ์šฉํ•ด์„œ CSV ํŒŒ์ผ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์„ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ค˜",
    
    """
    Python pandas๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ sales_data.csv ํŒŒ์ผ์„ ๋ถ„์„ํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
    
    ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ:
    - ์ปฌ๋Ÿผ: date, product, quantity, price
    - ์•ฝ 10,000๊ฐœ ํ–‰
    
    ๋ถ„์„ ๋‚ด์šฉ:
    1. ์›”๋ณ„ ์ด ๋งค์ถœ ๊ณ„์‚ฐ
    2. ๊ฐ€์žฅ ๋งŽ์ด ํŒ”๋ฆฐ ์ƒ์œ„ 5๊ฐœ ์ œํ’ˆ
    3. ๋งค์ถœ ์ถ”์„ธ ์‹œ๊ฐํ™” (matplotlib ์‚ฌ์šฉ)
    
    ์ถœ๋ ฅ:
    - ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ์ฝ˜์†”์— ์ถœ๋ ฅ
    - ๊ทธ๋ž˜ํ”„๋ฅผ PNG ํŒŒ์ผ๋กœ ์ €์žฅ
    - ์ฝ”๋“œ์— ์ฃผ์„ ํฌํ•จ
    """
]

# ์ผ๊ด„ ํ‰๊ฐ€
results = evaluator.batch_evaluate(prompts_to_test)

# ๊ฒฐ๊ณผ ์ •๋ ฌ ๋ฐ ์ถœ๋ ฅ
sorted_results = sorted(
    enumerate(results, 1),
    key=lambda x: x[1]['result'].get('total_score', 0) if x[1]['success'] else 0,
    reverse=True
)

print("=== ํ‰๊ฐ€ ๊ฒฐ๊ณผ ์ˆœ์œ„ ===\n")
for rank, (idx, result) in enumerate(sorted_results, 1):
    if result['success']:
        score = result['result']['total_score']
        grade = result['result']['grade']
        print(f"{rank}์œ„: ํ”„๋กฌํ”„ํŠธ #{idx} - {score:.1f}์  ({grade}๋“ฑ๊ธ‰)")
    else:
        print(f"{rank}์œ„: ํ”„๋กฌํ”„ํŠธ #{idx} - ํ‰๊ฐ€ ์‹คํŒจ")

๐Ÿ“Š ๊ฒฐ๊ณผ ์‹œ๊ฐํ™” ๋ฐ ๋ฆฌํฌํŠธ ์ƒ์„ฑ

ํ‰๊ฐ€ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๊ธฐ ์ข‹๊ฒŒ ์‹œ๊ฐํ™”ํ•˜๋ฉด ํ›จ์”ฌ ์œ ์šฉํ•ด! ๊ฐ„๋‹จํ•œ HTML ๋ฆฌํฌํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด๋ณด์ž.

utils.py - ์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜๋“ค

import json
from datetime import datetime

def generate_html_report(evaluation_result, prompt_text, output_file='report.html'):
    """
    ํ‰๊ฐ€ ๊ฒฐ๊ณผ๋ฅผ HTML ๋ฆฌํฌํŠธ๋กœ ์ƒ์„ฑ
    
    Args:
        evaluation_result (dict): ํ‰๊ฐ€ ๊ฒฐ๊ณผ
        prompt_text (str): ํ‰๊ฐ€๋œ ํ”„๋กฌํ”„ํŠธ
        output_file (str): ์ถœ๋ ฅ ํŒŒ์ผ๋ช…
    """
    if not evaluation_result['success']:
        print(f"๋ฆฌํฌํŠธ ์ƒ์„ฑ ์‹คํŒจ: {evaluation_result.get('error')}")
        return
    
    result = evaluation_result['result']
    scores = result.get('scores', {})
    
    # ๋ ˆ์ด๋” ์ฐจํŠธ์šฉ ๋ฐ์ดํ„ฐ (Chart.js ์‚ฌ์šฉ)
    criteria = list(scores.keys())
    values = list(scores.values())
    
    html_content = f"""
    <!DOCTYPE html>
    <html lang="ko">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋ฆฌํฌํŠธ</title>
        <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
        <style>.tx-header{background:linear-gradient(135deg,#f5f7fa 0%,#e8ecf1 100%);
border-radius:16px;
padding:40px 30px;
text-align:center;
margin-bottom:40px;
border:2px solid #d4dce5}
.tx-section{margin:50px 0;
padding:25px;
background:#fafbfc;
border-radius:12px;
border-left:4px solid #a8b8d8}
.tx-highlight{background:linear-gradient(120deg,#fef5e7 0%,#fdebd0 100%);
padding:20px;
border-radius:10px;
margin:25px 0;
border:1px solid #f0d9b5}
.tx-tip{background:#e8f4f8;
padding:18px;
border-radius:10px;
margin:25px 0;
border-left:4px solid #7eb8d1}
.tx-warning{background:#fff4e6;
padding:18px;
border-radius:10px;
margin:25px 0;
border-left:4px solid #f5a962}
.tx-step{background:#ffffff;
padding:20px;
margin:20px 0;
border-radius:10px;
border:2px solid #e0e5eb}
.tx-table-wrap{overflow-x:auto;
margin:25px 0}
.tx-table{width:100%;
border-collapse:collapse;
background:#ffffff;
border-radius:8px;
overflow:hidden}
.tx-table th{background:#e8ecf1;
padding:12px;
text-align:left;
font-weight:600;
border-bottom:2px solid #d4dce5}
.tx-table td{padding:12px;
border-bottom:1px solid #e8ecf1}
.tx-emphasis{color:#5a7ba8;
font-weight:600}
.tx-subtitle{color:#6b7c93;
font-size:1.1em;
margin:15px 0}</style>
    </head>
    <body>
        <div class="header">
            <h1>๐ŸŽฏ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋ฆฌํฌํŠธ</h1>
            <p>์ƒ์„ฑ ์‹œ๊ฐ: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>
        </div>
        
        <div class="score-card">
            <h2>์ข…ํ•ฉ ํ‰๊ฐ€</h2>
            <div style="display: flex; align-items: center; gap: 30px;">
                <div class="grade">{result.get('grade', 'N/A')}</div>
                <div>
                    <h3>์ด์ : {result.get('total_score', 0):.1f}/10</h3>
                    <p>ํ‰๊ฐ€ ๊ธฐ์ค€ 5๊ฐœ ํ•ญ๋ชฉ์˜ ํ‰๊ท  ์ ์ˆ˜</p>
                </div>
            </div>
        </div>
        
        <div class="section">
            <h2>๐Ÿ“ ํ‰๊ฐ€๋œ ํ”„๋กฌํ”„ํŠธ</h2>
            <div class="prompt-box">{prompt_text}</div>
        </div>
        
        <div class="section">
            <h2>๐Ÿ“Š ์„ธ๋ถ€ ์ ์ˆ˜</h2>
            <canvas id="radarChart" width="400" height="400"></canvas>
        </div>
        
        <div class="section">
            <h2>๐Ÿ’ช ๊ฐ•์ </h2>
            {''.join([f'<div class="suggestion">โœ… {s}</div>' for s in result.get('strengths', [])])}
        </div>
        
        <div class="section">
            <h2>โš ๏ธ ์•ฝ์ </h2>
            {''.join([f'<div class="suggestion">โŒ {w}</div>' for w in result.get('weaknesses', [])])}
        </div>
        
        <div class="section">
            <h2>๐Ÿ’ก ๊ฐœ์„  ์ œ์•ˆ</h2>
            {''.join([f'<div class="suggestion">๐Ÿ”ง {s}</div>' for s in result.get('suggestions', [])])}
        </div>
        
        <div class="section">
            <h2>โœจ ๊ฐœ์„ ๋œ ๋ฒ„์ „</h2>
            <div class="improved">{result.get('improved_version', '์ œ๊ณต๋˜์ง€ ์•Š์Œ')}</div>
        </div>
        
        <script>
            const ctx = document.getElementById('radarChart').getContext('2d');
            const radarChart = new Chart(ctx, {{
                type: 'radar',
                data: {{
                    labels: {json.dumps([c.title() for c in criteria])},
                    datasets: [{{
                        label: '์ ์ˆ˜',
                        data: {json.dumps(values)},
                        backgroundColor: 'rgba(102, 126, 234, 0.2)',
                        borderColor: 'rgba(102, 126, 234, 1)',
                        borderWidth: 2,
                        pointBackgroundColor: 'rgba(102, 126, 234, 1)',
                        pointBorderColor: '#fff',
                        pointHoverBackgroundColor: '#fff',
                        pointHoverBorderColor: 'rgba(102, 126, 234, 1)'
                    }}]
                }},
                options: {{
                    scales: {{
                        r: {{
                            beginAtZero: true,
                            max: 10,
                            ticks: {{
                                stepSize: 2
                            }}
                        }}
                    }},
                    plugins: {{
                        legend: {{
                            display: false
                        }}
                    }}
                }}
            }});
        </script>
    </body>
    </html>
    """
    
    with open(output_file, 'w', encoding='utf-8') as f:
        f.write(html_content)
    
    print(f"โœ… ๋ฆฌํฌํŠธ๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค: {output_file}")

def save_evaluation_log(evaluation_result, prompt_text, log_file='evaluation_log.json'):
    """
    ํ‰๊ฐ€ ๊ฒฐ๊ณผ๋ฅผ JSON ๋กœ๊ทธ๋กœ ์ €์žฅ
    
    Args:
        evaluation_result (dict): ํ‰๊ฐ€ ๊ฒฐ๊ณผ
        prompt_text (str): ํ‰๊ฐ€๋œ ํ”„๋กฌํ”„ํŠธ
        log_file (str): ๋กœ๊ทธ ํŒŒ์ผ๋ช…
    """
    log_entry = {
        'timestamp': datetime.now().isoformat(),
        'prompt': prompt_text,
        'evaluation': evaluation_result
    }
    
    # ๊ธฐ์กด ๋กœ๊ทธ ์ฝ๊ธฐ
    try:
        with open(log_file, 'r', encoding='utf-8') as f:
            logs = json.load(f)
    except FileNotFoundError:
        logs = []
    
    # ์ƒˆ ๋กœ๊ทธ ์ถ”๊ฐ€
    logs.append(log_entry)
    
    # ์ €์žฅ
    with open(log_file, 'w', encoding='utf-8') as f:
        json.dump(logs, f, ensure_ascii=False, indent=2)
    
    print(f"โœ… ๋กœ๊ทธ๊ฐ€ ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค: {log_file}")

def calculate_statistics(log_file='evaluation_log.json'):
    """
    ์ €์žฅ๋œ ํ‰๊ฐ€ ๋กœ๊ทธ์—์„œ ํ†ต๊ณ„ ๊ณ„์‚ฐ
    
    Args:
        log_file (str): ๋กœ๊ทธ ํŒŒ์ผ๋ช…
        
    Returns:
        dict: ํ†ต๊ณ„ ์ •๋ณด
    """
    try:
        with open(log_file, 'r', encoding='utf-8') as f:
            logs = json.load(f)
    except FileNotFoundError:
        return {'error': '๋กœ๊ทธ ํŒŒ์ผ์ด ์—†์Šต๋‹ˆ๋‹ค'}
    
    if not logs:
        return {'error': 'ํ‰๊ฐ€ ๊ธฐ๋ก์ด ์—†์Šต๋‹ˆ๋‹ค'}
    
    total_scores = []
    criteria_scores = {
        'clarity': [],
        'specificity': [],
        'context': [],
        'structure': [],
        'constraints': []
    }
    
    for log in logs:
        if log['evaluation']['success']:
            result = log['evaluation']['result']
            total_scores.append(result.get('total_score', 0))
            
            for criterion, score in result.get('scores', {}).items():
                if criterion in criteria_scores:
                    criteria_scores[criterion].append(score)
    
    if not total_scores:
        return {'error': '์œ ํšจํ•œ ํ‰๊ฐ€ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค'}
    
    # ํ†ต๊ณ„ ๊ณ„์‚ฐ
    stats = {
        'total_evaluations': len(logs),
        'average_score': sum(total_scores) / len(total_scores),
        'max_score': max(total_scores),
        'min_score': min(total_scores),
        'criteria_averages': {
            criterion: sum(scores) / len(scores) if scores else 0
            for criterion, scores in criteria_scores.items()
        }
    }
    
    return stats

๋ฆฌํฌํŠธ ์ƒ์„ฑ ์˜ˆ์ œ

from evaluator import PromptEvaluator
from utils import generate_html_report, save_evaluation_log, calculate_statistics

# ํ‰๊ฐ€ ์‹คํ–‰
evaluator = PromptEvaluator()
test_prompt = "Python์œผ๋กœ ๋จธ์‹ ๋Ÿฌ๋‹ ๋ชจ๋ธ์„ ๋งŒ๋“ค์–ด์ค˜"
result = evaluator.evaluate(test_prompt)

# HTML ๋ฆฌํฌํŠธ ์ƒ์„ฑ
generate_html_report(result, test_prompt, 'my_evaluation.html')

# JSON ๋กœ๊ทธ ์ €์žฅ
save_evaluation_log(result, test_prompt)

# ํ†ต๊ณ„ ํ™•์ธ
stats = calculate_statistics()
print("\n=== ํ‰๊ฐ€ ํ†ต๊ณ„ ===")
print(f"์ด ํ‰๊ฐ€ ํšŸ์ˆ˜: {stats['total_evaluations']}")
print(f"ํ‰๊ท  ์ ์ˆ˜: {stats['average_score']:.2f}")
print(f"์ตœ๊ณ  ์ ์ˆ˜: {stats['max_score']:.2f}")
print(f"์ตœ์ € ์ ์ˆ˜: {stats['min_score']:.2f}")

๐Ÿš€ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ํ•˜๊ธฐ

๊ธฐ๋ณธ ๊ธฐ๋Šฅ์€ ์™„์„ฑํ–ˆ์œผ๋‹ˆ, ์ด์ œ ๋” ์‹ค์šฉ์ ์ธ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ๋“ค์„ ์ถ”๊ฐ€ํ•ด๋ณด์ž!

1. ํ”„๋กฌํ”„ํŠธ ์ž๋™ ๊ฐœ์„  ๊ธฐ๋Šฅ

ํ‰๊ฐ€๋งŒ ํ•˜๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ, ์ž๋™์œผ๋กœ ๊ฐœ์„ ๋œ ๋ฒ„์ „์„ ์ƒ์„ฑํ•˜๊ณ  ๋‹ค์‹œ ํ‰๊ฐ€ํ•˜๋Š” ๋ฐ˜๋ณต ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์–ด.

class PromptEvaluator:
    # ... ๊ธฐ์กด ์ฝ”๋“œ ...
    
    def iterative_improvement(self, initial_prompt, max_iterations=3, target_score=8.0):
        """
        ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋ฐ˜๋ณต์ ์œผ๋กœ ๊ฐœ์„ 
        
        Args:
            initial_prompt (str): ์ดˆ๊ธฐ ํ”„๋กฌํ”„ํŠธ
            max_iterations (int): ์ตœ๋Œ€ ๋ฐ˜๋ณต ํšŸ์ˆ˜
            target_score (float): ๋ชฉํ‘œ ์ ์ˆ˜
            
        Returns:
            dict: ๊ฐœ์„  ๊ณผ์ • ๋ฐ ์ตœ์ข… ๊ฒฐ๊ณผ
        """
        current_prompt = initial_prompt
        history = []
        
        for iteration in range(max_iterations):
            print(f"\n=== ๋ฐ˜๋ณต {iteration + 1}/{max_iterations} ===")
            
            # ํ˜„์žฌ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€
            result = self.evaluate(current_prompt)
            
            if not result['success']:
                break
            
            current_score = result['result'].get('total_score', 0)
            print(f"ํ˜„์žฌ ์ ์ˆ˜: {current_score:.2f}/10")
            
            # ๊ธฐ๋ก ์ €์žฅ
            history.append({
                'iteration': iteration + 1,
                'prompt': current_prompt,
                'score': current_score,
                'evaluation': result['result']
            })
            
            # ๋ชฉํ‘œ ๋‹ฌ์„ฑ ํ™•์ธ
            if current_score >= target_score:
                print(f"โœ… ๋ชฉํ‘œ ์ ์ˆ˜ ๋‹ฌ์„ฑ! ({current_score:.2f} >= {target_score})")
                break
            
            # ๊ฐœ์„ ๋œ ๋ฒ„์ „์œผ๋กœ ์—…๋ฐ์ดํŠธ
            improved = result['result'].get('improved_version')
            if improved and improved != current_prompt:
                current_prompt = improved
                print("๐Ÿ”„ ํ”„๋กฌํ”„ํŠธ ๊ฐœ์„  ์ค‘...")
            else:
                print("โš ๏ธ ๋” ์ด์ƒ ๊ฐœ์„ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
                break
        
        return {
            'initial_prompt': initial_prompt,
            'final_prompt': current_prompt,
            'initial_score': history[0]['score'] if history else 0,
            'final_score': history[-1]['score'] if history else 0,
            'improvement': history[-1]['score'] - history[0]['score'] if len(history) > 1 else 0,
            'iterations': len(history),
            'history': history
        }

2. ํ”„๋กฌํ”„ํŠธ ํ…œํ”Œ๋ฆฟ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กฌํ”„ํŠธ ํŒจํ„ด์„ ํ…œํ”Œ๋ฆฟ์œผ๋กœ ์ €์žฅํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ๊ธฐ๋Šฅ์ด์•ผ.

class PromptTemplateLibrary:
    """ํ”„๋กฌํ”„ํŠธ ํ…œํ”Œ๋ฆฟ ๊ด€๋ฆฌ ํด๋ž˜์Šค"""
    
    def __init__(self, templates_file='templates.json'):
        self.templates_file = templates_file
        self.templates = self._load_templates()
    
    def _load_templates(self):
        """ํ…œํ”Œ๋ฆฟ ํŒŒ์ผ ๋กœ๋“œ"""
        try:
            with open(self.templates_file, 'r', encoding='utf-8') as f:
                return json.load(f)
        except FileNotFoundError:
            return {}
    
    def save_template(self, name, prompt, category='general', tags=None):
        """
        ํ…œํ”Œ๋ฆฟ ์ €์žฅ
        
        Args:
            name (str): ํ…œํ”Œ๋ฆฟ ์ด๋ฆ„
            prompt (str): ํ”„๋กฌํ”„ํŠธ ๋‚ด์šฉ
            category (str): ์นดํ…Œ๊ณ ๋ฆฌ
            tags (list): ํƒœ๊ทธ ๋ฆฌ์ŠคํŠธ
        """
        self.templates[name] = {
            'prompt': prompt,
            'category': category,
            'tags': tags or [],
            'created_at': datetime.now().isoformat()
        }
        
        with open(self.templates_file, 'w', encoding='utf-8') as f:
            json.dump(self.templates, f, ensure_ascii=False, indent=2)
        
        print(f"โœ… ํ…œํ”Œ๋ฆฟ '{name}' ์ €์žฅ ์™„๋ฃŒ")
    
    def get_template(self, name):
        """ํ…œํ”Œ๋ฆฟ ๊ฐ€์ ธ์˜ค๊ธฐ"""
        return self.templates.get(name)
    
    def list_templates(self, category=None):
        """ํ…œํ”Œ๋ฆฟ ๋ชฉ๋ก ์กฐํšŒ"""
        if category:
            return {
                name: info for name, info in self.templates.items()
                if info['category'] == category
            }
        return self.templates
    
    def search_by_tag(self, tag):
        """ํƒœ๊ทธ๋กœ ํ…œํ”Œ๋ฆฟ ๊ฒ€์ƒ‰"""
        return {
            name: info for name, info in self.templates.items()
            if tag in info.get('tags', [])
        }

# ์‚ฌ์šฉ ์˜ˆ์ œ
library = PromptTemplateLibrary()

# ๊ณ ํ’ˆ์งˆ ํ…œํ”Œ๋ฆฟ ์ €์žฅ
library.save_template(
    name='code_generation_template',
    prompt="""
    [ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด]๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ [์ž‘์—… ์„ค๋ช…]์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
    
    ์š”๊ตฌ์‚ฌํ•ญ:
    1. [๊ตฌ์ฒด์  ์š”๊ตฌ์‚ฌํ•ญ 1]
    2. [๊ตฌ์ฒด์  ์š”๊ตฌ์‚ฌํ•ญ 2]
    3. [๊ตฌ์ฒด์  ์š”๊ตฌ์‚ฌํ•ญ 3]
    
    ์ œ์•ฝ์กฐ๊ฑด:
    - [์ œ์•ฝ์กฐ๊ฑด 1]
    - [์ œ์•ฝ์กฐ๊ฑด 2]
    
    ์ถœ๋ ฅ ํ˜•์‹:
    - ์ฃผ์„์ด ํฌํ•จ๋œ ์™„์ „ํ•œ ์ฝ”๋“œ
    - ์‚ฌ์šฉ ์˜ˆ์‹œ
    - ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ชฉ๋ก
    """,
    category='coding',
    tags=['code', 'programming', 'template']
)

# ํ…œํ”Œ๋ฆฟ ์‚ฌ์šฉ
template = library.get_template('code_generation_template')
if template:
    # ๋ณ€์ˆ˜ ์น˜ํ™˜
    actual_prompt = template['prompt'].replace(
        '[ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด]', 'Python'
    ).replace(
        '[์ž‘์—… ์„ค๋ช…]', '์›น ์Šคํฌ๋ž˜ํ•‘'
    )
    # ... ๋‚˜๋จธ์ง€ ๋ณ€์ˆ˜๋“ค๋„ ์น˜ํ™˜ ...

3. ์‹ค์‹œ๊ฐ„ ๋ชจ๋‹ˆํ„ฐ๋ง ๋Œ€์‹œ๋ณด๋“œ

Flask๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ„๋‹จํ•œ ์›น ๋Œ€์‹œ๋ณด๋“œ๋ฅผ ๋งŒ๋“ค ์ˆ˜๋„ ์žˆ์–ด!

from flask import Flask, render_template, request, jsonify
from evaluator import PromptEvaluator

app = Flask(__name__)
evaluator = PromptEvaluator()

@app.route('/')
def index():
    return render_template('dashboard.html')

@app.route('/api/evaluate', methods=['POST'])
def api_evaluate():
    """ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ API ์—”๋“œํฌ์ธํŠธ"""
    data = request.json
    prompt = data.get('prompt', '')
    
    if not prompt:
        return jsonify({'error': 'ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”'}), 400
    
    result = evaluator.evaluate(prompt)
    return jsonify(result)

@app.route('/api/compare', methods=['POST'])
def api_compare():
    """ํ”„๋กฌํ”„ํŠธ ๋น„๊ต API ์—”๋“œํฌ์ธํŠธ"""
    data = request.json
    prompt1 = data.get('prompt1', '')
    prompt2 = data.get('prompt2', '')
    
    if not prompt1 or not prompt2:
        return jsonify({'error': '๋‘ ๊ฐœ์˜ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”'}), 400
    
    result = evaluator.compare_prompts(prompt1, prompt2)
    return jsonify(result)

if __name__ == '__main__':
    app.run(debug=True, port=5000)
๐Ÿ’ก ์‹ค์ „ ํŒ: ์›น ๋Œ€์‹œ๋ณด๋“œ๋ฅผ ๋งŒ๋“ค๋ฉด ํŒ€์›๋“ค๊ณผ ๊ณต์œ ํ•˜๊ธฐ ํ›จ์”ฌ ์‰ฌ์›Œ์ ธ! ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ํ”„๋กฌํ”„ํŠธ ์ปจ์„คํŒ… ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•  ๋•Œ๋„ ์ด๋Ÿฐ ๋„๊ตฌ๋ฅผ ๋ณด์—ฌ์ฃผ๋ฉด ์ „๋ฌธ์„ฑ์ด ํ™• ์˜ฌ๋ผ๊ฐ€๊ฑฐ๋“ . ๐Ÿ˜Ž

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™” ๋ฐ ๋น„์šฉ ๊ด€๋ฆฌ

Claude API๋Š” ํ† ํฐ ๊ธฐ๋ฐ˜ ๊ณผ๊ธˆ์ด๋ผ์„œ, ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒŒ ์ค‘์š”ํ•ด!

1. ์บ์‹ฑ ์ „๋žต

๊ฐ™์€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋ฐ˜๋ณต ํ‰๊ฐ€ํ•˜์ง€ ์•Š๋„๋ก ์บ์‹ฑ์„ ๊ตฌํ˜„ํ•˜์ž.

import hashlib
import pickle
from pathlib import Path

class CachedEvaluator(PromptEvaluator):
    """์บ์‹ฑ ๊ธฐ๋Šฅ์ด ์ถ”๊ฐ€๋œ ํ‰๊ฐ€๊ธฐ"""
    
    def __init__(self, api_key=None, cache_dir='cache'):
        super().__init__(api_key)
        self.cache_dir = Path(cache_dir)
        self.cache_dir.mkdir(exist_ok=True)
    
    def _get_cache_key(self, prompt_text):
        """ํ”„๋กฌํ”„ํŠธ์˜ ํ•ด์‹œ ํ‚ค ์ƒ์„ฑ"""
        return hashlib.md5(prompt_text.encode()).hexdigest()
    
    def _get_cache_path(self, cache_key):
        """์บ์‹œ ํŒŒ์ผ ๊ฒฝ๋กœ"""
        return self.cache_dir / f"{cache_key}.pkl"
    
    def evaluate(self, prompt_text, use_cache=True, **kwargs):
        """
        ์บ์‹ฑ์„ ์ง€์›ํ•˜๋Š” ํ‰๊ฐ€
        
        Args:
            prompt_text (str): ํ‰๊ฐ€ํ•  ํ”„๋กฌํ”„ํŠธ
            use_cache (bool): ์บ์‹œ ์‚ฌ์šฉ ์—ฌ๋ถ€
        """
        if use_cache:
            cache_key = self._get_cache_key(prompt_text)
            cache_path = self._get_cache_path(cache_key)
            
            # ์บ์‹œ ํ™•์ธ
            if cache_path.exists():
                print("๐Ÿ“ฆ ์บ์‹œ์—์„œ ๊ฒฐ๊ณผ ๋กœ๋“œ")
                with open(cache_path, 'rb') as f:
                    return pickle.load(f)
        
        # ์‹ค์ œ ํ‰๊ฐ€ ์ˆ˜ํ–‰
        result = super().evaluate(prompt_text, **kwargs)
        
        # ์บ์‹œ ์ €์žฅ
        if use_cache and result['success']:
            cache_key = self._get_cache_key(prompt_text)
            cache_path = self._get_cache_path(cache_key)
            with open(cache_path, 'wb') as f:
                pickle.dump(result, f)
        
        return result
    
    def clear_cache(self):
        """์บ์‹œ ์ „์ฒด ์‚ญ์ œ"""
        for cache_file in self.cache_dir.glob('*.pkl'):
            cache_file.unlink()
        print("๐Ÿ—‘๏ธ ์บ์‹œ ์‚ญ์ œ ์™„๋ฃŒ")

2. ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ ์ตœ์ ํ™”

์—ฌ๋Ÿฌ ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ‰๊ฐ€ํ•  ๋•Œ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๋กœ ์†๋„๋ฅผ ๋†’์ผ ์ˆ˜ ์žˆ์–ด.

from concurrent.futures import ThreadPoolExecutor, as_completed

class OptimizedEvaluator(CachedEvaluator):
    """์ตœ์ ํ™”๋œ ํ‰๊ฐ€๊ธฐ"""
    
    def batch_evaluate_parallel(self, prompts_list, max_workers=3):
        """
        ๋ณ‘๋ ฌ ๋ฐฐ์น˜ ํ‰๊ฐ€
        
        Args:
            prompts_list (list): ํ”„๋กฌํ”„ํŠธ ๋ฆฌ์ŠคํŠธ
            max_workers (int): ๋™์‹œ ์‹คํ–‰ ์›Œ์ปค ์ˆ˜
        """
        results = []
        
        with ThreadPoolExecutor(max_workers=max_workers) as executor:
            # ๋ชจ๋“  ์ž‘์—… ์ œ์ถœ
            future_to_prompt = {
                executor.submit(self.evaluate, prompt): prompt
                for prompt in prompts_list
            }
            
            # ์™„๋ฃŒ๋œ ์ž‘์—… ์ˆ˜์ง‘
            for future in as_completed(future_to_prompt):
                prompt = future_to_prompt[future]
                try:
                    result = future.result()
                    results.append(result)
                    print(f"โœ… ์™„๋ฃŒ: {len(results)}/{len(prompts_list)}")
                except Exception as e:
                    print(f"โŒ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {e}")
                    results.append({'success': False, 'error': str(e)})
        
        return results

3. ๋น„์šฉ ์ถ”์ 

API ์‚ฌ์šฉ๋Ÿ‰๊ณผ ์˜ˆ์ƒ ๋น„์šฉ์„ ์ถ”์ ํ•˜๋Š” ๊ธฐ๋Šฅ์ด์•ผ.

class CostTracker:
    """API ๋น„์šฉ ์ถ”์  ํด๋ž˜์Šค"""
    
    # Claude 3 Sonnet ๊ฐ€๊ฒฉ (2024๋…„ ๊ธฐ์ค€, ์‹ค์ œ ๊ฐ€๊ฒฉ์€ ํ™•์ธ ํ•„์š”)
    PRICE_PER_1K_INPUT_TOKENS = 0.003  # $0.003 per 1K tokens
    PRICE_PER_1K_OUTPUT_TOKENS = 0.015  # $0.015 per 1K tokens
    
    def __init__(self):
        self.total_input_tokens = 0
        self.total_output_tokens = 0
        self.request_count = 0
    
    def add_usage(self, input_tokens, output_tokens):
        """์‚ฌ์šฉ๋Ÿ‰ ์ถ”๊ฐ€"""
        self.total_input_tokens += input_tokens
        self.total_output_tokens += output_tokens
        self.request_count += 1
    
    def get_cost(self):
        """์˜ˆ์ƒ ๋น„์šฉ ๊ณ„์‚ฐ"""
        input_cost = (self.total_input_tokens / 1000) * self.PRICE_PER_1K_INPUT_TOKENS
        output_cost = (self.total_output_tokens / 1000) * self.PRICE_PER_1K_OUTPUT_TOKENS
        return {
            'input_cost': input_cost,
            'output_cost': output_cost,
            'total_cost': input_cost + output_cost,
            'total_tokens': self.total_input_tokens + self.total_output_tokens,
            'request_count': self.request_count
        }
    
    def print_summary(self):
        """๋น„์šฉ ์š”์•ฝ ์ถœ๋ ฅ"""
        cost = self.get_cost()
        print("\n=== ๐Ÿ’ฐ API ์‚ฌ์šฉ ๋น„์šฉ ์š”์•ฝ ===")
        print(f"์ด ์š”์ฒญ ์ˆ˜: {cost['request_count']}")
        print(f"์ด ํ† ํฐ ์ˆ˜: {cost['total_tokens']:,}")
        print(f"  - ์ž…๋ ฅ: {self.total_input_tokens:,} tokens")
        print(f"  - ์ถœ๋ ฅ: {self.total_output_tokens:,} tokens")
        print(f"์˜ˆ์ƒ ๋น„์šฉ: ${cost['total_cost']:.4f}")
        print(f"  - ์ž…๋ ฅ ๋น„์šฉ: ${cost['input_cost']:.4f}")
        print(f"  - ์ถœ๋ ฅ ๋น„์šฉ: ${cost['output_cost']:.4f}")

# ํ‰๊ฐ€๊ธฐ์— ํ†ตํ•ฉ
class CostAwareEvaluator(OptimizedEvaluator):
    """๋น„์šฉ ์ถ”์  ๊ธฐ๋Šฅ์ด ์žˆ๋Š” ํ‰๊ฐ€๊ธฐ"""
    
    def __init__(self, api_key=None, cache_dir='cache'):
        super().__init__(api_key, cache_dir)
        self.cost_tracker = CostTracker()
    
    def evaluate(self, prompt_text, **kwargs):
        """๋น„์šฉ ์ถ”์ ๊ณผ ํ•จ๊ป˜ ํ‰๊ฐ€"""
        result = super().evaluate(prompt_text, **kwargs)
        
        # ์‚ฌ์šฉ๋Ÿ‰ ๊ธฐ๋ก
        if result['success'] and 'usage' in result:
            usage = result['usage']
            self.cost_tracker.add_usage(
                usage['input_tokens'],
                usage['output_tokens']
            )
        
        return result
    
    def get_cost_summary(self):
        """๋น„์šฉ ์š”์•ฝ ๋ฐ˜ํ™˜"""
        return self.cost_tracker.get_cost()
    
    def print_cost_summary(self):
        """๋น„์šฉ ์š”์•ฝ ์ถœ๋ ฅ"""
        self.cost_tracker.print_summary()
โš ๏ธ ๋น„์šฉ ๊ด€๋ฆฌ ์ฃผ์˜์‚ฌํ•ญ: โ€ข API ํ‚ค์— ์‚ฌ์šฉ ํ•œ๋„๋ฅผ ์„ค์ •ํ•ด๋‘๋Š” ๊ฒŒ ์•ˆ์ „ํ•ด
โ€ข ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์—์„œ๋Š” ๋ฐ˜๋“œ์‹œ ์บ์‹ฑ์„ ํ™œ์šฉํ•˜์ž
โ€ข ๋ฐฐ์น˜ ์ž‘์—… ์ „์— ์˜ˆ์ƒ ๋น„์šฉ์„ ๊ณ„์‚ฐํ•ด๋ณด๋Š” ์Šต๊ด€์„ ๋“ค์ด์ž
โ€ข ๋ฌด๋ฃŒ ํฌ๋ ˆ๋”ง์ด ์†Œ์ง„๋˜๋ฉด ์ž๋™์œผ๋กœ ๊ณผ๊ธˆ๋˜๋‹ˆ ์ฃผ์˜!

๐Ÿ”ง ์‹ค์ „ ํ™œ์šฉ ์‹œ๋‚˜๋ฆฌ์˜ค

์ด์ œ ์‹ค์ œ ์—…๋ฌด์—์„œ ์–ด๋–ป๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ตฌ์ฒด์ ์ธ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์‚ดํŽด๋ณด์ž!

์‹œ๋‚˜๋ฆฌ์˜ค 1: ํ”„๋กฌํ”„ํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ’ˆ์งˆ ๊ด€๋ฆฌ

ํšŒ์‚ฌ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ํ”„๋กฌํ”„ํŠธ์˜ ํ’ˆ์งˆ์„ ์ •๊ธฐ์ ์œผ๋กœ ์ ๊ฒ€ํ•˜๋Š” ์‹œ์Šคํ…œ์ด์•ผ.

import os
from pathlib import Path

def audit_prompt_library(library_dir, output_report='audit_report.html'):
    """
    ํ”„๋กฌํ”„ํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ „์ฒด ๊ฐ์‚ฌ
    
    Args:
        library_dir (str): ํ”„๋กฌํ”„ํŠธ ํŒŒ์ผ๋“ค์ด ์žˆ๋Š” ๋””๋ ‰ํ† ๋ฆฌ
        output_report (str): ๊ฐ์‚ฌ ๋ฆฌํฌํŠธ ํŒŒ์ผ๋ช…
    """
    evaluator = CostAwareEvaluator()
    library_path = Path(library_dir)
    
    # ๋ชจ๋“  .txt ํŒŒ์ผ ์ฐพ๊ธฐ
    prompt_files = list(library_path.glob('**/*.txt'))
    
    print(f"๐Ÿ“š ์ด {len(prompt_files)}๊ฐœ์˜ ํ”„๋กฌํ”„ํŠธ ํŒŒ์ผ ๋ฐœ๊ฒฌ")
    
    audit_results = []
    
    for prompt_file in prompt_files:
        print(f"\nํ‰๊ฐ€ ์ค‘: {prompt_file.name}")
        
        # ํ”„๋กฌํ”„ํŠธ ์ฝ๊ธฐ
        with open(prompt_file, 'r', encoding='utf-8') as f:
            prompt_text = f.read()
        
        # ํ‰๊ฐ€
        result = evaluator.evaluate(prompt_text)
        
        if result['success']:
            score = result['result']['total_score']
            grade = result['result']['grade']
            
            audit_results.append({
                'file': prompt_file.name,
                'path': str(prompt_file),
                'score': score,
                'grade': grade,
                'needs_improvement': score < 7.0,
                'evaluation': result['result']
            })
            
            print(f"  ์ ์ˆ˜: {score:.1f}/10 ({grade})")
        else:
            print(f"  โŒ ํ‰๊ฐ€ ์‹คํŒจ: {result.get('error')}")
    
    # ๊ฒฐ๊ณผ ์ •๋ ฌ (๋‚ฎ์€ ์ ์ˆ˜ ์šฐ์„ )
    audit_results.sort(key=lambda x: x['score'])
    
    # ๋ฆฌํฌํŠธ ์ƒ์„ฑ
    generate_audit_report(audit_results, output_report)
    
    # ๋น„์šฉ ์š”์•ฝ
    evaluator.print_cost_summary()
    
    # ๊ฐœ์„  ํ•„์š” ํ•ญ๋ชฉ ์ถœ๋ ฅ
    needs_improvement = [r for r in audit_results if r['needs_improvement']]
    if needs_improvement:
        print(f"\nโš ๏ธ ๊ฐœ์„ ์ด ํ•„์š”ํ•œ ํ”„๋กฌํ”„ํŠธ: {len(needs_improvement)}๊ฐœ")
        for item in needs_improvement[:5]:  # ์ƒ์œ„ 5๊ฐœ๋งŒ
            print(f"  โ€ข {item['file']}: {item['score']:.1f}์ ")
    
    return audit_results

def generate_audit_report(audit_results, output_file):
    """๊ฐ์‚ฌ ๋ฆฌํฌํŠธ HTML ์ƒ์„ฑ"""
    # ... HTML ์ƒ์„ฑ ์ฝ”๋“œ (์•ž์˜ ๋ฆฌํฌํŠธ ์ƒ์„ฑ ํ•จ์ˆ˜ ์ฐธ๊ณ ) ...
    pass

# ์‹คํ–‰
if __name__ == '__main__':
    results = audit_prompt_library('prompts_library/', 'quality_audit.html')

์‹œ๋‚˜๋ฆฌ์˜ค 2: A/B ํ…Œ์ŠคํŠธ ์ž๋™ํ™”

์—ฌ๋Ÿฌ ๋ฒ„์ „์˜ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž๋™์œผ๋กœ ํ…Œ์ŠคํŠธํ•˜๊ณ  ์ตœ์ ์˜ ๋ฒ„์ „์„ ์ฐพ๋Š” ์‹œ์Šคํ…œ์ด์•ผ.

def ab_test_prompts(variants, test_cases, evaluator=None):
    """
    ํ”„๋กฌํ”„ํŠธ A/B ํ…Œ์ŠคํŠธ
    
    Args:
        variants (dict): {'A': prompt_a, 'B': prompt_b, ...}
        test_cases (list): ํ…Œ์ŠคํŠธํ•  ์ž…๋ ฅ ์ผ€์ด์Šค๋“ค
        evaluator: ํ‰๊ฐ€๊ธฐ ์ธ์Šคํ„ด์Šค
    """
    if evaluator is None:
        evaluator = CostAwareEvaluator()
    
    results = {variant: [] for variant in variants}
    
    print(f"๐Ÿงช A/B ํ…Œ์ŠคํŠธ ์‹œ์ž‘: {len(variants)}๊ฐœ ๋ณ€ํ˜•, {len(test_cases)}๊ฐœ ์ผ€์ด์Šค\n")
    
    for variant_name, prompt_template in variants.items():
        print(f"=== ๋ณ€ํ˜• {variant_name} ํ…Œ์ŠคํŠธ ์ค‘ ===")
        
        for i, test_case in enumerate(test_cases, 1):
            # ํ…œํ”Œ๋ฆฟ์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ์ ์šฉ
            actual_prompt = prompt_template.format(**test_case)
            
            # ํ‰๊ฐ€
            result = evaluator.evaluate(actual_prompt)
            
            if result['success']:
                score = result['result']['total_score']
                results[variant_name].append({
                    'test_case': i,
                    'score': score,
                    'evaluation': result['result']
                })
                print(f"  ์ผ€์ด์Šค {i}: {score:.1f}์ ")
        
        # ๋ณ€ํ˜•๋ณ„ ํ‰๊ท  ์ ์ˆ˜
        avg_score = sum(r['score'] for r in results[variant_name]) / len(results[variant_name])
        print(f"  ํ‰๊ท  ์ ์ˆ˜: {avg_score:.2f}/10\n")
    
    # ์Šน์ž ๊ฒฐ์ •
    average_scores = {
        variant: sum(r['score'] for r in scores) / len(scores)
        for variant, scores in results.items()
    }
    
    winner = max(average_scores, key=average_scores.get)
    
    print("\n๐Ÿ† ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ")
    print("=" * 50)
    for variant, avg_score in sorted(average_scores.items(), key=lambda x: x[1], reverse=True):
        status = "๐Ÿ‘‘ ์Šน์ž" if variant == winner else ""
        print(f"{variant}: {avg_score:.2f}์  {status}")
    
    evaluator.print_cost_summary()
    
    return {
        'winner': winner,
        'scores': average_scores,
        'detailed_results': results
    }

# ์‚ฌ์šฉ ์˜ˆ์ œ
variants = {
    'A': """
    {language}๋กœ {task}๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
    """,
    
    'B': """
    {language}๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ {task}๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
    
    ์š”๊ตฌ์‚ฌํ•ญ:
    - ๋ช…ํ™•ํ•œ ์ฃผ์„ ํฌํ•จ
    - ์—๋Ÿฌ ํ•ธ๋“ค๋ง
    - ์‚ฌ์šฉ ์˜ˆ์‹œ ์ œ๊ณต
    """,
    
    'C': """
    ๋‹น์‹ ์€ ์ˆ™๋ จ๋œ {language} ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค.
    
    ๋‹ค์Œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ํ”„๋กœ๋•์…˜ ๋ ˆ๋ฒจ์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”:
    {task}
    
    ์š”๊ตฌ์‚ฌํ•ญ:
    1. ํƒ€์ž… ํžŒํŠธ ์‚ฌ์šฉ
    2. Docstring ํฌํ•จ
    3. ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ
    4. ์—๋Ÿฌ ํ•ธ๋“ค๋ง
    5. ๋กœ๊น…
    
    ์ถœ๋ ฅ ํ˜•์‹:
    - ๋ฉ”์ธ ์ฝ”๋“œ
    - ํ…Œ์ŠคํŠธ ์ฝ”๋“œ
    - ์‚ฌ์šฉ ์˜ˆ์‹œ
    - README
    """
}

test_cases = [
    {'language': 'Python', 'task': '์›น ์Šคํฌ๋ž˜ํ•‘'},
    {'language': 'Python', 'task': 'CSV ํŒŒ์ผ ์ฒ˜๋ฆฌ'},
    {'language': 'JavaScript', 'task': 'REST API ํด๋ผ์ด์–ธํŠธ'}
]

results = ab_test_prompts(variants, test_cases)

์‹œ๋‚˜๋ฆฌ์˜ค 3: CI/CD ํŒŒ์ดํ”„๋ผ์ธ ํ†ตํ•ฉ

GitHub Actions๋‚˜ GitLab CI์—์„œ ํ”„๋กฌํ”„ํŠธ ํ’ˆ์งˆ์„ ์ž๋™์œผ๋กœ ๊ฒ€์‚ฌํ•˜๋Š” ์›Œํฌํ”Œ๋กœ์šฐ์•ผ.

# .github/workflows/prompt-quality-check.yml
name: Prompt Quality Check

on:
  pull_request:
    paths:
      - 'prompts/**/*.txt'
      - 'prompts/**/*.md'

jobs:
  quality-check:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v2
    
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.10'
    
    - name: Install dependencies
      run: |
        pip install anthropic python-dotenv
    
    - name: Run quality check
      env:
        ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
      run: |
        python scripts/check_prompt_quality.py
    
    - name: Comment PR
      uses: actions/github-script@v5
      with:
        script: |
          const fs = require('fs');
          const report = fs.readFileSync('quality_report.md', 'utf8');
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: report
          });
# scripts/check_prompt_quality.py
import sys
from pathlib import Path
from evaluator import PromptEvaluator

def check_changed_prompts():
    """๋ณ€๊ฒฝ๋œ ํ”„๋กฌํ”„ํŠธ ํŒŒ์ผ๋“ค์˜ ํ’ˆ์งˆ ๊ฒ€์‚ฌ"""
    evaluator = PromptEvaluator()
    
    # Git diff๋กœ ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ ์ฐพ๊ธฐ
    import subprocess
    result = subprocess.run(
        ['git', 'diff', '--name-only', 'origin/main', 'HEAD'],
        capture_output=True,
        text=True
    )
    
    changed_files = [
        f for f in result.stdout.strip().split('\n')
        if f.startswith('prompts/') and (f.endswith('.txt') or f.endswith('.md'))
    ]
    
    if not changed_files:
        print("๋ณ€๊ฒฝ๋œ ํ”„๋กฌํ”„ํŠธ ํŒŒ์ผ์ด ์—†์Šต๋‹ˆ๋‹ค.")
        return True
    
    print(f"๊ฒ€์‚ฌํ•  ํŒŒ์ผ: {len(changed_files)}๊ฐœ\n")
    
    all_passed = True
    report_lines = ["# ํ”„๋กฌํ”„ํŠธ ํ’ˆ์งˆ ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ\n"]
    
    for file_path in changed_files:
        with open(file_path, 'r', encoding='utf-8') as f:
            prompt_text = f.read()
        
        result = evaluator.evaluate(prompt_text)
        
        if result['success']:
            score = result['result']['total_score']
            grade = result['result']['grade']
            
            status = "โœ… ํ†ต๊ณผ" if score >= 7.0 else "โŒ ๊ฐœ์„  ํ•„์š”"
            passed = score >= 7.0
            
            report_lines.append(f"## {file_path}")
            report_lines.append(f"**์ ์ˆ˜**: {score:.1f}/10 ({grade})")
            report_lines.append(f"**์ƒํƒœ**: {status}\n")
            
            if not passed:
                all_passed = False
                report_lines.append("### ๊ฐœ์„  ์ œ์•ˆ")
                for suggestion in result['result'].get('suggestions', []):
                    report_lines.append(f"- {suggestion}")
                report_lines.append("")
        else:
            all_passed = False
            report_lines.append(f"## {file_path}")
            report_lines.append(f"โŒ ํ‰๊ฐ€ ์‹คํŒจ: {result.get('error')}\n")
    
    # ๋ฆฌํฌํŠธ ์ €์žฅ
    with open('quality_report.md', 'w', encoding='utf-8') as f:
        f.write('\n'.join(report_lines))
    
    return all_passed

if __name__ == '__main__':
    passed = check_changed_prompts()
    sys.exit(0 if passed else 1)

๐ŸŽ“ ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค

๋„๊ตฌ๋ฅผ ๋งŒ๋“ค์—ˆ์œผ๋‹ˆ, ์ด์ œ ์‹ค์ œ๋กœ ์ข‹์€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์•Œ์•„์•ผ๊ฒ ์ง€?

1. ๋ช…ํ™•ํ•œ ์—ญํ•  ๋ถ€์—ฌ (Role Assignment)

AI์—๊ฒŒ ๊ตฌ์ฒด์ ์ธ ์—ญํ• ์„ ๋ถ€์—ฌํ•˜๋ฉด ๋” ์ผ๊ด€๋œ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์–ด.

โŒ ๋‚˜์œ ์˜ˆ:
"์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ค˜"

โœ… ์ข‹์€ ์˜ˆ:
"๋‹น์‹ ์€ 10๋…„ ๊ฒฝ๋ ฅ์˜ ์‹œ๋‹ˆ์–ด Python ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค. ํด๋ฆฐ ์ฝ”๋“œ ์›์น™์„ ์ค€์ˆ˜ํ•˜๋ฉฐ, ํ•ญ์ƒ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค."

2. ๋‹จ๊ณ„๋ณ„ ์ง€์‹œ (Step-by-Step Instructions)

๋ณต์žกํ•œ ์ž‘์—…์€ ๋‹จ๊ณ„๋ณ„๋กœ ๋‚˜๋ˆ ์„œ ์ง€์‹œํ•˜์ž.

โœ… ์ข‹์€ ์˜ˆ:
"""
๋‹ค์Œ ๋‹จ๊ณ„๋กœ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ด์ฃผ์„ธ์š”:

1. ๋จผ์ € ๋ฐ์ดํ„ฐ๋ฅผ ๋กœ๋“œํ•˜๊ณ  ๊ธฐ๋ณธ ํ†ต๊ณ„๋ฅผ ํ™•์ธ
2. ๊ฒฐ์ธก์น˜์™€ ์ด์ƒ์น˜๋ฅผ ์ฒ˜๋ฆฌ
3. ํŠน์„ฑ ์—”์ง€๋‹ˆ์–ด๋ง ์ˆ˜ํ–‰
4. ๋ชจ๋ธ ํ•™์Šต ๋ฐ ํ‰๊ฐ€
5. ๊ฒฐ๊ณผ๋ฅผ ์‹œ๊ฐํ™”

๊ฐ ๋‹จ๊ณ„๋งˆ๋‹ค ์ฝ”๋“œ์™€ ์„ค๋ช…์„ ์ œ๊ณตํ•ด์ฃผ์„ธ์š”.
"""

3. ์˜ˆ์‹œ ์ œ๊ณต (Few-Shot Learning)

์›ํ•˜๋Š” ์ถœ๋ ฅ ํ˜•์‹์˜ ์˜ˆ์‹œ๋ฅผ ๋ณด์—ฌ์ฃผ๋ฉด ํ›จ์”ฌ ์ •ํ™•ํ•ด์ ธ.

โœ… ์ข‹์€ ์˜ˆ:
"""
๋‹ค์Œ ํ˜•์‹์œผ๋กœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”:

์˜ˆ์‹œ:
```python
def calculate_average(numbers: List[float]) -> float:
"""
์ˆซ์ž ๋ฆฌ์ŠคํŠธ์˜ ํ‰๊ท ์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.

Args:
numbers: ํ‰๊ท ์„ ๊ณ„์‚ฐํ•  ์ˆซ์ž ๋ฆฌ์ŠคํŠธ

Returns:
float: ํ‰๊ท ๊ฐ’

Raises:
ValueError: ๋นˆ ๋ฆฌ์ŠคํŠธ๊ฐ€ ์ž…๋ ฅ๋œ ๊ฒฝ์šฐ
"""
if not numbers:
raise ValueError("๋นˆ ๋ฆฌ์ŠคํŠธ์ž…๋‹ˆ๋‹ค")
return sum(numbers) / len(numbers)
```

์ด์ œ ์ค‘์•™๊ฐ’์„ ๊ณ„์‚ฐํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๊ฐ™์€ ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
"""

4. ์ œ์•ฝ์กฐ๊ฑด ๋ช…์‹œ (Constraints)

ํ•˜์ง€ ๋ง์•„์•ผ ํ•  ๊ฒƒ, ์ง€์ผœ์•ผ ํ•  ๊ทœ์น™์„ ๋ช…ํ™•ํžˆ ํ•˜์ž.

โœ… ์ข‹์€ ์˜ˆ:
"""
์ œ์•ฝ์กฐ๊ฑด:
- ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ ๊ธˆ์ง€ (ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋งŒ ์‚ฌ์šฉ)
- ํ•จ์ˆ˜ ๊ธธ์ด๋Š” 20์ค„ ์ด๋‚ด
- ์ „์—ญ ๋ณ€์ˆ˜ ์‚ฌ์šฉ ๊ธˆ์ง€
- ๋ชจ๋“  ํ•จ์ˆ˜์— ํƒ€์ž… ํžŒํŠธ ํ•„์ˆ˜
"""

5. ์ถœ๋ ฅ ํ˜•์‹ ์ง€์ • (Output Format)

์›ํ•˜๋Š” ์ถœ๋ ฅ ํ˜•์‹์„ ๊ตฌ์ฒด์ ์œผ๋กœ ๋ช…์‹œํ•˜์ž.

โœ… ์ข‹์€ ์˜ˆ:
"""
์ถœ๋ ฅ ํ˜•์‹:
```json
{
"code": "์‹ค์ œ ์ฝ”๋“œ",
"explanation": "์ฝ”๋“œ ์„ค๋ช…",
"test_cases": [
{"input": "...", "expected": "..."},
{"input": "...", "expected": "..."}
],
"complexity": {
"time": "O(n)",
"space": "O(1)"
}
}
```
"""
๐ŸŽฏ ํ”„๋กฌํ”„ํŠธ ์ฒดํฌ๋ฆฌ์ŠคํŠธ: โ˜‘๏ธ ์—ญํ• ์ด ๋ช…ํ™•ํžˆ ์ •์˜๋˜์–ด ์žˆ๋Š”๊ฐ€?
โ˜‘๏ธ ์ž‘์—…์ด ๊ตฌ์ฒด์ ์œผ๋กœ ์„ค๋ช…๋˜์–ด ์žˆ๋Š”๊ฐ€?
โ˜‘๏ธ ํ•„์š”ํ•œ ๋งฅ๋ฝ ์ •๋ณด๊ฐ€ ์ œ๊ณต๋˜์—ˆ๋Š”๊ฐ€?
โ˜‘๏ธ ๋‹จ๊ณ„๋ณ„๋กœ ๊ตฌ์กฐํ™”๋˜์–ด ์žˆ๋Š”๊ฐ€?
โ˜‘๏ธ ์˜ˆ์‹œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋Š”๊ฐ€?
โ˜‘๏ธ ์ œ์•ฝ์กฐ๊ฑด์ด ๋ช…์‹œ๋˜์–ด ์žˆ๋Š”๊ฐ€?
โ˜‘๏ธ ์ถœ๋ ฅ ํ˜•์‹์ด ์ง€์ •๋˜์–ด ์žˆ๋Š”๊ฐ€?
โ˜‘๏ธ ๊ธˆ์ง€ ์‚ฌํ•ญ์ด ๋ช…ํ™•ํ•œ๊ฐ€?

๐Ÿ› ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ… ๊ฐ€์ด๋“œ

๊ฐœ๋ฐœํ•˜๋‹ค ๋ณด๋ฉด ์—ฌ๋Ÿฌ ๋ฌธ์ œ๋ฅผ ๋งŒ๋‚˜๊ฒŒ ๋ผ. ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ์ด์Šˆ๋“ค๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ–ˆ์–ด!

๋ฌธ์ œ 1: API ํ‚ค ์ธ์ฆ ์‹คํŒจ

์ฆ์ƒ:
AuthenticationError: Invalid API key

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:
1. .env ํŒŒ์ผ์— API ํ‚ค๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž…๋ ฅ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
2. API ํ‚ค ์•ž๋’ค์— ๊ณต๋ฐฑ์ด ์—†๋Š”์ง€ ํ™•์ธ
3. Anthropic ์ฝ˜์†”์—์„œ API ํ‚ค๊ฐ€ ํ™œ์„ฑํ™”๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธ
4. ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ์ œ๋Œ€๋กœ ๋กœ๋“œ๋˜๋Š”์ง€ ํ™•์ธ:

import os
from dotenv import load_dotenv

load_dotenv()
print(f"API Key loaded: {bool(os.getenv('ANTHROPIC_API_KEY'))}")

๋ฌธ์ œ 2: JSON ํŒŒ์‹ฑ ์‹คํŒจ

์ฆ์ƒ:
Claude์˜ ์‘๋‹ต์—์„œ JSON์„ ์ถ”์ถœํ•  ์ˆ˜ ์—†์Œ

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:
1. ํ”„๋กฌํ”„ํŠธ์—์„œ JSON ํ˜•์‹์„ ๋” ๋ช…ํ™•ํžˆ ์ง€์ •
2. "๋ฐ˜๋“œ์‹œ ์œ ํšจํ•œ JSON๋งŒ ์ถœ๋ ฅํ•˜์„ธ์š”"๋ผ๊ณ  ๊ฐ•์กฐ
3. ํŒŒ์‹ฑ ๋กœ์ง ๊ฐœ์„ :

def robust_json_parse(text):
    """๋” ๊ฒฌ๊ณ ํ•œ JSON ํŒŒ์‹ฑ"""
    import re
    import json
    
    # ์—ฌ๋Ÿฌ ํŒจํ„ด ์‹œ๋„
    patterns = [
        r'```json\s*(.*?)\s*```',  # ```json ... ``` ๋ธ”๋ก
        r'```\s*(.*?)\s*```',       # ``` ... ``` ๋ธ”๋ก
        r'\{[\s\S]*\}'              # ์ค‘๊ด„ํ˜ธ๋กœ ๋‘˜๋Ÿฌ์‹ธ์ธ ๋ชจ๋“  ๊ฒƒ
    ]
    
    for pattern in patterns:
        matches = re.findall(pattern, text, re.DOTALL)
        for match in matches:
            try:
                return json.loads(match)
            except:
                continue
    
    # ๋ชจ๋“  ์‹œ๋„ ์‹คํŒจ
    raise ValueError("JSON์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")

๋ฌธ์ œ 3: ํ† ํฐ ์ œํ•œ ์ดˆ๊ณผ

์ฆ์ƒ:
Error: maximum context length exceeded

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:
1. ํ”„๋กฌํ”„ํŠธ ๊ธธ์ด ํ™•์ธ ๋ฐ ์ถ•์†Œ
2. max_tokens ๊ฐ’ ์กฐ์ •
3. ๊ธด ํ”„๋กฌํ”„ํŠธ๋Š” ์š”์•ฝํ•˜๊ฑฐ๋‚˜ ๋ถ„ํ• :

def truncate_prompt(prompt, max_length=4000):
    """ํ”„๋กฌํ”„ํŠธ๋ฅผ ์•ˆ์ „ํ•œ ๊ธธ์ด๋กœ ์ž๋ฅด๊ธฐ"""
    if len(prompt) <= max_length:
        return prompt
    
    # ์ค‘์š”ํ•œ ๋ถ€๋ถ„๋งŒ ์œ ์ง€
    parts = prompt.split('\n\n')
    truncated = []
    current_length = 0
    
    for part in parts:
        if current_length + len(part) > max_length:
            break
        truncated.append(part)
        current_length += len(part)
    
    return '\n\n'.join(truncated) + "\n\n[... ์ƒ๋žต ...]"

๋ฌธ์ œ 4: ํ‰๊ฐ€ ๊ฒฐ๊ณผ๊ฐ€ ์ผ๊ด€๋˜์ง€ ์•Š์Œ

์ฆ์ƒ:
๊ฐ™์€ ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ‰๊ฐ€ํ•ด๋„ ๋งค๋ฒˆ ๋‹ค๋ฅธ ์ ์ˆ˜๊ฐ€ ๋‚˜์˜ด

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:
1. temperature ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋‚ฎ์ถฐ์„œ ์ผ๊ด€์„ฑ ํ–ฅ์ƒ:

response = self.client.messages.create(
    model=self.model,
    max_tokens=self.max_tokens,
    temperature=0.1,  # ๋‚ฎ์€ ๊ฐ’ = ๋” ์ผ๊ด€์ 
    messages=[...]
)

2. ์—ฌ๋Ÿฌ ๋ฒˆ ํ‰๊ฐ€ํ•˜๊ณ  ํ‰๊ท  ์‚ฌ์šฉ:

def stable_evaluate(self, prompt, num_runs=3):
    """์—ฌ๋Ÿฌ ๋ฒˆ ํ‰๊ฐ€ํ•˜๊ณ  ํ‰๊ท  ์ ์ˆ˜ ๋ฐ˜ํ™˜"""
    scores = []
    
    for i in range(num_runs):
        result = self.evaluate(prompt)
        if result['success']:
            scores.append(result['result']['total_score'])
    
    return {
        'average_score': sum(scores) / len(scores),
        'std_dev': statistics.stdev(scores) if len(scores) > 1 else 0,
        'all_scores': scores
    }

๋ฌธ์ œ 5: ์†๋„๊ฐ€ ๋„ˆ๋ฌด ๋А๋ฆผ

์ฆ์ƒ:
๋ฐฐ์น˜ ํ‰๊ฐ€ ์‹œ ์‹œ๊ฐ„์ด ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ฆผ

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:
1. ์บ์‹ฑ ํ™œ์šฉ (์œ„์—์„œ ๊ตฌํ˜„ํ•œ CachedEvaluator ์‚ฌ์šฉ)
2. ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ ์‚ฌ์šฉ
3. Quick mode ํ™œ์šฉ (๊ฐ„๋‹จํ•œ ์ ์ˆ˜๋งŒ ํ•„์š”ํ•œ ๊ฒฝ์šฐ)
4. API ํ˜ธ์ถœ ์ตœ์†Œํ™”:

# ์—ฌ๋Ÿฌ ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ•˜๋‚˜์˜ ์š”์ฒญ์œผ๋กœ ํ‰๊ฐ€
def batch_evaluate_single_call(self, prompts_list):
    """ํ•˜๋‚˜์˜ API ํ˜ธ์ถœ๋กœ ์—ฌ๋Ÿฌ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€"""
    combined_prompt = f"""
    ๋‹ค์Œ {len(prompts_list)}๊ฐœ์˜ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๊ฐ๊ฐ ํ‰๊ฐ€ํ•ด์ฃผ์„ธ์š”.
    ๊ฐ ํ”„๋กฌํ”„ํŠธ๋งˆ๋‹ค 0-10์  ์ ์ˆ˜๋ฅผ JSON ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•˜์„ธ์š”.
    
    """
    
    for i, prompt in enumerate(prompts_list, 1):
        combined_prompt += f"\nํ”„๋กฌํ”„ํŠธ {i}:\n{prompt}\n"
    
    combined_prompt += """
    ์ถœ๋ ฅ ํ˜•์‹:
    [
        {"id": 1, "score": X.X},
        {"id": 2, "score": X.X},
        ...
    ]
    """
    
    # ํ•˜๋‚˜์˜ API ํ˜ธ์ถœ๋กœ ์ฒ˜๋ฆฌ
    result = self.evaluate(combined_prompt)
    # ... ๊ฒฐ๊ณผ ํŒŒ์‹ฑ ...

๐Ÿš€ ํ”„๋กœ์ ํŠธ ํ™•์žฅ ์•„์ด๋””์–ด

๊ธฐ๋ณธ ๋„๊ตฌ๋Š” ์™„์„ฑํ–ˆ์–ด! ์ด์ œ ๋” ๋ฐœ์ „์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ์•„์ด๋””์–ด๋“ค์„ ์†Œ๊ฐœํ• ๊ฒŒ.

1. ๋‹ค๊ตญ์–ด ์ง€์›

์˜์–ด๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํ•œ๊ตญ์–ด, ์ผ๋ณธ์–ด ๋“ฑ ๋‹ค์–‘ํ•œ ์–ธ์–ด์˜ ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ‰๊ฐ€ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ™•์žฅํ•˜์ž.

EVALUATION_PROMPTS = {
    'ko': """๋‹น์‹ ์€ ํ•œ๊ตญ์–ด ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ์ „๋ฌธ๊ฐ€์ž…๋‹ˆ๋‹ค...""",
    'en': """You are an expert in evaluating English prompts...""",
    'ja': """ใ‚ใชใŸใฏๆ—ฅๆœฌ่ชžใƒ—ใƒญใƒณใƒ—ใƒˆ่ฉ•ไพกใฎๅฐ‚้–€ๅฎถใงใ™..."""
}

def evaluate(self, prompt_text, language='ko'):
    template = EVALUATION_PROMPTS.get(language, EVALUATION_PROMPTS['en'])
    # ...

2. ๋„๋ฉ”์ธ๋ณ„ ํŠนํ™” ํ‰๊ฐ€

์ฝ”๋”ฉ, ๊ธ€์“ฐ๊ธฐ, ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋“ฑ ๋„๋ฉ”์ธ๋ณ„๋กœ ๋‹ค๋ฅธ ํ‰๊ฐ€ ๊ธฐ์ค€์„ ์ ์šฉํ•˜์ž.

DOMAIN_CRITERIA = {
    'coding': {
        'clarity': 10,
        'specificity': 15,  # ์ฝ”๋”ฉ์€ ๊ตฌ์ฒด์„ฑ์ด ๋” ์ค‘์š”
        'context': 10,
        'structure': 10,
        'constraints': 15
    },
    'writing': {
        'clarity': 15,
        'specificity': 10,
        'context': 15,  # ๊ธ€์“ฐ๊ธฐ๋Š” ๋งฅ๋ฝ์ด ์ค‘์š”
        'structure': 10,
        'constraints': 10
    }
}

3. ํ”„๋กฌํ”„ํŠธ ๋ฒ„์ „ ๊ด€๋ฆฌ

Git์ฒ˜๋Ÿผ ํ”„๋กฌํ”„ํŠธ์˜ ๋ณ€๊ฒฝ ์ด๋ ฅ์„ ์ถ”์ ํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ์‹œ์Šคํ…œ์ด์•ผ.

class PromptVersionControl:
    """ํ”„๋กฌํ”„ํŠธ ๋ฒ„์ „ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ"""
    
    def __init__(self, repo_path='prompt_repo'):
        self.repo_path = Path(repo_path)
        self.repo_path.mkdir(exist_ok=True)
        self.history_file = self.repo_path / 'history.json'
        self.load_history()
    
    def commit(self, prompt_id, prompt_text, message, evaluation=None):
        """์ƒˆ ๋ฒ„์ „ ์ปค๋ฐ‹"""
        version = {
            'version': len(self.history.get(prompt_id, [])) + 1,
            'timestamp': datetime.now().isoformat(),
            'prompt': prompt_text,
            'message': message,
            'evaluation': evaluation
        }
        
        if prompt_id not in self.history:
            self.history[prompt_id] = []
        
        self.history[prompt_id].append(version)
        self.save_history()
    
    def diff(self, prompt_id, version1, version2):
        """๋‘ ๋ฒ„์ „ ๋น„๊ต"""
        # difflib ์‚ฌ์šฉํ•˜์—ฌ ์ฐจ์ด์  ํ‘œ์‹œ
        import difflib
        
        v1 = self.get_version(prompt_id, version1)
        v2 = self.get_version(prompt_id, version2)
        
        diff = difflib.unified_diff(
            v1['prompt'].splitlines(),
            v2['prompt'].splitlines(),
            lineterm=''
        )
        
        return '\n'.join(diff)

4. ํŒ€ ํ˜‘์—… ๊ธฐ๋Šฅ

์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ํ•จ๊ป˜ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๊ฐœ์„ ํ•˜๊ณ  ๋ฆฌ๋ทฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์ด์•ผ.

class PromptReviewSystem:
    """ํ”„๋กฌํ”„ํŠธ ๋ฆฌ๋ทฐ ์‹œ์Šคํ…œ"""
    
    def create_review_request(self, prompt_id, prompt_text, author):
        """๋ฆฌ๋ทฐ ์š”์ฒญ ์ƒ์„ฑ"""
        review_request = {
            'id': str(uuid.uuid4()),
            'prompt_id': prompt_id,
            'prompt': prompt_text,
            'author': author,
            'created_at': datetime.now().isoformat(),
            'status': 'pending',
            'reviews': []
        }
        # ์ €์žฅ ๋กœ์ง...
    
    def add_review(self, request_id, reviewer, score, comments):
        """๋ฆฌ๋ทฐ ์ถ”๊ฐ€"""
        review = {
            'reviewer': reviewer,
            'score': score,
            'comments': comments,
            'timestamp': datetime.now().isoformat()
        }
        # ์ €์žฅ ๋กœ์ง...
    
    def approve(self, request_id):
        """๋ฆฌ๋ทฐ ์Šน์ธ"""
        # ๋ชจ๋“  ๋ฆฌ๋ทฐ์–ด๊ฐ€ ์Šน์ธํ–ˆ๋Š”์ง€ ํ™•์ธ
        # ์Šน์ธ ์‹œ ๋ฉ”์ธ ๋ธŒ๋žœ์น˜์— ๋จธ์ง€

5. ํ”„๋กฌํ”„ํŠธ ๋งˆ์ผ“ํ”Œ๋ ˆ์ด์Šค

๊ฒ€์ฆ๋œ ๊ณ ํ’ˆ์งˆ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๊ณต์œ ํ•˜๊ณ  ๊ฑฐ๋ž˜ํ•˜๋Š” ํ”Œ๋žซํผ์ด์•ผ. ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ๊ณณ์—์„œ ์ด๋Ÿฐ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๋ฉด ์ •๋ง ์œ ์šฉํ•  ๊ฑฐ์•ผ! ๐Ÿ’ก

class PromptMarketplace:
    """ํ”„๋กฌํ”„ํŠธ ๋งˆ์ผ“ํ”Œ๋ ˆ์ด์Šค"""
    
    def publish_prompt(self, prompt_text, metadata):
        """ํ”„๋กฌํ”„ํŠธ ๊ฒŒ์‹œ"""
        # ํ’ˆ์งˆ ๊ฒ€์ฆ
        evaluation = self.evaluator.evaluate(prompt_text)
        
        if evaluation['result']['total_score'] < 8.0:
            return {
                'success': False,
                'message': 'ํ’ˆ์งˆ ๊ธฐ์ค€(8.0์ )์„ ์ถฉ์กฑํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค'
            }
        
        listing = {
            'id': str(uuid.uuid4()),
            'prompt': prompt_text,
            'category': metadata['category'],
            'tags': metadata['tags'],
            'price': metadata['price'],
            'quality_score': evaluation['result']['total_score'],
            'author': metadata['author'],
            'published_at': datetime.now().isoformat()
        }
        
        # ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ...
        return {'success': True, 'listing_id': listing['id']}
    
    def search(self, query, category=None, min_score=7.0):
        """ํ”„๋กฌํ”„ํŠธ ๊ฒ€์ƒ‰"""
        # ๊ฒ€์ƒ‰ ๋กœ์ง...
        pass

๐Ÿ“š ํ•™์Šต ๋ฆฌ์†Œ์Šค ๋ฐ ์ฐธ๊ณ  ์ž๋ฃŒ

๋” ๊นŠ์ด ๊ณต๋ถ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ด๋Ÿฐ ์ž๋ฃŒ๋“ค์„ ์ถ”์ฒœํ•ด!

๊ณต์‹ ๋ฌธ์„œ

โ€ข Anthropic Claude API ๋ฌธ์„œ: https://docs.anthropic.com/
โ€ข OpenAI Prompt Engineering Guide: ํ”„๋กฌํ”„ํŠธ ์ž‘์„ฑ ๊ธฐ๋ฒ•
โ€ข Python asyncio ๋ฌธ์„œ: ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ ์ตœ์ ํ™”

์ถ”์ฒœ ๋„์„œ

โ€ข "The Art of Prompt Engineering" - ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ๊ธฐ์ดˆ
โ€ข "Building LLM Applications" - LLM ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ
โ€ข "Clean Code" - ์ฝ”๋“œ ํ’ˆ์งˆ ๊ด€๋ฆฌ (ํ”„๋กฌํ”„ํŠธ์—๋„ ์ ์šฉ ๊ฐ€๋Šฅ!)

์˜จ๋ผ์ธ ์ปค๋ฎค๋‹ˆํ‹ฐ

โ€ข Reddit r/PromptEngineering - ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ์ปค๋ฎค๋‹ˆํ‹ฐ
โ€ข Discord: AI Developers - AI ๊ฐœ๋ฐœ์ž ๋ชจ์ž„
โ€ข GitHub: awesome-prompt-engineering - ํ๋ ˆ์ด์…˜๋œ ๋ฆฌ์†Œ์Šค ๋ชจ์Œ

์‹ค์Šต ํ”„๋กœ์ ํŠธ ์•„์ด๋””์–ด

1. ํ”„๋กฌํ”„ํŠธ ํ…œํ”Œ๋ฆฟ ์ƒ์„ฑ๊ธฐ - ๋„๋ฉ”์ธ๋ณ„ ์ตœ์ ํ™”๋œ ํ…œํ”Œ๋ฆฟ ์ž๋™ ์ƒ์„ฑ
2. ํ”„๋กฌํ”„ํŠธ A/B ํ…Œ์ŠคํŠธ ํ”Œ๋žซํผ - ์›น ๊ธฐ๋ฐ˜ ํ…Œ์ŠคํŠธ ๋„๊ตฌ
3. ํ”„๋กฌํ”„ํŠธ ํ’ˆ์งˆ ๋Œ€์‹œ๋ณด๋“œ - ์‹ค์‹œ๊ฐ„ ๋ชจ๋‹ˆํ„ฐ๋ง ์‹œ์Šคํ…œ
4. ํ”„๋กฌํ”„ํŠธ ์ตœ์ ํ™” ๋ด‡ - Slack/Discord ๋ด‡์œผ๋กœ ์ฆ‰์‹œ ํ‰๊ฐ€
5. ํ”„๋กฌํ”„ํŠธ ํ•™์Šต ํ”Œ๋žซํผ - ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ํŠœํ† ๋ฆฌ์–ผ

๐Ÿ’ก ํ•™์Šต ํŒ: โ€ข ๋งค์ผ ํ•˜๋‚˜์”ฉ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ํ‰๊ฐ€ํ•ด๋ณด์ž
โ€ข ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋ถ„์„ํ•˜๊ณ  ๊ฐœ์„ ์ ์„ ์ฐพ์•„๋ณด์ž
โ€ข ์ž์‹ ๋งŒ์˜ ํ”„๋กฌํ”„ํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ตฌ์ถ•ํ•˜์ž
โ€ข ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ๊ณ ๋ฐ›์ž
โ€ข ์‹ค์ œ ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ•˜๋ฉด์„œ ๋ฐฐ์šฐ์ž!

๐ŸŽฌ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ

์™€! ์—ฌ๊ธฐ๊นŒ์ง€ ์ •๋ง ๊ธด ์—ฌ์ •์ด์—ˆ์–ด. ์šฐ๋ฆฌ๋Š” Python๊ณผ Claude API๋ฅผ ํ™œ์šฉํ•ด์„œ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋„๊ตฌ๋ฅผ ์ฒ˜์Œ๋ถ€ํ„ฐ ๋๊นŒ์ง€ ๋งŒ๋“ค์–ด๋ดค์–ด. ๐ŸŽ‰

์šฐ๋ฆฌ๊ฐ€ ๋ฐฐ์šด ๊ฒƒ๋“ค

โœ… Claude API์˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•๊ณผ ์ธ์ฆ
โœ… ํ”„๋กฌํ”„ํŠธ ํ’ˆ์งˆ ํ‰๊ฐ€์˜ 5๊ฐ€์ง€ ํ•ต์‹ฌ ์ง€ํ‘œ
โœ… ํ‰๊ฐ€ ์—”์ง„์˜ ์„ค๊ณ„์™€ ๊ตฌํ˜„
โœ… ๊ฒฐ๊ณผ ์‹œ๊ฐํ™” ๋ฐ ๋ฆฌํฌํŠธ ์ƒ์„ฑ
โœ… ์„ฑ๋Šฅ ์ตœ์ ํ™”์™€ ๋น„์šฉ ๊ด€๋ฆฌ
โœ… ์‹ค์ „ ํ™œ์šฉ ์‹œ๋‚˜๋ฆฌ์˜ค์™€ ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…
โœ… ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค

๋‹ค์Œ ๋‹จ๊ณ„

์ด์ œ ์ด ๋„๊ตฌ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž์‹ ๋งŒ์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž!

๐Ÿš€ ์‹ค์ „ ์ ์šฉ ์•„์ด๋””์–ด: 1. ๊ฐœ์ธ ํ”„๋กœ์ ํŠธ
โ€ข ์ž์‹ ์˜ ํ”„๋กฌํ”„ํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ตฌ์ถ• ๋ฐ ๊ด€๋ฆฌ
โ€ข ์ผ์ผ ํ”„๋กฌํ”„ํŠธ ํ’ˆ์งˆ ์ฒดํฌ ๋ฃจํ‹ด ๋งŒ๋“ค๊ธฐ

2. ํŒ€ ํ”„๋กœ์ ํŠธ
โ€ข CI/CD ํŒŒ์ดํ”„๋ผ์ธ์— ํ’ˆ์งˆ ๊ฒ€์‚ฌ ํ†ตํ•ฉ
โ€ข ํŒ€ ํ”„๋กฌํ”„ํŠธ ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ ์ž๋™ ๊ฒ€์ฆ

3. ๋น„์ฆˆ๋‹ˆ์Šค
โ€ข ํ”„๋กฌํ”„ํŠธ ์ปจ์„คํŒ… ์„œ๋น„์Šค ์ œ๊ณต
โ€ข ํ”„๋กฌํ”„ํŠธ ํ’ˆ์งˆ ์ธ์ฆ ์„œ๋น„์Šค
โ€ข ํ”„๋กฌํ”„ํŠธ ๋งˆ์ผ“ํ”Œ๋ ˆ์ด์Šค ์šด์˜

๋งˆ์ง€๋ง‰ ์กฐ์–ธ

ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง์€ ๊ณ„์† ๋ฐœ์ „ํ•˜๋Š” ๋ถ„์•ผ์•ผ. ์˜ค๋Š˜ ๋ฐฐ์šด ๋‚ด์šฉ์ด ๋‚ด์ผ์€ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์–ด. ํ•˜์ง€๋งŒ ํ•ต์‹ฌ ์›์น™์€ ๋ณ€ํ•˜์ง€ ์•Š์•„:

๋ช…ํ™•ํ•˜๊ฒŒ, ๊ตฌ์ฒด์ ์œผ๋กœ, ๋งฅ๋ฝ๊ณผ ํ•จ๊ป˜, ๊ตฌ์กฐํ™”ํ•ด์„œ, ์ œ์•ฝ์กฐ๊ฑด์„ ๋ช…์‹œํ•˜๋ผ!

์ด ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค๋ฉด์„œ ๋ฐฐ์šด ๊ฒƒ๋“ค์„ ์‹ค์ œ ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ•ด๋ณด๊ณ , ๊ณ„์† ๊ฐœ์„ ํ•ด๋‚˜๊ฐ€์ž. ๊ทธ๋ฆฌ๊ณ  ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ์ž์‹ ์˜ ์ „๋ฌธ์„ฑ์„ ๊ณต์œ ํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ด์•ผ! ๐Ÿ’ช

๐ŸŽ“ ์ตœ์ข… ์ฒดํฌ๋ฆฌ์ŠคํŠธ: โ˜‘๏ธ ์ฝ”๋“œ๋ฅผ GitHub์— ์˜ฌ๋ฆฌ๊ณ  ๋ฌธ์„œํ™”ํ–ˆ๋Š”๊ฐ€?
โ˜‘๏ธ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ–ˆ๋Š”๊ฐ€?
โ˜‘๏ธ ์—๋Ÿฌ ํ•ธ๋“ค๋ง์ด ์ถฉ๋ถ„ํ•œ๊ฐ€?
โ˜‘๏ธ ๋ณด์•ˆ ์„ค์ •(API ํ‚ค ๊ด€๋ฆฌ)์ด ์˜ฌ๋ฐ”๋ฅธ๊ฐ€?
โ˜‘๏ธ ์„ฑ๋Šฅ ์ตœ์ ํ™”๋ฅผ ๊ณ ๋ คํ–ˆ๋Š”๊ฐ€?
โ˜‘๏ธ ์‚ฌ์šฉ์ž ๋ฌธ์„œ๋ฅผ ์ž‘์„ฑํ–ˆ๋Š”๊ฐ€?
โ˜‘๏ธ ์‹ค์ œ ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ•ด๋ดค๋Š”๊ฐ€?
์ž, ์ด์ œ ๋‹น์‹  ์ฐจ๋ก€์•ผ! ์ด ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ๋ฉ‹์ง„ ํ”„๋กฌํ”„ํŠธ ํ‰๊ฐ€ ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž. ์งˆ๋ฌธ์ด๋‚˜ ํ”ผ๋“œ๋ฐฑ์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“  ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ๊ณต์œ ํ•˜์ž! ๐Ÿš€

Happy Coding! ์ฆ๊ฑฐ์šด ํ”„๋กฌํ”„ํŠธ ์—”์ง€๋‹ˆ์–ด๋ง ๋˜๊ธธ! ๐Ÿ˜Š
Happy Prompt Engineering! ํ”„๋กฌํ”„ํŠธ์˜ ํ’ˆ์งˆ์ด AI์˜ ๋ฏธ๋ž˜๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค ๐Ÿš€ ๐Ÿ’ก โœจ
๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.