0Pricing
AI Prompt Engineering · บทเรียน

การควบคุมเวอร์ชันสำหรับพรอมต์

การจัดการเวอร์ชันรูปแบบ Git การจัดการเวอร์ชันเชิงความหมาย และบันทึกการเปลี่ยนแปลงสำหรับพรอมต์

การควบคุมเวอร์ชันสำหรับพรอมต์ เป็นบทเรียน AI Prompt Engineering ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Prompt Engineering และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน

เหตุใดจึงต้องควบคุมเวอร์ชันพรอมต์

พรอมต์มีการพัฒนาอย่างต่อเนื่อง — การเปลี่ยนถ้อยคำเพียงเล็กน้อยอาจเปลี่ยนพฤติกรรมของโมเดลได้อย่างมาก หากไม่มีการควบคุมเวอร์ชัน ทีมจะติดตามไม่ได้ว่าเปลี่ยนอะไร เมื่อใด และเพราะเหตุใด การจัดการพรอมต์เช่นเดียวกับโค้ดช่วยให้มี ประวัติ การย้อนกลับ การทำงานร่วมกัน และการระบุผู้แก้ไข

การกำหนดเวอร์ชันพรอมต์ด้วยระบบควบคุมเวอร์ชัน

การจัดเก็บไฟล์พรอมต์ในระบบควบคุมเวอร์ชันเป็นกลยุทธ์การกำหนดเวอร์ชันที่เรียบง่ายที่สุด พรอมต์แต่ละรายการเป็นไฟล์ข้อความล้วน และการบันทึกการเปลี่ยนแปลงจะเก็บทุกการแก้ไข สาขาใช้แทนการทดลอง ส่วนแท็กใช้ระบุรุ่นที่เผยแพร่สู่ระบบจริง

# Initialize a prompt repo
git init prompt-library
cd prompt-library
mkdir -p prompts/summarize-article

# First version
cat > prompts/summarize-article/prompt.txt << 'PROMPT'
Summarize the article in {num_sentences} sentences.

Article:
{article_text}
PROMPT

git add prompts/summarize-article/prompt.txt
git commit -m 'feat(summarize-article): initial prompt v1.0.0'
git tag v1.0.0

# Experiment on a branch
git checkout -b experiment/add-focus-area
# ... edit prompt ...
git commit -m 'feat(summarize-article): add focus_area variable'
git tag v1.1.0-rc1

การกำหนดเวอร์ชันเชิงความหมายสำหรับพรอมต์

ใช้การกำหนดเวอร์ชันเชิงความหมาย (MAJOR.MINOR.PATCH) ที่ปรับให้เหมาะกับความหมายของพรอมต์:

  • PATCH (1.0.0 → 1.0.1): แก้คำผิด เปลี่ยนช่องว่าง — ผลลัพธ์ไม่เปลี่ยนแปลง
  • MINOR (1.0.0 → 1.1.0): เพิ่มตัวแปรที่ไม่จำเป็น ปรับปรุงการใช้ถ้อยคำ — ใช้ร่วมกับเวอร์ชันเดิมได้
  • MAJOR (1.0.0 → 2.0.0): เพิ่มตัวแปรที่จำเป็น เปลี่ยนรูปแบบผลลัพธ์ เปลี่ยนพฤติกรรมจนไม่เข้ากันได้
# semver.py — helper to validate version bumps
import re

def parse_semver(v):
    m = re.match(r'^(\d+)\.(\d+)\.(\d+)$', v)
    if not m:
        raise ValueError(f'Invalid semver: {v}')
    return tuple(int(x) for x in m.groups())

def classify_bump(old, new):
    o = parse_semver(old)
    n = parse_semver(new)
    if n[0] > o[0]:
        return 'MAJOR'
    elif n[1] > o[1]:
        return 'MINOR'
    elif n[2] > o[2]:
        return 'PATCH'
    else:
        raise ValueError('New version must be greater than old')

print(classify_bump('1.0.0', '1.1.0'))  # MINOR
print(classify_bump('1.1.0', '2.0.0'))  # MAJOR
print(classify_bump('2.0.0', '2.0.1'))  # PATCH

รูปแบบบันทึกการเปลี่ยนแปลง

เวอร์ชันพรอมต์ทุกเวอร์ชันควรมีบันทึกการเปลี่ยนแปลงที่เป็นระบบ เพื่อให้ทีมเข้าใจว่ามีการเปลี่ยนแปลงอะไรและเพราะเหตุใด ให้ใช้รูปแบบบันทึกการเปลี่ยนแปลงมาตรฐานที่ปรับให้เหมาะกับพรอมต์

# CHANGELOG.md for prompts/summarize-article/

## [2.0.0] - 2024-08-10
### Breaking Changes
- Renamed variable 'text' to 'article_text' (update all call sites)
- Output now always includes a headline sentence before the summary

### Changed
- Improved instruction specificity to reduce hallucination rate by ~12%

## [1.1.0] - 2024-07-01
### Added
- New optional variable 'focus_area' to direct summary emphasis
- Fallback instruction when 'focus_area' is not provided

### Changed
- Reworded opening instruction for clarity

## [1.0.0] - 2024-06-01
### Added
- Initial prompt: basic summarization with 'num_sentences' control

การติดแท็กรุ่นที่เผยแพร่สู่ระบบจริง

แท็กของระบบควบคุมเวอร์ชันระบุ commit ที่นำไปใช้งานในระบบจริงอย่างแน่นอน ใช้แท็กพร้อมคำอธิบายเพื่อจัดเก็บบันทึกประจำรุ่นไว้พร้อมกับแท็ก วิธีนี้ทำให้สร้างขึ้นใหม่ได้อย่างง่ายดายว่าพรอมต์ใดกำลังใช้งานอยู่ ณ เวลาใดเวลาหนึ่ง

# Annotated git tag with release notes
git tag -a v2.0.0 -m 'Release 2.0.0

Breaking: renamed variable text -> article_text
Improved: reduced hallucination rate by 12%
Author: alice@company.com
Reviewed-by: bob@company.com'

# Push tags to remote
git push origin --tags

# List all tags with dates
git tag -l --sort=version:refname -n9
# v1.0.0  Initial prompt
# v1.1.0  Add focus_area variable
# v2.0.0  Release 2.0.0 — Breaking: renamed variable ...

# View exact prompt at a tag
git show v1.1.0:prompts/summarize-article/prompt.txt

ขั้นตอนการย้อนกลับ

เมื่อพรอมต์เวอร์ชันใหม่ทำให้คุณภาพถดถอย การย้อนกลับต้องทำได้อย่างรวดเร็ว มีกลยุทธ์ 2 แบบ ได้แก่ การย้อนกลับด้วยโค้ด (ติดตั้งสิ่งประดิษฐ์เดิมอีกครั้ง) และ การย้อนกลับของคลัง (สลับแฟล็ก is_active โดยไม่ต้องติดตั้งใหม่)

# Strategy 1: Registry rollback (fastest — no redeploy needed)
def rollback_prompt(registry, prompt_id, target_version):
    print(f'Rolling back {prompt_id} to {target_version}...')
    registry.activate_version(prompt_id, target_version)
    print(f'Rollback complete. {prompt_id} now serving {target_version}')

# Strategy 2: Git-based rollback with audit trail
# Create a revert commit (do NOT force-push, keep history clean)
git revert HEAD --no-commit   # stage the revert
git commit -m 'revert(summarize-article): roll back to v1.1.0 due to quality regression'
git tag v2.0.1-hotfix

# Then trigger re-deployment of the reverted artifact
# This preserves full history — nobody loses track of what happened

เครื่องมือเปรียบเทียบความแตกต่างของพรอมต์

การตรวจสอบการเปลี่ยนแปลงของพรอมต์จำเป็นต้องใช้เครื่องมือเปรียบเทียบความแตกต่างเฉพาะทาง git diff แบบธรรมดาใช้ได้กับข้อความ แต่เครื่องมือเปรียบเทียบเชิงความหมายจะแสดงการเปลี่ยนแปลงโครงสร้างของตัวแปรและคำสั่งได้อย่างชัดเจน

# prompt_diff.py — highlight variable changes between versions
import re

def extract_variables(template):
    return set(re.findall(r'\{(\w+)\}', template))

def diff_prompts(old_template, new_template):
    old_vars = extract_variables(old_template)
    new_vars = extract_variables(new_template)
    added = new_vars - old_vars
    removed = old_vars - new_vars
    kept = old_vars & new_vars

    print('Variables added:', added or 'none')
    print('Variables removed:', removed or 'none')
    print('Variables kept:', kept)

    old_lines = set(old_template.splitlines())
    new_lines = set(new_template.splitlines())
    print('New lines:', new_lines - old_lines)
    print('Removed lines:', old_lines - new_lines)

old = 'Summarize in {num_sentences} sentences.\n\n{text}'
new = 'Summarize in {num_sentences} sentences focused on {focus_area}.\n\n{article_text}'
diff_prompts(old, new)

กลยุทธ์การแตกสาขาสำหรับการทดลองพรอมต์

ใช้แนวทางการแตกสาขาแบบเดียวกับการพัฒนาซอฟต์แวร์สำหรับการพัฒนาพรอมต์:

  • main — มีเฉพาะพรอมต์ที่พร้อมใช้งานจริง
  • experiment/<name> — รูปแบบสำหรับการทดสอบ A/B ที่อยู่ระหว่างการพัฒนา
  • hotfix/<issue> — การแก้ไขฉุกเฉินสำหรับระบบจริง
  • release/<version> — การจัดเตรียมรุ่น候เลือกก่อนเผยแพร่

กำหนดให้มีการตรวจสอบโค้ด (คำขอรวมการเปลี่ยนแปลง) ก่อนรวมการเปลี่ยนแปลงพรอมต์เข้ากับ main — เช่นเดียวกับโค้ดของแอปพลิเคชัน

# Typical prompt development workflow

# 1. Create experiment branch
git checkout -b experiment/tone-formal

# 2. Edit and test prompt locally
python test_prompt.py --prompt prompts/summarize-article/prompt.txt \
                      --eval-set evals/summarize-100.jsonl

# 3. Open PR with eval results in description
gh pr create --title 'experiment: formal tone improves ROUGE by 8%' \
             --body 'Eval results attached. ROUGE-L: 0.61 -> 0.66'

# 4. After approval, merge and tag
git checkout main && git merge experiment/tone-formal
git tag v1.2.0 && git push origin main --tags

การตรวจสอบเวอร์ชันอัตโนมัติในการผสานรวมอย่างต่อเนื่อง

กระบวนการผสานรวมอย่างต่อเนื่องสำหรับการเปลี่ยนแปลงพรอมต์ควรตรวจสอบโดยอัตโนมัติว่า การเพิ่มเวอร์ชันเชิงความหมายถูกต้อง บันทึกการเปลี่ยนแปลงได้รับการปรับปรุง ตัวแปรทั้งหมดในแม่แบบมีเอกสารอธิบาย และคะแนน eval ไม่ถดถอย

# .github/workflows/prompt-ci.yml
# name: Prompt Validation
# on: [pull_request]
# jobs:
#   validate:
#     runs-on: ubuntu-latest
#     steps:
#       - uses: actions/checkout@v4
#       - name: Check semver bump
#         run: python scripts/check_semver.py
#       - name: Validate template syntax
#         run: python scripts/validate_templates.py
#       - name: Run eval suite
#         run: python scripts/run_evals.py --threshold 0.95

# scripts/validate_templates.py
import glob, json, sys

errors = []
for f in glob.glob('prompts/**/*.yaml', recursive=True):
    with open(f) as fh:
        data = fh.read()
    if '{' not in data:
        errors.append(f'{f}: no variables found (may be intentional — double check)')

if errors:
    print('Warnings:', errors)
print('Template validation complete')

ความไม่เปลี่ยนแปลงของเวอร์ชันที่ติดแท็ก

หลักการสำคัญคือ เวอร์ชันที่ติดแท็กต้องไม่เปลี่ยนแปลง เมื่อแท็ก v2.0.0 แล้ว แม่แบบของเวอร์ชันนั้นต้องไม่เปลี่ยนแปลงอีก การแก้ไขต้องอยู่ในเวอร์ชันใหม่ (v2.0.1) วิธีนี้รับประกันการสร้างผลลัพธ์ซ้ำได้ — คุณสามารถสร้างสถานะของระบบจริงที่แน่นอนขึ้นใหม่จากแท็กได้เสมอ

# Enforce immutability in the registry
def register(self, prompt_id, version, template, ...):
    with self.conn.cursor() as cur:
        # Check if version already exists
        cur.execute(
            'SELECT id FROM prompt_versions '
            'WHERE prompt_id=%s AND version=%s',
            (prompt_id, version)
        )
        if cur.fetchone():
            raise ValueError(
                f'Version {version} of {prompt_id} already exists. '
                'Versions are immutable. Create a new version instead.'
            )
        # Proceed with insertion
        cur.execute(
            'INSERT INTO prompt_versions '
            '(prompt_id, version, template, author, tags, model) '
            'VALUES (%s, %s, %s, %s, %s, %s)',
            (prompt_id, version, template, author, tags, model)
        )
    self.conn.commit()

การเชื่อมโยงพรอมต์กับผลลัพธ์ eval

เวอร์ชันพรอมต์แต่ละเวอร์ชันควรเชื่อมโยงกับผลลัพธ์ eval เพื่อให้ทีมเปรียบเทียบคุณภาพระหว่างเวอร์ชันได้ จัดเก็บเมทาดาทาของ eval ไว้พร้อมกับสิ่งประดิษฐ์พรอมต์

# Attach eval results to a prompt version
ALTER TABLE prompt_versions ADD COLUMN eval_results JSONB;

# Python: record eval scores
def attach_eval_results(self, prompt_id, version, results):
    with self.conn.cursor() as cur:
        cur.execute(
            'UPDATE prompt_versions SET eval_results=%s '
            'WHERE prompt_id=%s AND version=%s',
            (json.dumps(results), prompt_id, version)
        )
    self.conn.commit()

# Example eval results structure
eval_results = {
    'dataset': 'cnn-dailymail-100',
    'date_run': '2024-08-10',
    'metrics': {
        'rouge_l': 0.66,
        'bertscore_f1': 0.89,
        'human_quality_avg': 4.2
    },
    'sample_size': 100,
    'runner': 'alice@company.com'
}
registry.attach_eval_results('summarize-article', '1.2.0', eval_results)

ตรวจสอบอย่างรวดเร็ว

ควรเพิ่มเวอร์ชัน MAJOR ของพรอมต์เมื่อใด

สรุปการควบคุมเวอร์ชัน

การควบคุมเวอร์ชันพรอมต์ใช้แนวทางเดียวกับการควบคุมเวอร์ชันซอฟต์แวร์ โดยปรับให้เหมาะกับพรอมต์ดังนี้:

  • การกำหนดเวอร์ชันเชิงความหมาย: PATCH/MINOR/MAJOR แสดงผลกระทบของการเปลี่ยนแปลง
  • การติดแท็ก: แท็กที่ไม่เปลี่ยนแปลงและมีคำอธิบายสำหรับรุ่นที่เผยแพร่สู่ระบบจริง
  • บันทึกการเปลี่ยนแปลง: ประวัติของแต่ละเวอร์ชันที่เป็นระบบเพื่อการตรวจสอบย้อนหลัง
  • การย้อนกลับ: สลับแฟล็กของคลัง (รวดเร็ว) หรือย้อนการเปลี่ยนแปลงด้วยระบบควบคุมเวอร์ชัน (ตรวจสอบย้อนหลังได้)
  • การตรวจสอบโดยอัตโนมัติ: ตรวจสอบเวอร์ชันเชิงความหมาย ตรวจสอบแม่แบบ และป้องกันการถดถอยของ eval โดยอัตโนมัติ
  • ความไม่เปลี่ยนแปลง: เวอร์ชันที่ติดแท็กจะไม่เปลี่ยนแปลง — การแก้ไขจะสร้างเวอร์ชันใหม่เสมอ

คำถามที่พบบ่อย

บทเรียน “การควบคุมเวอร์ชันสำหรับพรอมต์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การควบคุมเวอร์ชันสำหรับพรอมต์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Prompt Engineering ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การควบคุมเวอร์ชันสำหรับพรอมต์”

การจัดการเวอร์ชันรูปแบบ Git การจัดการเวอร์ชันเชิงความหมาย และบันทึกการเปลี่ยนแปลงสำหรับพรอมต์ คุณปฏิบัติ AI Prompt Engineering ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Prompt Engineering หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Prompt Engineering บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การควบคุมเวอร์ชันสำหรับพรอมต์” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AI Prompt Engineering นี้ได้ไหม

ได้ บทเรียน AI Prompt Engineering ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. สถาปัตยกรรมทะเบียนพรอมต์
  2. การควบคุมเวอร์ชันสำหรับพรอมต์
  3. กลยุทธ์การนำไปใช้งานและย้อนกลับ
  4. การตรวจติดตามประสิทธิภาพพรอมต์ในระบบจริง
← กลับไปที่ AI Prompt Engineering