การรัน AI Model บน Server ต้องการ Resource สูงและมี Latency สูง Cloudflare Workers AI แก้ปัญหานี้ด้วยการรัน AI Inference โดยตรงบน Cloudflare Edge Network ทำให้คุณได้ใชงาน LLM, Image Classification, Translation และอื่นๆ ปราศจาก GPU บน Edge ทำให้คุณไม่ต้องจัดการ AI Infrastructure เอง เหมาะสำหรับนักพัฒนาที่ใช้ Cloud VPS ของ ผู้ให้บริการโฮสติ้ง และต้องการเพิ่ม AI Feature ให้ Application
Cloudflare Workers AI คืออะไร?
Workers AI เป็นบริการ AI Inference บน Cloudflare Edge ที่ให้คุณเรียกใช้ AI Model สำเร็จรูป (Pre-trained) ผ่าน API โดยไม่ต้องแบงหรือจัดการ GPU Server เอง
AI Models ที่รองรับ
| ประเภท | Model ตัวอย่าง | Use Case |
|---|---|---|
| Text Generation | @cf/meta/llama-3.1-8b-instruct | Chatbot, Content Generation |
| Text Embeddings | @cf/baai/bge-small-en-v1.5 | Semantic Search, RAG |
| Image Classification | @cf/microsoft/resnet-50 | จัดหมวดหมู่รูปภาพ |
| Object Detection | @cf/facebook/detr-resnet-50 | ตรวจรฦะสิ่งของในรูปภาพ |
| Translation | @cf/meta/m2m100-1.2b | แปลภาษาอัตโนมัติ |
| Speech to Text | @cf/openai/whisper | ถอดเสียงเป็นข้อความ |
| Summarization | @cf/facebook/bart-large-cnn | สรุปเนื้อหาอัตโนมัติ |
การใช้งาน Workers AI
ตั้งค่า AI Binding
# wrangler.toml
[ai]
binding = "AI"
ตัวอย่างการใช้ LLM
export default {
async fetch(request, env, ctx) {
if (request.method === 'POST') {
const { question } = await request.json();
// เรียกใช้ Llama 3.1 บน Edge
const response = await env.AI.run('@cf/meta/llama-3.1-8b-instruct', {
messages: [
{ role: 'system', content: 'You are a helpful assistant for ผู้ให้บริการโฮสติ้ง Cloud services.' },
{ role: 'user', content: question }
]
});
return new Response(JSON.stringify({
answer: response.response
}), {
headers: { 'Content-Type': 'application/json' }
});
}
return new Response('Send a POST request with {"question": "..."}');
}
};
ตัวอย่างการแปลภาษา
export default {
async fetch(request, env, ctx) {
const { text, source_lang, target_lang } = await request.json();
const translated = await env.AI.run('@cf/meta/m2m100-1.2b', {
text: text,
source_lang: source_lang || 'en', // ภาษาต้นทาง
target_lang: target_lang || 'th' // แปลเป็นภาษาไทย
});
return new Response(JSON.stringify(translated), {
headers: { 'Content-Type': 'application/json' }
});
}
};
ราคาและ Free Tier
Workers AI มี Free Tier สำหรับการเริ่มต้น:
- Free Plan — 10,000 Neurons/วัน (1 Neuron ≈ 1 Text Token หรือ 1 Image Operation)
- Workers Paid Plan ($5/เดือน) — ใช้ได้มากขึ้น + คิดค่าตามการใช้จริง
ประยุกต์ใช้งาน Workers AI กับ ผู้ให้บริการโฮสติ้ง
สำหรับเว็บไซต์หรือ Application ที่ใช้ Cloud VPS ของ ผู้ให้บริการโฮสติ้ง สามารถใช้ Workers AI เพิ่ม AI Feature ได้หลายอย่าง:
- AI Chatbot — สร้าง Chatbot ผู้ช่วยลูกค้า Support ด้วย LLM บน Edge
- สรุปบทความอัตโนมัติ — สรุปเนื้อหาบทความหรือรีวิวเพื่อแสดงผลหน้าเว็บ
- ตรวจจับเนื้อหาอัตโนมัติ — ใช้ Text Classification กรองเนื้อหาที่ไม่เหมาะสม
- Semantic Search — ค้นหาแบบความหมายด้วย Text Embeddings
- Image Moderation — ตรวจสอบรูปภาพอัตโนมัติก่อน Upload
สรุป
Cloudflare Workers AI เป็นวิธีที่ง่ายที่สุดในการเพิ่ม AI Feature ให้กับ Application โดยไม่ต้องจัดการ GPU Infrastructure เอง บริการทำงานร่วมกับ Cloud VPS หรือ Cloud Hosting ของ ผู้ให้บริการโฮสติ้ง เพื่อสร้าง Application ที่เตมไปด้วย AI ในราคาที่แข่งขันได้

