อัปเดตล่าสุด 2026: เทคนิคใหม่ล่าสุด

Prompt Engineering

โปรแกรมเมอร์, DevOps & System Admin

เทคนิคเขียน Prompt ให้ AI ช่วยงานเขียนโค้ด ตรวจจุดบกพร่อง และทำงานอัตโนมัติ
พร้อมตัวอย่างจริงและเทมเพลตพร้อมใช้

AI Assistant
Python
JavaScript

Prompt Engineering คืออะไร?

Prompt Engineering คือศาสตร์และศิลป์ของการออกแบบคำสั่ง (prompts) ให้ AI ให้ผลลัพธ์ที่ตรงตามที่ต้องการ สำหรับนักพัฒนาและ DevOps การเขียน prompt ที่ดีสามารถช่วย:

  • ลดเวลาเขียนโค้ดได้ถึง 70%
  • เพิ่มความแม่นยำของโค้ดได้ 35%
  • ช่วยเขียน Terraform, Ansible, Kubernetes manifests ได้รวดเร็ว
  • ตรวจจุดบกพร่องด้วย AI ได้แม่นยำขึ้น

แหล่งอ้างอิง: ข้อมูลนี้รวบรวมจาก Addy Osmani's Prompt Engineering Playbook (2025), DigitalOcean, Strapi และ research papers ปี 2024-2025

Framework สำหรับการเขียน Prompt

1. CO-STAR Framework (ภาษาไทย)

Framework นี้แบ่ง prompt เป็น 6 ส่วน ช่วยให้คุณเขียน prompt ที่ครบถ้วนและมีประสิทธิภาพ

C - Context (บริบท)

ข้อมูลเบื้องต้นเกี่ยวกับสถานการณ์ สภาพแวดล้อม หรือปัญหา

O - Objective (วัตถุประสงค์)

สิ่งที่ต้องการให้ AI ทำ ผลลัพธ์ที่คาดหวัง

S - Style (รูปแบบ)

รูปแบบ/สไตล์ของ output (formal, casual, technical)

T - Tone (โทน)

โทนการเขียน (มืออาชีพ, เป็นกันเอง, สอนสั่ง)

A - Audience (ผู้รับ)

ใครคือผู้รับข้อมูล (developer, client, management)

R - Response (รูปแบบตอบ)

รูปแบบของคำตอบที่ต้องการ (code, markdown, bullet points)

CO-STAR Template (ภาษาไทย)
บริบท (Context): ผมกำลังสร้าง REST API สำหรับ E-commerce โดยใช้ Laravel 10 มีปัญหาที่ product listing โหลดช้าเมื่อข้อมูลเยอะ วัตถุประสงค์ (Objective): 1. ออกแบบการ optimize database queries 2. สร้าง caching strategy 3. ใช้ Laravel Scout สำหรับ full-text search รูปแบบ (Style): - Production-ready code - มี type hints - มี error handling ครบถ้วน - ใช้ Laravel best practices โทน (Tone): - เป็นมืออาชีพ - อธิบายเข้าใจง่าย - ให้เหตุผลประกอบ ผู้รับ (Audience): Developer คนอื่นที่จะดูแล codebase นี้ต่อ รูปแบบตอบ (Response): - Code snippets พร้อมคำอธิบาย - ก่อน/หลัง เปรียบเทียบ performance - Migration scripts ถ้าต้องแก้ database

1. CO-STAR Framework (English)

This framework divides prompts into 6 parts, helping you write comprehensive and effective prompts

C - Context

Background information about the situation, environment, or problem

O - Objective

What you want AI to do, the expected outcome

S - Style

Format/style of output (formal, casual, technical)

T - Tone

Writing tone (professional, casual, instructional)

A - Audience

Who will receive the information (developer, client, management)

R - Response

Format of the response (code, markdown, bullet points)

CO-STAR Template (English)
CONTEXT: I'm building a REST API for an e-commerce platform using Laravel 10 There's a problem with product listing being slow when there's a lot of data OBJECTIVE: 1. Design database query optimization 2. Create caching strategy 3. Use Laravel Scout for full-text search STYLE: - Production-ready code - With type hints - Complete error handling - Following Laravel best practices TONE: - Professional - Easy to understand explanations - Provide reasoning AUDIENCE: Other developers who will maintain this codebase RESPONSE FORMAT: - Code snippets with explanations - Before/after performance comparison - Migration scripts if database changes are needed

2. RISE Framework (ภาษาไทย)

Framework ที่เน้นความง่ายและชัดเจน เหมาะสำหรับงานที่ต้องการผลลัพธ์เฉพาะ

R - Role (บทบาท)

ให้ AI แสดงบทบาทที่เฉพาะเจาะจง

I - Input (ข้อมูล)

ข้อมูล คำสั่ง หรือปัญหาที่ให้ AI

S - Specifics (รายละเอียด)

ความต้องการ ข้อกำหนด และเงื่อนไขที่ชัดเจน

RISE Template (ภาษาไทย)
บทบาท (Role): จงแสดงบทบาทเป็น System Admin ผู้เชี่ยวชาญด้าน Linux Security ประสบการณ์ 10+ ปี ข้อมูล (Input): ต้องการ audit Ubuntu 22.04 server เพื่อตรวจสอบความปลอดภัย มี user ทั้งหมด 20 คน มี services: Nginx, MySQL, PHP-FPM, Redis ใช้ AWS EC2 t3.medium รายละเอียด (Specifics): 1. ตรวจสอบสิทธิ์ของ user แต่ละคน 2. ตรวจสอบ services ที่เปิด port อะไรบ้าง 3. ตรวจสอบ firewall rules ปัจจุบัน 4. ตรวจสอบ SSH configuration 5. ตรวจสอบ logs ที่น่าสงสัย 6. ให้คำแนะนำที่ต้องปรับปรุง พร้อม priority (High/Medium/Low) 7. ให้ command ที่ใช้ตรวจสอบและ command ที่ใช้แก้ไข Output: - สรุป findings เป็น bullet points - Command พร้อมคำอธิบาย - Risk assessment

2. RISE Framework (English)

A framework focusing on simplicity and clarity, perfect for tasks requiring specific outputs

R - Role

Have AI assume a specific persona

I - Input

Information, command, or problem given to AI

S - Specifics

Clear requirements, constraints, and conditions

RISE Template (English)
ROLE: Act as a System Admin expert in Linux Security with 10+ years experience INPUT: Need to audit an Ubuntu 22.04 server for security Have 20 users total Services running: Nginx, MySQL, PHP-FPM, Redis Running on AWS EC2 t3.medium SPECIFICS: 1. Check permissions for each user 2. Check what ports are opened by services 3. Check current firewall rules 4. Check SSH configuration 5. Check suspicious logs 6. Provide recommendations with priority (High/Medium/Low) 7. Provide commands for checking and fixing OUTPUT: - Summary of findings in bullet points - Commands with explanations - Risk assessment

3. Chain-of-Thought (COT) Prompting

ให้ AI คิดเป็นขั้นตอนก่อนตอบ เหมาะสำหรับปัญหาที่ซับซ้อน

Chain-of-Thought Template
You are helping me design a Kubernetes deployment strategy. Please think through this step-by-step: 1. First, explain deployment options available (Rolling, Blue-Green, Canary) 2. For each option, analyze: - How it works technically - When it's most appropriate - Pros and cons - Resource requirements 3. Based on this analysis, recommend the best strategy for my scenario: - Application: Microservice API - Traffic: ~10,000 RPS with 20% variance - Update frequency: Daily deployments - Risk tolerance: Medium 4. Explain your recommendation with justification 5. Provide example manifests for the recommended strategy Walk me through your entire thought process before giving the final recommendation.

3. Chain-of-Thought (COT) Prompting (English)

Ask AI to think step-by-step before responding, suitable for complex problems

Chain-of-Thought Template (English)
You are helping me design a Kubernetes deployment strategy. Please think through this step-by-step: 1. First, explain deployment options available (Rolling, Blue-Green, Canary) 2. For each option, analyze: - How it works technically - When it's most appropriate - Pros and cons - Resource requirements 3. Based on this analysis, recommend the best strategy for my scenario: - Application: Microservice API - Traffic: ~10,000 RPS with 20% variance - Update frequency: Daily deployments - Risk tolerance: Medium 4. Explain your recommendation with justification 5. Provide example manifests for the recommended strategy Walk me through your entire thought process before giving the final recommendation.

ตัวอย่าง Prompt สำหรับการเขียนโปรแกรม

Prompt สำหรับสร้างโค้ดใหม่

คีย์ที่สำคัญคือการให้ context และระบุข้อกำหนดชัดเจน

ภาษาไทย (Thai)

Code Generation Template (ภาษาไทย)
จงแสดงบทบาทเป็นนักพัฒนาภาษา [ภาษา] ระดับอาวุโส ข้อกำหนด: - ภาษา: [ระบุเวอร์ชัน เช่น Python 3.11, Node.js 20] - ฟังก์ชันที่ต้องการ: [อธิบาย] - รองรับ edge cases: [ระบุ] - Return type: [ระบุ type] - มี docstring พร้อมตัวอย่างการใช้งาน ตัวอย่าง input: [ใส่ตัวอย่าง] ตัวอย่าง output: [ใส่ผลลัพธ์ที่คาดหวัง] เพิ่มเติม: - มี error handling ครบถ้วน - ใช้ best practices ของภาษานั้นๆ - มี type hints ถ้าเป็นภาษาที่รองรับ - มี unit tests พร้อม

English

Code Generation Template (English)
Act as a senior [language] developer. Requirements: - Language: [specify version, e.g., Python 3.11, Node.js 20] - Function needed: [describe] - Handle edge cases: [specify] - Return type: [specify type] - Include docstring with example usage Example input: [provide example] Example output: [expected output] Additional: - Complete error handling - Follow best practices for that language - Include type hints if applicable - Include unit tests
Prompt ที่ไม่ดี
"Write a function to sort an array"
Prompt ที่ดี
จงแสดงบทบาทเป็นนักพัฒนา Python ระดับอาวุโส เขียนฟังก์ชันเรียงลำดับอาร์เรย์จำนวนเต็มจากน้อยไปมาก ข้อกำหนด: - ภาษา: Python 3.11 - ใช้เมธอด sort() ที่มีอยู่แล้ว - รองรับ edge cases: อาร์เรย์ว่าง, อาร์เรย์เดียว, input เป็น None - Return type: List[int] - มี docstring พร้อมตัวอย่างการใช้งาน ตัวอย่าง input: [4, 2, 7, 1, 3] ตัวอย่าง output: [1, 2, 3, 4, 7]

เคล็ดลับ: ใส่เวอร์ชันของภาษา (เช่น Python 3.11, Node.js 20), ระบุ error handling, และขอ unit tests ไปด้วย

Prompt สำหรับ Debugging

สูตรการ debug: ให้ AI ช่วยหาสาเหตุของปัญหา

Debugging Template
I'm debugging a [language] [feature/function] that's [symptom]. Code: [paste your code here] Error: [paste error message] Expected behavior: [describe what should happen] What I've tried: [list troubleshooting steps taken] Please provide: 1. Diagnostic analysis of the problem 2. The root cause with explanation 3. Fixed code with comments 4. How to prevent similar issues

ตัวอย่างจริง: React Infinite Loop

React Component Debug
I have a React 18 functional component that's causing infinite re-renders. Code: ```jsx const UserProfile = ({ userId }) => { const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetchUser(userId).then(setUser).finally(() => setLoading(false)); }, [userId, setUser, setLoading]); // Problem is here return loading ?
Loading...
:
{user?.name}
; }; ``` Expected behavior: Should fetch user data once when userId changes Actual behavior: Component re-renders infinitely Error in console: "Warning: Maximum update depth exceeded" What's causing this infinite loop and how do I fix the dependency array? Act as a senior React developer and walk through this step-by-step.

Prompt สำหรับ Refactoring

ให้ AI ปรับปรุงโค้ดให้ดีขึ้น ต้องระบุเป้าหมายชัดเจน

ภาษาไทย (Thai)

Refactoring Template (ภาษาไทย)
ฉันมีฟังก์ชันภาษา [ภาษา] ในโปรเจค [framework] ที่ต้องการ refactoring โค้ดปัจจุบัน: [วางโค้ด] ปัญหาที่ต้องการแก้ไข: 1. [ปัญหาด้าน performance] 2. [โค้ดซ้ำ] 3. [การใช้ API ที่ล้าสมัย] สิ่งที่คิดไว้: [แนวทางที่คิดไว้] เป้าหมายการปรับปรุง: - แก้ปัญหา N+1 query - เพิ่มคำแนะนำเรื่อง indexing - รักษาความปลอดภัยของ TypeScript types - อธิบายแต่ละการปรับปรุงพร้อมระยะเวลาโดยประมาณ ภาษา: Node.js 20+ กับ Sequelize 6.35 และ TypeScript 5.3 โปรดแนะนำ: 1. โค้ดที่ปรับปรุงแล้วพร้อมคำอธิบาย 2. การเปรียบเทียบก่อน/หลัง 3. การปรับปรุง performance ที่คาดหวัง

English

Refactoring Template (English)
I have a [language] function in a [framework] project that needs refactoring. Current code: [paste code] Issues I'd like to address: 1. [performance issue] 2. [code duplication] 3. [outdated API usage] What I've considered: [any approaches you've thought about] Optimization goals: - Eliminate N+1 query problem - Add proper indexing recommendations - Maintain TypeScript type safety - Explain each optimization with timing estimates Language: Node.js 20+ with Sequelize 6.35 and TypeScript 5.3 Please suggest: 1. Refactored code with explanations 2. Before/after comparison 3. Performance improvements expected

ตัวอย่าง Prompt สำหรับ DevOps

Prompt สำหรับ Terraform (Infrastructure as Code)

สร้าง Terraform module ที่ complete พร้อม security best practices

ภาษาไทย (Thai)

Terraform Generation Template (ภาษาไทย)
สร้าง Terraform module สมบูรณ์สำหรับ AWS RDS PostgreSQL instance Module ต้อง: 1. เข้ากันได้กับ Terraform 1.5+ 2. ใช้ AWS provider ล่าสุด (~> 5.0) 3. Variables: instance_class, db_name, username, allocated_storage, multi_az 4. Outputs: database endpoint, port, arn 5. มี security group ที่อนุญาต ingress บน port 5432 เฉพาะจาก security group ID ที่ระบุ 6. เปิดใช้งาน: - Performance Insights - สำรองข้อมูลอัตโนมัติ (7 วัน) - Encryption at rest (AWS KMS) - Deletion protection 7. เพิ่ม IAM role สำหรับเข้าถึง monitoring 8. มี tags สำหรับทุก resources ข้อกำหนดเพิ่มเติม: - ใช้โครงสร้าง module แยกเป็นไฟล์ (main.tf, variables.tf, outputs.tf) - เพิ่ม README.md ที่ครบถ้วนพร้อมตัวอย่างและ outputs - ทำตาม best practices ของ Terraform และแนวทาง security ของ AWS - มี input validation สำหรับ variables แสดงบทบาทเป็น: วิศวกร Terraform ระดับอาวุโส ประสบการณ์ 5+ ปี โปรดให้: 1. main.tf ที่สมบูรณ์พร้อม resources 2. variables.tf พร้อมคำอธิบายและค่าเริ่มต้น 3. outputs.tf 4. README.md พร้อมตัวอย่างการใช้งาน

English

Terraform Generation Template (English)
Generate a complete Terraform module for an AWS RDS for PostgreSQL instance. The module must: 1. Be compatible with Terraform 1.5+ 2. Use latest AWS provider (~> 5.0) 3. Variables: instance_class, db_name, username, allocated_storage, multi_az 4. Outputs: database endpoint, port, arn 5. Include a security group that only allows ingress on port 5432 from a specified source security group ID 6. Enable: - Performance Insights - Automated backups (7-day retention) - Encryption at rest (AWS KMS) - Deletion protection 7. Add IAM role for monitoring access 8. Include tags for all resources Additional requirements: - Use module structure with separate files (main.tf, variables.tf, outputs.tf) - Add comprehensive README.md with examples and outputs - Follow Terraform best practices and AWS security guidelines - Include input validation for variables Act as: A senior Terraform engineer with 5+ years experience. Please provide: 1. Complete main.tf with resources 2. variables.tf with descriptions and defaults 3. outputs.tf 4. README.md with usage examples

Prompt สำหรับ Kubernetes Manifests

สร้าง Kubernetes manifests ที่ production-ready

ภาษาไทย (Thai)

Kubernetes Manifest Template (ภาษาไทย)
เขียน Kubernetes manifests สำหรับ Node.js API service ที่พร้อมใช้งานใน production ข้อกำหนด: 1. Kubernetes version: 1.28+ 2. Namespace: production Manifests ที่ต้องการ: - Deployment พร้อม: - Image: my-org/api-service:v2.3.1 - Replicas: 3 (พร้อม HPA 3-10 ตาม CPU 70%) - Resource requests: 250m CPU, 512Mi memory - Resource limits: 500m CPU, 1Gi memory - Health checks: liveness และ readiness probes - Environment variables จาก ConfigMap และ Secret - Volume mounts สำหรับ logs - Service: - Type: ClusterIP สำหรับ internal traffic - Ports: HTTP บน 8080, metrics บน 9090 - ConfigMap: - Database URL, Redis URL, API keys - Secret: - Sensitive credentials (ตัวอย่าง Base64 encoded) - HorizontalPodAutoscaler: - Scale ตาม CPU utilization - Min: 3 replicas, Max: 10 replicas - NetworkPolicy: - ปฏิเสธ ingress/egress ทั้งหมดโดยค่าเริ่มต้น - อนุญาต traffic จาก namespace ที่ระบุ รวม: - ไฟล์ YAML ที่มีโครงสร้างถูกต้อง - Labels และ annotations สำหรับการจัดระเบียบ - คำอธิบายเรื่อง RBAC requirements - การตั้งค่า rolling update strategy แสดงบทบาทเป็น: วิศวกรแพลตฟอร์ม Kubernetes

English

Kubernetes Manifest Template (English)
Write Kubernetes manifests for a production-ready Node.js API service. Requirements: 1. Kubernetes version: 1.28+ 2. Namespace: production Manifests needed: - Deployment with: - Image: my-org/api-service:v2.3.1 - Replicas: 3 (with HPA for 3-10 based on CPU 70%) - Resource requests: 250m CPU, 512Mi memory - Resource limits: 500m CPU, 1Gi memory - Health checks: liveness and readiness probes - Environment variables from ConfigMap and Secret - Volume mounts for logs - Service: - Type: ClusterIP for internal traffic - Ports: HTTP on 8080, metrics on 9090 - ConfigMap: - Database URL, Redis URL, API keys - Secret: - Sensitive credentials (Base64 encoded examples) - HorizontalPodAutoscaler: - Scale based on CPU utilization - Min: 3 replicas, Max: 10 replicas - NetworkPolicy: - Deny all ingress/egress by default - Allow traffic from specific namespace Include: - YAML files with proper structure - Labels and annotations for organization - RBAC requirements explanation - Rolling update strategy configuration Act as: A Kubernetes platform engineer.

Prompt สำหรับ CI/CD Pipeline (GitHub Actions)

สร้าง workflow ที่ complete พร้อม security

ภาษาไทย (Thai)

CI/CD Template (ภาษาไทย)
สร้าง GitHub Actions workflow YAML สำหรับโปรเจค Node.js 20 พร้อมข้อกำหนดต่อไปนี้: บริบท: - โครงสร้าง monorepo พร้อม workspaces - Package manager: pnpm - Framework: Next.js 14 พร้อม App Router - Deployment target: Vercel - Tests: Jest + Playwright สำหรับ E2E Pipeline stages: 1. Install dependencies (พร้อม caching) 2. Run linter (ESLint + Prettier) 3. Run unit tests (Jest พร้อม coverage) 4. Build application 5. Run E2E tests (Playwright บน Chromium) 6. Deploy ไป staging บน main branch 7. Deploy ไป production บน release tags ข้อกำหนด: - ใช้ matrix strategy สำหรับ test ข้าม Node 18, 20 และ 21 - Cache node_modules และ pnpm store - ใช้ GitHub OIDC สำหรับ deployment ที่ปลอดภัยไปยัง Vercel - เพิ่ม notifications ไป Slack เมื่อล้มเหลว - รวม security scanning ด้วย CodeQL โปรดให้: 1. ไฟล์ workflow YAML ที่สมบูรณ์ 2. โครงสร้าง directory สำหรับ .github/workflows/ 3. คำอธิบายของแต่ละ job 4. Repository secrets และ variables ที่จำเป็น

English

CI/CD Template (English)
Generate a GitHub Actions workflow YAML for a Node.js 20 project with the following requirements: Context: - Monorepo structure with workspaces - Package manager: pnpm - Framework: Next.js 14 with App Router - Deployment target: Vercel - Tests: Jest + Playwright for E2E Pipeline stages: 1. Install dependencies (with caching) 2. Run linter (ESLint + Prettier) 3. Run unit tests (Jest with coverage) 4. Build application 5. Run E2E tests (Playwright on Chromium) 6. Deploy to staging on main branch 7. Deploy to production on release tags Requirements: - Use matrix strategy for testing across Node 18, 20, and 21 - Cache node_modules and pnpm store - Use GitHub OIDC for secure deployment to Vercel - Add notifications to Slack on failure - Include security scanning with CodeQL Please provide: 1. Complete workflow YAML file 2. Directory structure for .github/workflows/ 3. Explanation of each job 4. Required repository secrets and variables

ตัวอย่าง Prompt สำหรับ System Administration

Prompt สำหรับ Server Security Hardening

สร้าง script สำหรับ hardening server ตามมาตรฐาน CIS

ภาษาไทย (Thai)

Security Hardening Template (ภาษาไทย)
สร้าง bash script สำหรับ security hardening อย่างครบถ้วนสำหรับ Ubuntu 22.04 web server หมวดหมู่ Hardening: 1. การจัดการผู้ใช้ (User Management) - ปิด root SSH login - สร้าง admin user พร้อม sudo - ใช้ SSH key authentication เท่านั้น - ลบ user ที่ไม่จำเป็น 2. ความปลอดภัยเครือข่าย (Network Security) - ตั้งค่า UFW firewall rules - ปิด services ที่ไม่ใช้ - ตั้งค่า fail2ban สำหรับ SSH - IP whitelisting สำหรับการจัดการ 3. การอัปเดตระบบ (System Updates) - เปิดใช้งาน automatic security updates - ตั้งค่า unattended-upgrades - ตั้งค่า update notifications 4. ความปลอดภัยของระบบไฟล์ (File System Security) - ตั้งค่า permissions ที่ถูกต้องบน directories ที่สำคัญ - ตั้งค่า /tmp ด้วย noexec - รักษาความปลอดภัย /home directories 5. พารามิเตอร์เคอร์เนล (Kernel Parameters) - sysctl hardening (ปิด IP forwarding ฯลฯ) - โมดูลความปลอดภัยของเคอร์เนล 6. การบันทึกและการตรวจสอบ (Logging and Monitoring) - ตั้งค่า centralized logging - ตั้งค่า logrotate - เปิดใช้งาน auditd สำหรับไฟล์ที่สำคัญ รวม: - Bash script ที่สมบูรณ์พร้อม error handling - คำอธิบายของแต่ละมาตรการ hardening - อ้างอิง CIS benchmark - คำสั่งสำหรับทดสอบ/ตรวจสอบ - ขั้นตอน rollback ถ้าจำเป็น แสดงบทบาทเป็น: ผู้ดูแลระบบ Linux ระดับอาวุโส ระบบปฏิบัติการ: Ubuntu 22.04 LTS

English

Security Hardening Template (English)
Generate a comprehensive security hardening script for a Ubuntu 22.04 web server. Hardening categories: 1. User Management - Disable root SSH login - Create admin user with sudo - SSH key authentication only - Remove unnecessary users 2. Network Security - Configure UFW firewall rules - Disable unused services - Configure fail2ban for SSH - IP whitelisting for management 3. System Updates - Enable automatic security updates - Configure unattended-upgrades - Set up update notifications 4. File System Security - Set proper permissions on sensitive directories - Configure /tmp with noexec - Secure /home directories 5. Kernel Parameters - sysctl hardening (disable IP forwarding, etc.) - Kernel security modules 6. Logging and Monitoring - Configure centralized logging - Set up logrotate - Enable auditd for critical files Include: - Complete bash script with error handling - Explanation of each hardening measure - CIS benchmark references - Testing/verification commands - Rollback procedures if needed Act as: A senior Linux systems administrator. OS: Ubuntu 22.04 LTS

Prompt สำหรับ Troubleshooting

ให้ AI ช่วยวินิจฉัยปัญหาระบบอย่างเป็นระบบ

ภาษาไทย (Thai)

Troubleshooting Template (ภาษาไทย)
ฉันพบปัญหา [อาการ] บนเซิร์ฟเวอร์ Linux ของฉัน ข้อมูลระบบ: - ระบบปฏิบัติการ: [distribution และ version] - เคอร์เนล: [version] - ฮาร์ดแวร์: [CPU, RAM, disk] - โหลดเฉลี่ย: [average] - การเปลี่ยนแปลงล่าสุด: [updates, deployments ฯลฯ] อาการ: - [อธิบายสิ่งที่เกิดขึ้น] - [ข้อความ error ถ้ามี] - [เมื่อเริ่มเกิด] พฤติกรรมที่คาดหวัง: - [สิ่งที่ควรจะเกิด] สิ่งที่ฉันลองแล้ว: - [รายการขั้นตอน troubleshooting ที่ทำไปแล้ว] โปรดให้: 1. คำสั่ง diagnostic ที่ต้องรัน 2. สิ่งที่ต้องระวังใน output 3. สาเหตุที่เป็นไปได้เรียงตามความน่าจะเป็น 4. วิธีแก้ปัญหาที่แนะนำ 5. กลยุทธ์ป้องกันในอนาคต แสดงบทบาทเป็น: ผู้ดูแลระบบ Linux ระดับอาวุโส

English

Troubleshooting Template (English)
I'm experiencing a [symptom] on my Linux server. System information: - OS: [distribution and version] - Kernel: [version] - Hardware: [CPU, RAM, disk] - Load: [average] - Recent changes: [updates, deployments, etc.] Symptoms: - [describe what's happening] - [error messages if any] - [when it started] Expected behavior: - [what should be happening] What I've tried: - [list troubleshooting steps already taken] Please provide: 1. Diagnostic commands to run 2. What to look for in the output 3. Possible causes ranked by likelihood 4. Recommended solutions 5. Prevention strategies for future Act as: A senior Linux systems administrator.

ตัวอย่างจริง: High CPU Usage

อาการ: CPU ใช้งานสูงถึง 85-95% อย่างต่อเนื่อง ระบบ: Ubuntu 22.04 LTS, 8 vCPUs, 16GB RAM โหลดเฉลี่ย: 8.45, 8.32, 7.98 คาดหวัง: CPU ใช้งาน 30-50% ตามปกติ ลองแล้ว: Restart Apache, ตรวจสอบ runaway processes โปรดให้: 1. คำสั่ง diagnostic (htop, iotop, vmstat analysis) 2. วิธีอ่าน output 3. วิธีแก้ Apache tuning ทั่วไป 4. การตั้งค่า monitoring เพื่อตรวจจับตั้งแต่ต้น

เทคนิคและเคล็ดลับที่ต้องรู้

เทคนิคที่ควรทำ

  • ให้ context และรายละเอียดเต็มที่ (version, framework, error messages)
  • ใช้ตัวอย่าง (Few-Shot Prompting) แสดง input/output ที่ต้องการ
  • ระบุ output format ชัดเจน (markdown, JSON, code blocks)
  • แบ่งงานใหญ่เป็น prompt เล็กๆ แล้วเชื่อมกัน (prompt chaining)
  • ขอให้ AI อธิบาย reasoning หรือ "Think step-by-step"
  • ขอ unit tests หรือ examples ไปพร้อมกับโค้ด

ข้อผิดพลาดที่ควรหลีกเลี่ยง

  • ไม่ให้ context หรือให้คำสั่งที่คลุมเครือ (เช่น "Fix my code")
  • โหลด prompt มากเกินไป (ขอทุกอย่างใน prompt เดียว)
  • ใช้ negative instructions (เช่น "Don't use libraries") - ใช้คำบวกแทน
  • ไม่ระบุ success criteria หรือเป้าหมายที่ชัดเจน
  • ลืมระบุ version ของภาษา/framework ที่ใช้
  • ไม่ตรวจสอบหรือทดสอบ output ของ AI

ตัวอย่าง Prompt ภาษาไทยที่เป็นประโยชน์

ตัวอย่าง Prompt ที่คุณสามารถใช้งานได้ทันที พร้อมคำอธิบายว่าทำไมจึงดี

Prompt ที่ดี
ช่วยเขียนฟังก์ชัน Python สำหรับดึงข้อมูลจาก API แบบพร้อม error handling รายละเอียด: - ใช้ requests library - มี timeout และ retry mechanism - ต้องรองรับกรณี connection error, timeout, และ invalid response - รองรับ async/await pattern - ใส docstring ภาษาไทย URL: https://api.example.com/users Response format: JSON array of users
ให้รายละเอียดและข้อกำหนดชัดเจน
Prompt ที่ไม่ดี
เขียนฟังก์ชันดึงข้อมูลให้หน่อยๆ
ไม่ระบุภาษา หรือรายละเอียด
Prompt สำหรับ DevOps
สร้าง Terraform module สำหรับ AWS RDS PostgreSQL ข้อกำหนด: - เปิด Performance Insights - Backup 7 วัน - Encryption at rest ด้วย KMS - Multi-AZ - Instance class: db.t3.micro - มี security group ที่เปิด port 5432 เฉพาะจาก SG ที่ระบุ ต้องการ: - main.tf, variables.tf, outputs.tf - README.md พร้อมวิธีใช้ - ใช้ Terraform 1.5+
ระบุ resource และ security requirements ชัดเจน
Prompt สำหรับ Debugging
ช่วย debug React component ที่ infinite re-render ปัญหา: รีเรนเดอร์ไม่หยุด ทำให้เครื่องช้าลง โค้ด: [paste code] Error: Maximum update depth exceeded คาดหวม: ปิด useEffect dependency array ผิด ต้องการ: 1. อธิบายทีละสิ่งที่ผิด 2. แก้โค้ดให้ถูก 3. อธิบายวิธีป้องกันเพื่อไม่ให้เกิดใหม่
ให้ error message, คาดหวม, และคาดหวิการ
Prompt สำหรับ System Admin
ช่วยตั้งค่า Ubuntu server ให้ปลอดภัย Server: Ubuntu 22.04 LTS ต้องการ: 1. ปิด root SSH login 2. ตั้ง fail2ban สำหรับ SSH 3. ปิด port ที่ไม่ใช้งานด้วย UFW 4. เปิด port 80, 443, 22 เท่านั้น 5. สร้าง user ใหม่ด้วย sudo privileges 6. ให้ bash script ที่ run ได้ทันที เพิ่มเติม: - อธิบายทีละบรรทัดว่าทำอะไร - อธิบายวิธี rollback ถ้ามีปัญหา
ให้ขั้นตอนและคำอธิบายชัดเจน
Prompt สำหรับ Code Review
ช่วย review code สำหรับ REST API endpoint โค้ด: [paste code] เน้น: 1. Security vulnerabilities (SQL injection, XSS, etc.) 2. Performance issues (N+1 query, inefficient logic) 3. Code style และ best practices 4. Error handling ครบถ้วนไหม Output: - แจ้งปัญหา Critical/High/Medium/Low - ให้ code ตัวอย่างที่แก้แล้ว - อธิบายสิ่งที่แก้และเพราะอะไร
ให้ criteria และ output format ที่ต้องการ
Prompt สำหรับ Server Security Hardening (ระดับสูง)
ทำ Server Hardening ให้กับ Ubuntu 22.04 Server สภาพแวดล้อม: - OS: Ubuntu 22.04 LTS - Server: AWS EC2 t3.medium - Services: Nginx, MySQL, PHP-FPM, Redis - เปิดให้บริการ: Web application สำหรับร้านค้าออนไลน์ - User: มี admin user 1 คน, user ปกติ 5 คน ต้องการ: 1. **User & Authentication** - สร้าง user admin ใหม่ด้วย SSH key authentication - ปิด root SSH login - ปิด password authentication สำหรับ SSH - ตั้งค่า password policy (length, complexity, expiry) 2. **Network Security** - ตั้งค่า UFW firewall - เปิดเฉพาะ port 22 (SSH), 80 (HTTP), 443 (HTTPS) - ใช้ fail2ban สำหรับ SSH protection - Rate limiting สำหรับ Nginx 3. **System Hardening** - อัปเดต packages ทั้งหมด - ติดตั้งและตั้งค่า automatic security updates (unattended-upgrades) - ปิด services ที่ไม่ใช้ - ตั้งค่า log rotation 4. **Application Security** - ตั้งค่า Nginx security headers (X-Frame-Options, CSP, etc.) - ติดตั้ง SSL certificate (Let's Encrypt) - ตั้งค่า MySQL security (remove test database, secure root) 5. **Monitoring & Logging** - ติดตั้ง OSSEC หรือ Fail2ban สำหรับ intrusion detection - ตั้งค่า log monitoring พร้อม alerting Output: - Bash script ที่ run ได้ทันที - อธิบายทีละบรรทัดว่าทำอะไร - ระบุความเสี่ยง (High/Medium/Low) สำหรับแต่ละการเปลี่ยนแปลง - ให้ command สำหรับ rollback ถ้ามีปัญหา - เช็คลิสต์สำหรับ verify ว่าทำครบหรือยัง บันทึก: เน้นความปลอดภัยและไม่กระทบ performance มากเกินไป
ให้รายละเอียดเพิ่มเติมเกี่ยวกับ services, user และ environment
Prompt สำหรับ Troubleshooting
ช่วยแก้ปัญหาที่เกิดขึ้นใน production server ปัญหา: ร้านค้าออนไลน์โหลดช้ามาก ลูกค้าร้องเรียนว่า checkout page โหลดนานกว่า 30 วินาที สภาพแวดล้อม: - OS: Ubuntu 22.04 LTS - Server: DigitalOcean Droplet 4GB RAM, 2 vCPU - Tech Stack: Laravel 10, MySQL 8.0, Redis, Nginx - PHP: 8.2 - Database: ~50,000 products - Cache: Redis สำหรับ session และ cache สิ่งที่ตรวจสอบแล้ว: 1. CPU usage: ~70% 2. Memory usage: ~85% 3. Disk space: มีว่าง ~40% 4. Nginx error log: ไม่มี error พิเศษ 5. Laravel log: มี "MySQL server has gone away" error บ้าง คาดหวัง: Database connection pool หรือ N+1 query problem ต้องการ: 1. วิเคราะห์ปัญหาทีละขั้นตอน 2. อธิบายทุกความเป็นไปได้ 3. ให้ command สำหรับ diagnostic 4. ให้ solution ที่ใช้ได้ทันที 5. ให้ solution ระยะยาว (preventive)
ให้สถานะปัจจุบันและสิ่งที่ตรวจสอบแล้ว
Prompt สำหรับ Laravel
ช่วยสร้าง Laravel API สำหรับ Product Management โครงสร้าง: - Laravel 10 - PHP 8.2 - MySQL 8.0 - ใช้ Laravel Sanctum สำหรับ authentication ต้องการ endpoints: 1. GET /api/products - List products (pagination, filtering, sorting) 2. GET /api/products/{id} - Get single product 3. POST /api/products - Create product (admin only) 4. PUT /api/products/{id} - Update product (admin only) 5. DELETE /api/products/{id} - Delete product (admin only) Product Model: - id, name, description, price, stock, category_id, image_url, created_at, updated_at - belongsTo Category - belongsToMany Tag ข้อกำหนด: 1. ใช้ Laravel Resource API 2. ใช้ Form Request สำหรับ validation 3. ใช้ API Policies สำหรับ authorization 4. รองรับ search ด้วย name และ category 5. รองรับ sort ด้วย price (asc/desc) และ created_at 6. Pagination 10 items per page 7. Upload images ไปยัง S3 8. มี swagger/OpenAPI documentation 9. มี unit tests และ feature tests Output: - Migration files - Model (with relationships) - Controller (with all methods) - API Resource - Form Request (Store & Update) - Policy - Routes (api.php) - Tests - คำอธิบายวิธีใช้งาน
ระบุ version และ requirements ทั้งหมด
Prompt สำหรับ Laravel Eloquent Optimization
ช่วย optimize Laravel Eloquent queries สำหรับ order listing page ปัญหา: order listing page โหลดช้าเมื่อมี orders เยอะ โค้ดปัจจุบัน: ```php public function index() { $orders = Order::where('status', '!=', 'cancelled') ->orderBy('created_at', 'desc') ->paginate(20); return view('orders.index', compact('orders')); } ``` Blade View: ```html @foreach($orders as $order) {{ $order->id }} {{ $order->customer->name }} {{ $order->items->count() }} items {{ $order->items->sum('price') }} {{ $order->status }} @endforeach ``` Database Schema:** - orders: id, customer_id, status, created_at, updated_at - customers: id, name, email, created_at, updated_at - order_items: id, order_id, product_id, quantity, price - products: id, name, price, created_at, updated_at ต้องการ: 1. แก้ N+1 query problems 2. ใช้ eager loading 3. ใช้ select เฉพาะ columns ที่จำเป็น 4. ใช้ database aggregation แทน PHP 5. เพิ่ม database indexes ที่เหมาะสม 6. เพิ่ม cache ถ้าจำเป็น Output: 1. อธิบายปัญหาทีละจุด 2. ให้โค้ดที่ optimize แล้ว 3. ให้ migration สำหรับเพิ่ม indexes 4. เปรียบเทียบ performance ก่อน/หลัง (estimated query count) 5. อธิบายว่าทำไมจึงดีขึ้น
ให้โค้ดปัจจุบันและปัญหาที่พบ

Quick Reference: Prompt Templates

Code Generation

Generate X in language Y with requirements Z

Debugging

I have error X in code Y, help me fix it

IaC/DevOps

Generate Terraform/K8s for X with Y requirements

สรุปและ Next Steps

Prompt Engineering เป็นทักษะที่พัฒนาได้ด้วยการฝึกฝนเป็นประจำ เริ่มจากง่ายๆ แล้วค่อยๆ เพิ่มความซับซ้อน