# Set payment
payment = "one thousand"
# Code that may raise exception
try:
if float(payment) < 0:
print("Payment cannot be negative.")
# Print when exception occurs
except ValueError:
print("Payment must be a number.")
# Set payment
payment = 500
# Code that may raise exception
try:
if float(payment) < 0:
print("Payment cannot be negative.")
# Print when exception occurs
except ValueError as e:
print(f"Error: {e}")
# Print when exception does not occur
else:
print("Processing payment ...")
# Set payment
payment = 500
# Code that may raise exception
try:
if float(payment) < 0:
print("Payment cannot be negative.")
# Print when exception occurs
except ValueError as e:
print(f"Error: {e}")
# Print when exception does not occur
else:
print("Processing payment ...")
# Print no matter what
finally:
print("Thank you for your payment.")
ผลลัพธ์:
Processing payment ...
Thank you for your payment.
# Set payment
payment = -50
# Code that may raise exception
try:
if not isinstance(payment, (int, float)):
raise TypeError("Payment must be a number.")
if payment < 0:
raise ValueError("Payment cannot be negative.")
# Print when exception occurs
except (TypeError, ValueError) as e:
print(f"Error: {e}")
# Print when exception does not occur
else:
print("Processing payment ...")
# Print no matter what
finally:
print("Thank you for your payment.")
ผลลัพธ์:
Error: Payment cannot be negative.
Thank you for your payment.
# Set payments
payments = {
"Alex": "one thousand",
"Barbara": -50,
"Carter": 500
}
# Loop through payments
for name, payment in payments.items():
# Print name and payment
print(f"{name} paying {payment}.")
# Code that may raise exception
try:
if not isinstance(payment, (int, float)):
raise TypeError("Payment must be a number.")
if payment < 0:
raise ValueError("Payment cannot be negative.")
# Print when exception occurs
except (TypeError, ValueError) as e:
print(f"Error: {e}")
# Print when exception does not occur
else:
print("Processing payment ...")
# Print no matter what
finally:
print("Thank you for your payment.")
# Print divider
print("\\n -------------------------------------------------- \\n")
ผลลัพธ์:
Alex paying one thousand.
Error: Payment must be a number.
Thank you for your payment.
--------------------------------------------------
Barbara paying -50.
Error: Payment cannot be negative.
Thank you for your payment.
--------------------------------------------------
Carter paying 500.
Processing payment ...
Thank you for your payment.
--------------------------------------------------
ถ้าข้าม 2 ขั้นตอนนี้ไป เราจะไม่สามารถใช้งาน function ได้
เช่น เรียกใช้ sample_n() เพื่อสุ่มข้อมูลจาก data frame (ตารางข้อมูล):
# Data frame of my friends
friends <- data.frame(
name = c("Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Heidi"),
age = c(28, 32, 25, 30, 29, 35, 27, 31)
)
# friends data frame:
# name age
# 1 Alice 28
# 2 Bob 32
# 3 Charlie 25
# 4 David 30
# 5 Eve 29
# 6 Frank 35
# 7 Grace 27
# 8 Heidi 31
# Sample 3 of my friends
sample_n(friends, 3)
ผลลัพธ์:
Error in sample_n(friends, 3) : could not find function "sample_n"
จะเห็นได้ว่า R ส่ง error กลับมา ซึ่งเราแก้ได้โดยติดตั้งและโหลด package ก่อนเรียกใช้งาน sample_n():
💪 ผมขอแนะนำ R Book for Psychologists หนังสือสอนใช้ภาษา R เพื่อการวิเคราะห์ข้อมูลทางจิตวิทยา ที่เขียนมาเพื่อนักจิตวิทยาที่ไม่เคยมีประสบการณ์เขียน code มาก่อน
ในหนังสือ เราจะปูพื้นฐานภาษา R และพาไปดูวิธีวิเคราะห์สถิติที่ใช้บ่อยกัน เช่น:
Correlation
t-tests
ANOVA
Reliability
Factor analysis
🚀 เมื่ออ่านและทำตามตัวอย่างใน R Book for Psychologists ทุกคนจะไม่ต้องพึง SPSS และ Excel ในการทำงานอีกต่อไป และสามารถวิเคราะห์ข้อมูลด้วยตัวเองได้ด้วยความมั่นใจ
การที่ AI พัฒนาเร็วขึ้นเรื่อย ๆ ทำให้เรามีเวลาปรับตัวน้อยลงเรื่อย ๆ
และตอนนี้ เราเหมือนอยู่ที่ทางแยกที่เราจะต้องเลือกว่า เราจะเรียนรู้การใช้ AI ให้เป็นและอยู่รอดในยุคของ AI หรือเราจะใช้ AI แบบเดิม ๆ และถูกทิ้งไว้ข้างหลัง
The people who will come out of this well won’t be the ones who mastered one tool. They’ll be the ones who got comfortable with the pace of change itself. — Matt Shumer
💼 Part II. Working With AI
.
ข้อ 9. Maslow’s hammer
I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail. — Abraham Maslow
Maslow’s hammer เป็น mental model ที่บอกว่า เครื่องมือสามารถจำกัดมุมมองของเราได้
เช่น ถ้าเรามีค้อน เราจะมองทุกอย่างเป็นตะปู
ในยุคของ AI เราอาจมองว่าทุกอย่างแก้ได้ด้วย AI:
ทำงานเร็วขึ้น
ผิดพลาดน้อยลง
มีเวลามากขึ้น
แต่ไม่ใช่ทุกปัญหาจะแก้ได้ด้วย AI เพราะ AI ไม่ใช่เครื่องมือสำหรับแก้ทุกอย่าง
ถ้าเราอยากตอกตะปู เราจะต้องใช้ค้อน ไม่ใช่ AI
การใช้ AI ที่ถูกต้อง คือ เริ่มต้นจากปัญหาและความต้องการของเรา แล้วเลือกเครื่องมือที่ตอบโจทย์ ซึ่งเครื่องมือนั้นอาจจะเป็น AI หรือไม่ก็ได้
.
ข้อ 10. AI is built in man’s image
AI เกิดจากการ train model ด้วยข้อมูลจากอินเทอร์เน็ตซึ่งมาจากมนุษย์
Human -> Data -> Train -> AI
เพราะ AI ถูกสร้างจากข้อมูลของมนุษย์ และเรามองได้ว่า AI เป็นเหมือนเป็นมนุษย์คนหนึ่ง
.
ข้อ 11. AI as capable but junior assistant
ถ้าเรามอง AI เป็นคน AI จะเป็นเหมือนผู้ช่วยที่มีความรู้รอบด้านและมีศักยภาพสูง
แต่สิ่งเดียวที่ผู้ช่วยคนนี้ยังขาดไป คือ ทิศทาง
.
ข้อ 12. Even a fried egg is hard to get right
การทำงานกับ AI ก็เหมือนสั่งไข่ดาว แม้จะดูง่าย แต่ก็ไม่ง่ายอย่างที่คิด
บางครั้ง เราอยากกินไข่ไม่สุก แต่ได้แบบสุกมาแทน
บางครั้ง เราอยากให้ AI สร้างรูปในแบบที่เราคิด แต่ไม่เคยได้ภาพนั้นสักที
ถ้าสิ่งที่ AI ส่งกลับมาไม่ตรงใจ เราควรจะบอก AI ว่าอะไรที่ยังไม่ถูกใจ เพื่อให้ AI ปรับผลลัพธ์และส่งกลับมาให้เราเช็กจนกว่าเราจะพอใจกับงานของ AI
.
ข้อ 16. Be accountable
เราควรจะเช็กงานของ AI ทุกครั้ง เพราะถ้าเราไม่รับผิดชอบกับงานของ AI เราอาจจะเป็นเหมือนทนายความจากออสเตรเลียที่ถูกตรวจสอบ หลังจากศาลพบว่าเอกสารที่ทนายนำส่งเป็นข้อมูลที่ไม่มีอยู่จริง
แม้ทนายจะอ้างว่ารู้เท่าไม่ถึงการณ์ว่า AI ที่บริษัทให้ใช้สามารถสร้างข้อมูลที่ไม่มีอยู่จริงได้ และตัวเองควรตรวจสอบข้อมูลจาก AI ก่อน ศาลยังสั่งให้ทนายงดว่าความด้วยตัวเองเป็นเวลา 2 ปี โดยในระยะเวลานี้จะต้องทำงานเป็นลูกจ้างของคนอื่น และต้องรายงานต่อศาลทุกไตรมาส
ดังนั้น ไม่ว่างานของ AI จะดูดีขนาดไหน เราควรจะตรวจสอบด้วยตัวเองก่อนที่จะนำงานไปใช้จริง
# Set system prompt
system_prompt = """
You are a helpful, cheerful, and optimistic assistant.
Be concise, validate answers, and admit when you don’t know.
Make responses clear, easy to read, and sprinkle in playful emoji.
"""
# Instantiate chat history
chat_history = [
{
"role": "system",
"content": system_prompt
}
]
📨 Step 4. Create a Chat Function
ในขั้นที่ 4 เราจะสร้าง function ที่จะทำให้เราถาม-ตอบกับ chatbot แบบ real-time ได้:
# Create a function for chatbot
def chatbot(model="gemini-2.5-flash"):
# Set chat history as global variable
global chat_history
# Print chat header
display(Markdown("# 🟢 --- Chat Begins ---"))
# Print chat instruction
print("ℹ️ Type \\"end chat\\" to exit.")
# Loop through conversation
while True:
# Render user prompt display
display(Markdown("## 🧑💻 You:"))
# Get user input
user_prompt = input("")
# Check if user wants to exit chat
if user_prompt.lower() == "end chat":
# Print goodbye message
display(Markdown("## ✨ Assistant:\\n" + "👋 See you later!"))
# End chat
break
# Append user input to chat history
chat_history.append(
{
"role": "user",
"content": user_prompt
}
)
# Get response
response = client.chat.completions.create(
# Set prompt
messages=chat_history,
# Set model
model=model
)
# Append response to history
chat_history.append(
{
"role": "assistant",
"content": response.choices[0].message.content
}
)
# Render response
display(Markdown("## ✨ Assistant:\\n" + response.choices[0].message.content + "\\n"))
💬 Step 5. Chat
ในขั้นสุดท้าย เราจะเรียกใช้งาน chatbot() เพื่อเริ่มคุยกับ AI เลย:
💪 ผมขอแนะนำ R Book for Psychologists หนังสือสอนใช้ภาษา R เพื่อการวิเคราะห์ข้อมูลทางจิตวิทยา ที่เขียนมาเพื่อนักจิตวิทยาที่ไม่เคยมีประสบการณ์เขียน code มาก่อน
ในหนังสือ เราจะปูพื้นฐานภาษา R และพาไปดูวิธีวิเคราะห์สถิติที่ใช้บ่อยกัน เช่น:
Correlation
t-tests
ANOVA
Reliability
Factor analysis
🚀 เมื่ออ่านและทำตามตัวอย่างใน R Book for Psychologists ทุกคนจะไม่ต้องพึง SPSS และ Excel ในการทำงานอีกต่อไป และสามารถวิเคราะห์ข้อมูลด้วยตัวเองได้ด้วยความมั่นใจ
ID Name Age Grade CursedEnergy Technique Missions
Min. : 1.00 Length:10 Min. :15.00 Length:10 Min. : 60.00 Length:10 Min. : 20.00
1st Qu.: 3.25 Class :character 1st Qu.:16.25 Class :character 1st Qu.: 76.25 Class :character 1st Qu.: 28.50
Median : 5.50 Mode :character Median :17.00 Mode :character Median : 90.00 Mode :character Median : 37.50
Mean : 5.50 Mean :19.80 Mean :236.40 Mean : 52.30
3rd Qu.: 7.75 3rd Qu.:24.75 3rd Qu.:275.00 3rd Qu.: 73.75
Max. :10.00 Max. :28.00 Max. :999.00 Max. :120.00
.
💠 dim()
dim() ใช้แสดงจำนวน rows และ columns ใน data frame:
# Create a new data frame
new_sorcerer <- data.frame(
ID = 11,
Name = "Hajime Kashimo",
Age = 25,
Grade = "Special",
CursedEnergy = 500,
Technique = "Lightning",
Missions = 60
)
# Bind the data frames by rows
jjk_df <- rbind(jjk_df, new_sorcerer)
# View the result
jjk_df
ผลลัพธ์:
ID Name Age Grade CursedEnergy Technique Missions
1 1 Yuji Itadori 15 1st Year 80 Divergent Fist 25
2 2 Megumi Fushiguro 16 1st Year 95 Ten Shadows 30
3 3 Nobara Kugisaki 16 1st Year 70 Straw Doll 20
4 4 Satoru Gojo 28 Special 999 Limitless 120
5 5 Maki Zenin 17 2nd Year 60 Heavenly Restriction 35
6 6 Toge Inumaki 17 2nd Year 85 Cursed Speech 28
7 7 Panda 18 2nd Year 75 Gorilla Mode 40
8 8 Kento Nanami 27 Special 200 Ratio Technique 90
9 9 Yuta Okkotsu 17 Special 300 Rika 55
10 10 Suguru Geto 27 Special 400 Cursed Spirit Manipulation 80
11 11 Hajime Kashimo 25 Special 500 Lightning 60
💪 ผมขอแนะนำ R Book for Psychologists หนังสือสอนใช้ภาษา R เพื่อการวิเคราะห์ข้อมูลทางจิตวิทยา ที่เขียนมาเพื่อนักจิตวิทยาที่ไม่เคยมีประสบการณ์เขียน code มาก่อน
ในหนังสือ เราจะปูพื้นฐานภาษา R และพาไปดูวิธีวิเคราะห์สถิติที่ใช้บ่อยกัน เช่น:
Correlation
t-tests
ANOVA
Reliability
Factor analysis
🚀 เมื่ออ่านและทำตามตัวอย่างใน R Book for Psychologists ทุกคนจะไม่ต้องพึง SPSS และ Excel ในการทำงานอีกต่อไป และสามารถวิเคราะห์ข้อมูลด้วยตัวเองได้ด้วยความมั่นใจ
เรามีปัจจัยที่ต้องพิจารณาในการทำ AI transformation มีอยู่ 4 อย่าง ได้แก่:
People: พนักงานและลูกค้าของเรา
Culture: วัฒนธรรมขององค์กร
Systems/tools/tech: ระบบ เครื่องมือ และเทคโนโลยี
Finance: เงิน (เพราะองค์กรอยู่ได้ด้วยเงินทุน)
People เป็นสิ่งที่เราต้องให้ความสำคัญเป็นอันดับแรก เพราะถ้าเราโฟกัสที่ technology แต่พนักงานหรือลูกค้าไม่พร้อมที่จะใช้เครื่องมือใหม่ เราอาจจะได้ AI solution ที่ไม่มีใครใช้
🤠 Topic 4. People Management
การบริหารพนักงานในยุคของ AI มีอยู่ 3 หัวข้อ ได้แก่:
Mindset อาจจะเริ่มที่ตัวเราก่อน เช่น ถ้าเราอยากทำ AI transformation แต่เราไม่ชอบ AI เราต้องหันกลับมามองว่า ถ้า AI เป็นสิ่งที่หลีกเลี่ยงไม่ได้ เป็นเราหรือเปล่าที่จะต้องเปลี่ยน
# Load libraries
# Connect to Gemini
from openai import OpenAI
# Connect to Google Drive
from google.colab import drive
# Extract text from PDF
import PyPDF2
# Dedent text
import textwrap
# Render markdown text
from rich.console import Console
from rich.markdown import Markdown
# Set the job description (JD)
web_dev_jd = """
Senior Web Developer
We're looking for a Senior Web Developer with a strong background in front-end development and a passion for creating dynamic, intuitive web experiences. The ideal candidate will have extensive experience with the entire development lifecycle, from project conception to final deployment and quality assurance. This role requires a blend of technical skill, creative collaboration, and a commitment to solving complex programming challenges.
Responsibilities
* Cooperate with designers to create clean, responsive interfaces and intuitive user experiences.
* Develop and maintain project concepts, ensuring an optimal workflow throughout the development cycle.
* Work with a team to manage large, complex design projects for corporate clients.
* Complete detailed programming tasks for both front-end and back-end server code.
* Conduct quality assurance tests to discover errors and optimize usability for all projects.
Qualifications
* Bachelor's degree in Computer Information Systems or a related field.
* Proven experience in all stages of the development cycle for dynamic web projects.
* Expertise in programming languages including PHP OOP, HTML5, JavaScript, CSS, and MySQL.
* Familiarity with various PHP frameworks such as Zend, Codeigniter, and Symfony.
* A strong background in project management and customer relations.
"""
Note: ในกรณีที่ JD เป็นไฟล์ PDF เราสามารถใช้วิธีดึงข้อมูลแบบเดียวกันกับ resumes ได้
.
📄 (3) Resumes
Input สุดท้าย คือ resumes ที่เราต้องการวิเคราะห์
ในตัวอย่าง เราจะดึงข้อมูล resumes จากไฟล์ PDF ใน Google Drive ใน 3 ขั้นตอน ได้แก่:
ขั้นที่ 1. เชื่อมต่อ Google Drive ด้วย drive.mount():
# Connect to Google Drive
drive.mount("/content/drive")
Note: Google จะถามยืนยันการให้สิทธิ์เข้าถึงไฟล์ใน Drive ให้เรากดยืนยันเพื่อไปต่อ
ขั้นที่ 2. กำหนด file path ของไฟล์ PDF ใน Google Drive:
ขั้นที่ 3. ดึง text ออกจาก resumes ด้วย for loop และ PyPDF2:
# Extract resume texts
# Instantiate a collector
rs_texts = {}
# Loop through resume files to get text
for key in rs_file_paths:
# Instantiate an empty string to store the extracted text
rs_text = ""
# Open the PDF file
reader = PyPDF2.PdfReader(rs_file_paths[key])
# Loop through the pages
for i in range(len(reader.pages)):
# Extract the text from the page
text = reader.pages[i].extract_text()
# Append the text to the string
rs_text += text
# Collect the extracted text
rs_texts[key] = rs_text
Contact
+1 (970) 343 888 999
george.evans@gmail.com
<https://www.coolfreecv.com>
32 ELM STREET MADISON, SD
57042
George Evans
PHP / OOP
Zend Framework Summary
Senior Web Developer specializing in front end development .
Experienced with all stages of the development cycle for dynamic
web projects. Well -versed in numerous programming languages
including HTML5, PHP OOP, JavaScript, CSS, MySQL. Strong
background in project management and customer relations.
Perceived as versatile, unconventional and committed, I am
looking for new and interesting programming challenges.
Experience
Web Developer - 09/201 8 to 05/20 22
Luna Web Design, New York
• Cooperate with designers to create clean interfaces and
simple, intuitive interactions and experiences.
• Develop project concepts and maintain optimal workflow.
• Work with senior developer to manage large, complex
design projects for corporate clients.
• Complete detailed programming and development tasks
for front end public and internal websites as well as
challenging back -end server code.
• Carry out quality assurance tests to discover errors and
optimize usability.
Education
Bachelor of Science: Computer Information Systems - 2018
Columbia University, NY
Certifications
PHP Framework (certificate): Zend, Codeigniter, Symfony.
Programming Languages: JavaScript, HTML5, PHP OOP, CSS, SQL,
MySQL.
Reference
Adam Smith - Luna Web Design
adam.smith@luna.com +1(970 )555 555 Skills
JavaScript Symfony Framework
model: model ของ Gemini ที่เราจะเรียกใช้ (เช่น Gemini 2.5 Flash)
temp: ระดับความคิดสร้างสรรค์ของ model โดยมีค่าระหว่าง 0 และ 2 โดย 0 จะทำให้ model ให้คำตอบเหมือนกันทุกครั้ง และ 2 คำตอบจะแตกต่างกันทุกครั้ง
# Create a function to get a Gemini response
def get_gemini_response(prompts, model, temp):
# Generate a response
response = client.chat.completions.create(
# Set the prompts
messages=prompts,
# Set the model
model=model,
# Set the temperature
temperature=temp
)
# Return the response
return response.choices[0].message.content
.
➕ (2) Function ใส่ Input ใน Prompt
ในขั้นที่ 2 เราจะสร้าง function เพื่อประกอบ input เข้ากับ prompt เพื่อพร้อมที่จะนำไปใช้ใน function ในขั้นที่ 1
ในตัวอย่างเราจะสร้าง function แบบนี้:
# Create a function to concatenate prompt + JD + resume
def concat_input(jd_text, rs_text):
# Set the system prompt
system_prompt = """
# 1. Your Role
You are an expert technical recruiter and resume analyst.
"""
# Set the user prompt
user_prompt = f"""
# 2. Your Task
Your task is to meticulously evaluate a candidate's resume against a specific job description (JD) and provide a detailed pre-screening report.
Your analysis must be structured with the following sections and include specific, data-driven insights.
## 1. Strengths
- Identify and elaborate on top three key strengths.
- For each strength, briefly provide specific evidence from the resume (e.g., "The candidate's experience with Python and Django, as shown in their role at Acme Corp, directly addresses the JD's requirement for...") and explain how it directly fulfills a requirement in the JD.
## 2. Weaknesses
- Identify top three areas where the candidate's experience or skills may not fully align with the JD's requirements.
- For each point, briefly explain the potential concern and why it might be a risk for the role (e.g., "The JD requires experience with AWS, but the resume only mentions exposure to Azure. This could indicate a gap in cloud infrastructure expertise.").
## 3. Candidate Summary
- Draft a concise summary of the candidate's professional background.
- Emphasise their JD-relevant core responsibilities, key achievements, and career progression as evidenced in the resume.
## 4. Overall Fit Score
- Provide a numerical score from 1 to 100, representing the overall alignment of the candidate's profile with the JD.
- A higher score indicates a stronger match: 80-100 = best match; 60-80 = strong match; 0-40 = weak match.
## 5. Hiring Recommendation
- Conclude with a clear, binary hiring recommendation: "🟢 Proceed to interview", "🟡 Add to waitlist", or "🔴 Do not proceed".
- Justify this recommendation with a brief, objective explanation based on the analysis above.
---
# 3. Your Output
- Use a professional and objective tone.
- Base your analysis solely on the provided resume and JD. Do not make assumptions.
- Be concise and to the point; no more than 30 words per sentence; the hiring manager needs to quickly grasp the key findings.
- Format your final report using markdown headings and bullet points for readability.
Output template:
'''
# [candidate's name (Title Case)] ([fit score]/100)
[recommendation]: [justification]
## Profile Summary:
[summary]
## Strengths:
- [strength 1]
- [strength 2]
- [strength 3]
## Weaknesses:
- [weakness 1]
- [weakness 2]
- [weakness 3]
'''
---
# 4. Your Input
**1. JD:**
{jd_text}
**2. Resume:**
{rs_text}
---
Generate the report.
"""
# Collect prompts
prompts = [
{
"role": "system",
"content": textwrap.dedent(system_prompt)
},
{
"role": "user",
"content": textwrap.dedent(user_prompt)
}
]
# Return the prompts
return prompts
Note: เราใช้ textwrap.dedent() เพื่อลบย่อหน้าที่เกิดจาก indent ใน function ออกจาก prompt เพื่อป้องกันความผิดพลาดในการประมวลผลของ AI และประหยัด input token
ใช้ for loop เพื่อส่ง resumes ให้กับ Gemini จนครบทุกใบ
# Instantiate a response collector
results = {}
# Loop through the resumes
for rs_name, rs_text in rs_texts.items():
# Create the prompts
prompts = concat_input(web_dev_jd, rs_text)
# Get the Gemini response
response = get_gemini_response(prompts=prompts, model="gemini-2.5-flash", temp=0.5)
# Collect the response
results[rs_name] = response
# Instantiate a console
console = Console()
# Instantiate a counter
i = 1
# Print the results
for rs_name, analysis_result in results.items():
# Print the resume name
print(f"👇 {i}. {rs_name}:")
# Print the response
console.print(Markdown(analysis_result))
# Add spacers and divider
print("\\n")
print("-----------------------------------------------------------")
print("\\n")
# Add a counter
i += 1
ตัวอย่างผลลัพธ์:
ในตัวอย่าง จะเห็นได้ว่า George Evans เหมาะที่จะเป็น Senior Web Developer