การรับสมัครงานในองค์กรใหญ่อาจมีผู้สมัครเข้ามาถึง 500-1,000 คนต่อตำแหน่ง การอ่านเ Lebenslauf ทีละฉบับด้วยมือใช้เวลาหลายชั่วโมงและอาจเกิดอคติโดยไม่รู้ตัว ในบทความนี้ ผมจะสอนคุณวิธีสร้างระบบ AI ที่ช่วยคัดกรองเอกสารผู้สมัครจำนวนมากได้อย่างรวดเร็วและเป็นธรรม โดยไม่ต้องมีความรู้ด้านการเขียนโปรแกรมมาก่อน

ทำไมต้องใช้ AI ในการคัดกรองเอกสาร

จากประสบการณ์ของผมในการพัฒนาระบบ HR มากว่า 5 ปี การใช้ AI ช่วยคัดกรองมีข้อดีหลายประการ:

เตรียมพร้อมก่อนเริ่มต้น

สำหรับการสร้างระบบนี้ คุณต้องมีบัญชี HolySheep AI ก่อน ซึ่งเป็นแพลตฟอร์ม AI ที่มีความเร็วตอบสนองต่ำกว่า 50 มิลลิวินาที และราคาประหยัดกว่า 85% เมื่อเทียบกับบริการอื่น สามารถสมัครได้ที่ สมัครที่นี่ และจะได้รับเครดิตฟรีเมื่อลงทะเบียน

สิ่งที่ต้องเตรียม

ขั้นตอนที่ 1: ติดตั้งโปรแกรมที่จำเป็น

เปิด Command Prompt หรือ Terminal บนคอมพิวเตอร์ของคุณ พิมพ์คำสั่งต่อไปนี้เพื่อติดตั้งโปรแกรมที่จำเป็น:

pip install requests python-dotenv pdfplumber python-docx

คำสั่งนี้จะติดตั้ง:

ขั้นตอนที่ 2: สร้างไฟล์เก็บรหัส API

สร้างโฟลเดอร์ใหม่ชื่อ "hr-ai-screening" จากนั้นสร้างไฟล์ชื่อ ".env" โดยใช้โปรแกรม Notepad หรือ TextEdit พิมพ์ข้อมูลดังนี้:

HOLYSHEEP_API_KEY=YOUR_HOLYSHEEP_API_KEY

วิธีได้รับ API Key:

ขั้นตอนที่ 3: สร้างโปรแกรมอ่านไฟล์เ Lebenslauf

สร้างไฟล์ใหม่ชื่อ "read_resume.py" และพิมพ์โค้ดต่อไปนี้:

import pdfplumber
import docx
import os

def read_resume(file_path):
    """อ่านเนื้อหาจากไฟล์เ Lebenslauf"""
    ext = os.path.splitext(file_path)[1].lower()
    
    if ext == '.pdf':
        with pdfplumber.open(file_path) as pdf:
            text = ''
            for page in pdf.pages:
                text += page.extract_text() or ''
        return text
    
    elif ext in ['.docx', '.doc']:
        doc = docx.Document(file_path)
        text = '\n'.join([para.text for para in doc.paragraphs])
        return text
    
    elif ext == '.txt':
        with open(file_path, 'r', encoding='utf-8') as f:
            return f.read()
    
    else:
        return "รูปแบบไฟล์ไม่รองรับ"

ทดสอบการอ่านไฟล์

if __name__ == "__main__": test_file = "sample_resume.pdf" if os.path.exists(test_file): content = read_resume(test_file) print(f"อ่านไฟล์สำเร็จ จำนวนตัวอักษร: {len(content)}") print("ตัวอย่างเนื้อหา:", content[:500])

วิธีใช้งาน: นำไฟล์เ Lebenslauf ที่ต้องการอ่านไปวางในโฟลเดอร์เดียวกับโปรแกรม จากนั้นแก้ไขชื่อไฟล์ในบรรทัด "test_file = 'sample_resume.pdf'" ให้ตรงกับชื่อไฟล์จริงของคุณ

ขั้นตอนที่ 4: สร้างระบบประเมินด้วย AI

นี่คือหัวใจหลักของระบบ สร้างไฟล์ "evaluate_resume.py" ที่จะใช้ AI วิเคราะห์เอกสารแต่ละฉบับ:

import os
import requests
from dotenv import load_dotenv

โหลด API Key จากไฟล์ .env

load_dotenv() api_key = os.getenv("HOLYSHEEP_API_KEY")

ตั้งค่าการเชื่อมต่อกับ HolySheep API

BASE_URL = "https://api.holysheep.ai/v1" def evaluate_resume(resume_text, job_requirements): """ ประเมินเอกสารผู้สมัครด้วย AI resume_text: เนื้อหาจากเ Lebenslauf job_requirements: ความต้องการของตำแหน่งงาน """ # สร้างคำถามสำหรับ AI prompt = f"""คุณเป็นผู้เชี่ยวชาญด้านการคัดกรองบุคลากร กรุณาประเมินเอกสารผู้สมัครต่อไปนี้ตามเกณฑ์ที่กำหนด ความต้องการของตำแหน่ง: {job_requirements} เนื้อหาเอกสารผู้สมัคร: {resume_text} กรุณาประเมินและตอบเป็นรูปแบบ JSON ดังนี้: {{ "score": คะแนนรวม 0-100, "education_match": "ตรง/ไม่ตรง/เกี่ยวข้อง", "experience_match": "ตรง/ไม่ตรง/เกี่ยวข้อง", "skills_match": ["รายการทักษะที่ตรงกับความต้องการ"], "missing_skills": ["ทักษะที่ขาดหายไป"], "bias_check": "ปราศจากอคติ/พบจุดที่ควรระวัง", "recommendation": "ผ่าน/ไม่ผ่าน/สัมภาษณ์", "summary": "สรุปความเหมาะสม 2-3 ประโยค" }} """ # ส่งข้อมูลไปยัง HolySheep API headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } data = { "model": "gpt-4.1", "messages": [ {"role": "user", "content": prompt} ], "temperature": 0.3 } response = requests.post( f"{BASE_URL}/chat/completions", headers=headers, json=data, timeout=30 ) if response.status_code == 200: result = response.json() return result["choices"][0]["message"]["content"] else: return f"เกิดข้อผิดพลาด: {response.status_code}"

ตัวอย่างการใช้งาน

if __name__ == "__main__": job_req = """ - วุฒิการศึกษา: ปริญญาตรีสาขาคอมพิวเตอร์ - ประสบการณ์: อย่างน้อย 3 ปีในการพัฒนา Python - ทักษะ: Machine Learning, SQL, Git """ sample_resume = """ สมชาย ใจดี วุฒิการศึกษา: ปริญญาตรี สาขาวิทยาการคอมพิวเตอร์ ประสบการณ์: 4 ปี ในการพัฒนา Python และ Machine Learning ทักษะ: Python, SQL, TensorFlow, Git, Docker """ result = evaluate_resume(sample_resume, job_req) print("ผลการประเมิน:") print(result)

ขั้นตอนที่ 5: ประมวลผลไฟล์จำนวนมากพร้อมกัน

สำหรับการประมวลผลเอกสารหลายฉบับพร้อมกัน สร้างไฟล์ "batch_process.py":

import os
import json
import time
from read_resume import read_resume
from evaluate_resume import evaluate_resume
from concurrent.futures import ThreadPoolExecutor, as_completed

def process_single_resume(file_path, job_requirements, max_retries=3):
    """
    ประมวลผลเอกสาร 1 ฉบับพร้อมระบบลองใหม่หากล้มเหลว
    """
    print(f"กำลังประมวลผล: {os.path.basename(file_path)}")
    
    for attempt in range(max_retries):
        try:
            # อ่านเนื้อหาไฟล์
            resume_text = read_resume(file_path)
            
            if len(resume_text) < 50:
                return {
                    "file": os.path.basename(file_path),
                    "status": "error",
                    "message": "ไฟล์ว่างเปล่าหรืออ่านไม่ได้"
                }
            
            # ส่งให้ AI ประเมิน
            result = evaluate_resume(resume_text, job_requirements)
            
            return {
                "file": os.path.basename(file_path),
                "status": "success",
                "evaluation": result
            }
            
        except Exception as e:
            if attempt < max_retries - 1:
                wait_time = (attempt + 1) * 2
                print(f"  ล้มเหลว ลองใหม่ใน {wait_time} วินาที...")
                time.sleep(wait_time)
            else:
                return {
                    "file": os.path.basename(file_path),
                    "status": "error",
                    "message": str(e)
                }

def batch_process_resumes(folder_path, job_requirements, max_workers=5):
    """
    ประมวลผลไฟล์ทั้งหมดในโฟลเดอร์พร้อมกัน
    """
    # หาไฟล์ทั้งหมดที่รองรับ
    supported_formats = ['.pdf', '.docx', '.doc', '.txt']
    resume_files = []
    
    for file in os.listdir(folder_path):
        if any(file.lower().endswith(ext) for ext in supported_formats):
            resume_files.append(os.path.join(folder_path, file))
    
    print(f"พบไฟล์ทั้งหมด: {len(resume_files)} ฉบับ")
    print(f"ประมวลผลพร้อมกันสูงสุด: {max_workers} ฉบับ")
    
    results = []
    start_time = time.time()
    
    # ประมวลผลพร้อมกัน
    with ThreadPoolExecutor(max_workers=max_workers) as executor:
        future_to_file = {
            executor.submit(process_single_resume, f, job_requirements): f 
            for f in resume_files
        }
        
        for future in as_completed(future_to_file):
            result = future.result()
            results.append(result)
            print(f"✓ เสร็จสิ้น: {result['file']} - สถานะ: {result['status']}")
    
    elapsed_time = time.time() - start_time
    
    # บันทึกผลลัพธ์
    output_file = os.path.join(folder_path, "evaluation_results.json")
    with open(output_file, 'w', encoding='utf-8') as f:
        json.dump({
            "summary": {
                "total_files": len(resume_files),
                "success": sum(1 for r in results if r['status'] == 'success'),
                "errors": sum(1 for r in results if r['status'] == 'error'),
                "processing_time": f"{elapsed_time:.2f} วินาที"
            },
            "results": results
        }, f, ensure_ascii=False, indent=2)
    
    print(f"\nเสร็จสิ้น! ใช้เวลาทั้งหมด: {elapsed_time:.2f} วินาที")
    print(f"บันทึกผลลัพธ์ที่: {output_file}")
    
    return results

การใช้งาน

if __name__ == "__main__": # กำหนดความต้องการของตำแหน่ง job_requirements = """ - วุฒิการศึกษา: ปริญญาตรีสาขาที่เกี่ยวข้อง - ประสบการณ์: อย่างน้อย 2 ปี - ทักษะ: การสื่อสาร, การทำงานเป็นทีม - ภาษา: ภาษาอังกฤษระดับดี """ # ประมวลผลไฟล์ทั้งหมดในโฟลเดอร์ folder = "resumes_to_review" results = batch_process_resumes(folder, job_requirements)

ขั้นตอนที่ 6: สร้างรายงานสรุปผล

สร้างไฟล์ "generate_report.py" เพื่อสร้างรายงานที่อ่านง่าย:

import json
import os
from datetime import datetime

def generate_report(evaluation_results):
    """สร้างรายงานสรุปผลการคัดกรอง"""
    
    report = []
    report.append("=" * 60)
    report.append("รายงานสรุปผลการคัดกรองเอกสารผู้สมัคร")
    report.append(f"วันที่: {datetime.now().strftime('%Y-%m-%d %H:%M')}")
    report.append("=" * 60)
    report.append("")
    
    # นับสถิติ
    total = len(evaluation_results)
    success = sum(1 for r in evaluation_results if r['status'] == 'success')
    errors = total - success
    
    report.append(f"สรุปภาพรวม:")
    report.append(f"  - จำนวนไฟล์ทั้งหมด: {total}")
    report.append(f"  - ประมวลผลสำเร็จ: {success}")
    report.append(f"  - เกิดข้อผิดพลาด: {errors}")
    report.append("")
    
    # แยกผลลัพธ์ที่สำเร็จ
    successful = [r for r in evaluation_results if r['status'] == 'success']
    
    if successful:
        report.append("รายละเอียดผู้สมัครที่ผ่านการคัดกรอง:")
        report.append("-" * 60)
        
        for i, result in enumerate(successful, 1):
            report.append(f"\n{i}. {result['file']}")
            if 'evaluation' in result:
                report.append(f"   ผลการประเมิน: {result['evaluation'][:200]}...")
    
    # บันทึกรายงาน
    report_text = "\n".join(report)
    report_file = "screening_report.txt"
    
    with open(report_file, 'w', encoding='utf-8') as f:
        f.write(report_text)
    
    print(report_text)
    print(f"\nรายงานถูกบันทึกที่: {report_file}")
    
    return report_text

if __name__ == "__main__":
    # อ่านผลลัพธ์จากไฟล์
    if os.path.exists("resumes_to_review/evaluation_results.json"):
        with open("resumes_to_review/evaluation_results.json", 'r', encoding='utf-8') as f:
            data = json.load(f)
            generate_report(data['results'])
    else:
        print("ไม่พบไฟล์ผลลัพธ์ กรุณารัน batch_process.py ก่อน")

วิธีการตั้งค่าเกณฑ์การประเมิน

หัวใจสำคัญของระบบที่เป็นธรรมคือการตั้งค่าเกณฑ์ที่ชัดเจน ตัวอย่างการตั้งค่าตามตำแหน่งงานต่างๆ:

ตำแหน่งนักพัฒนาซอฟต์แวร์

job_requirements_software = """
ตำแหน่ง: นักพัฒนาซอฟต์แวร์
ความต้องการ:
- วุฒิการศึกษา: ปริญญาตรีสาขาคอมพิวเตอร์, วิศวกรรมซอฟต์แวร์ หรือสาขาที่เกี่ยวข้อง
- ทักษะที่ต้องการ: Python, Java, JavaScript, SQL, Git
- ประสบการณ์: 1-3 ปี หรือเป็นเฟรชเกรดที่มีโปรเจกต์สำคัญ
- เกณฑ์การให้คะแนน:
  * ตรงสาขา: +20 คะแนน
  * มีประสบการณ์เต็มเวลา: +25 คะแนน
  * มีทักษะตรงทุกข้อ: +30 คะแนน
  * มีผลงาน/โปรเจกต์ส่วนตัว: +15 คะแนน
  * ผ่านเกณฑ์ขั้นต่ำ: ต้องได้อย่างน้อย 60 คะแนน
"""

ตำแหน่งฝ่ายการตลาด

job_requirements_marketing = """
ตำแหน่ง: เจ้าหน้าที่การตลาด
ความต้องการ:
- วุฒิการศึกษา: ปริญญาตรีสาขาบริหารธุรกิจ, การตลาด หรือสาขาที่เกี่ยวข้อง
- ทักษะที่ต้องการ: การสื่อสาร, การวิเคราะห์ข้อมูล, การใช้โซเชียลมีเดีย, Excel
- ประสบการณ์: 1-2 ปีในงานการตลาด
- ภาษา: ภาษาอังกฤษในระดับที่ใช้งานได้
"""

ข้อผิดพลาดที่พบบ่อยและวิธีแก้ไข

กรณีที่ 1: ได้รับข้อผิดพลาด "401 Unauthorized"

สาเหตุ: API Key ไม่ถูกต้องหรือหมดอายุ

# วิธีแก้ไข: ตรวจสอบและแก้ไขไฟล์ .env

1. เปิดไฟล์ .env และตรวจสอบว่าไม่มีช่องว่างเกิน

รูปแบบที่ถูกต้อง:

HOLYSHEEP_API_KEY=sk-abc123xyz456

2. หากยังไม่ได้ ให้สร้าง API Key ใหม่ที่หน้า dashboard ของ Holy