SiamCafe.net Blog
Technology

Text Generation WebUI

text generation webui คมอฉบบสมบรณ 2026
Text Generation WebUI | SiamCafe Blog
2025-08-29· อ. บอม — SiamCafe.net· 1,555 คำ

Text Generation WebUI คืออะไร

Text Generation WebUI (oobabooga) เป็น open source web interface สำหรับรัน Large Language Models (LLMs) บนเครื่องตัวเอง รองรับ models หลากหลาย เช่น LLaMA, Mistral, Phi, Qwen และ GGUF format ผ่าน llama.cpp ทำให้สามารถใช้ AI chatbot ได้โดยไม่ต้องพึ่ง cloud services ช่วยรักษา privacy ไม่เสียค่าใช้จ่ายรายเดือน และ customize ได้ตามต้องการ เหมาะสำหรับนักพัฒนา นักวิจัย และผู้ที่ต้องการ self-hosted AI

การติดตั้ง Text Generation WebUI

# install.py — Installation guide
import json

class InstallGuide:
 REQUIREMENTS = {
 "minimum": {
 "name": "Minimum (7B model, CPU)",
 "cpu": "Intel i5 / Ryzen 5 ขึ้นไป",
 "ram": "16 GB RAM",
 "gpu": "ไม่จำเป็น (ช้ากว่า GPU มาก)",
 "storage": "20 GB (model + app)",
 },
 "recommended": {
 "name": "Recommended (13B model, GPU)",
 "cpu": "Intel i7 / Ryzen 7",
 "ram": "32 GB RAM",
 "gpu": "NVIDIA RTX 3060 12GB+ (CUDA)",
 "storage": "50 GB SSD",
 },
 "optimal": {
 "name": "Optimal (70B model, GPU)",
 "cpu": "Intel i9 / Ryzen 9",
 "ram": "64 GB RAM",
 "gpu": "NVIDIA RTX 4090 24GB / A100",
 "storage": "200 GB SSD",
 },
 }

 INSTALL_STEPS = """
# Step 1: Clone repository
git clone https://github.com/oobabooga/text-generation-webui.git
cd text-generation-webui

# Step 2: Run installer (auto-detects OS + GPU)
# Windows:
start_windows.bat

# Linux:
bash start_linux.sh

# macOS:
bash start_macos.sh

# Step 3: เลือก GPU type เมื่อถูกถาม
# A) NVIDIA (CUDA)
# B) AMD (ROCm)
# C) Apple Silicon (Metal)
# D) CPU only

# Step 4: เปิด browser
# http://localhost:7860

# Step 5: Download model
# Tab "Model" → Download → ใส่ model name
# เช่น: TheBloke/Mistral-7B-Instruct-v0.2-GGUF
"""

 DOCKER = """
# Docker installation
docker run -d \\
 --name text-gen-webui \\
 --gpus all \\
 -p 7860:7860 \\
 -p 5000:5000 \\
 -v ./models:/app/models \\
 -v ./characters:/app/characters \\
 -v ./loras:/app/loras \\
 atinoda/text-generation-webui:latest \\
 --listen --api
"""

 def show_requirements(self):
 print("=== System Requirements ===\n")
 for key, req in self.REQUIREMENTS.items():
 print(f"[{req['name']}]")
 print(f" CPU: {req['cpu']}")
 print(f" RAM: {req['ram']}")
 print(f" GPU: {req['gpu']}")
 print()

 def show_install(self):
 print("=== Installation ===")
 print(self.INSTALL_STEPS[:500])

install = InstallGuide()
install.show_requirements()
install.show_install()

Model Selection Guide

# models.py — Model selection guide
import json

class ModelGuide:
 MODELS = {
 "mistral_7b": {
 "name": "Mistral 7B Instruct",
 "size": "7B parameters (~4-5 GB GGUF Q4)",
 "vram": "6-8 GB",
 "quality": "ดีมากสำหรับขนาดเล็ก",
 "use_case": "General chat, coding, summarization",
 "download": "TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
 },
 "llama3_8b": {
 "name": "LLaMA 3.1 8B Instruct",
 "size": "8B parameters (~5-6 GB GGUF Q4)",
 "vram": "8-10 GB",
 "quality": "ดีมาก, multilingual",
 "use_case": "General purpose, Thai language support",
 "download": "meta-llama/Meta-Llama-3.1-8B-Instruct",
 },
 "qwen2_7b": {
 "name": "Qwen 2.5 7B",
 "size": "7B parameters (~4-5 GB GGUF Q4)",
 "vram": "6-8 GB",
 "quality": "ดีมาก, coding + math",
 "use_case": "Coding, math, Asian languages",
 "download": "Qwen/Qwen2.5-7B-Instruct-GGUF",
 },
 "phi3_mini": {
 "name": "Phi-3 Mini (3.8B)",
 "size": "3.8B parameters (~2-3 GB GGUF Q4)",
 "vram": "4-6 GB",
 "quality": "ดีสำหรับขนาดเล็กมาก",
 "use_case": "Lightweight, fast inference, edge deployment",
 "download": "microsoft/Phi-3-mini-4k-instruct-gguf",
 },
 "codellama_13b": {
 "name": "Code Llama 13B",
 "size": "13B parameters (~8-10 GB GGUF Q4)",
 "vram": "12-16 GB",
 "quality": "ดีมากสำหรับ coding",
 "use_case": "Code generation, debugging, refactoring",
 "download": "TheBloke/CodeLlama-13B-Instruct-GGUF",
 },
 }

 QUANTIZATION = {
 "Q2_K": {"bits": 2, "quality": "ต่ำ", "size": "เล็กมาก", "use": "RAM จำกัดมาก"},
 "Q4_K_M": {"bits": 4, "quality": "ดี (แนะนำ)", "size": "กลาง", "use": "สมดุลคุณภาพ/ขนาด"},
 "Q5_K_M": {"bits": 5, "quality": "ดีมาก", "size": "ใหญ่ขึ้น", "use": "มี VRAM พอ"},
 "Q8_0": {"bits": 8, "quality": "ใกล้ original", "size": "ใหญ่", "use": "VRAM เหลือเฟือ"},
 "F16": {"bits": 16, "quality": "Full precision", "size": "ใหญ่มาก", "use": "Research only"},
 }

 def show_models(self):
 print("=== Recommended Models ===\n")
 for key, model in self.MODELS.items():
 print(f"[{model['name']}] {model['size']}")
 print(f" VRAM: {model['vram']} | Quality: {model['quality']}")
 print(f" Use: {model['use_case']}")
 print()

 def show_quant(self):
 print("=== Quantization Guide ===")
 for key, q in self.QUANTIZATION.items():
 print(f" [{key}] {q['bits']}-bit | Quality: {q['quality']:<15} | {q['use']}")

guide = ModelGuide()
guide.show_models()
guide.show_quant()

Configuration & Optimization

# config.py — Configuration and optimization
import json
import random

class Configuration:
 PARAMETERS = {
 "temperature": {
 "name": "Temperature",
 "range": "0.0 - 2.0",
 "default": "0.7",
 "effect": "ต่ำ = ตอบตรงๆ, สูง = สร้างสรรค์/สุ่มมากขึ้น",
 "recommend": "Chat: 0.7, Code: 0.2, Creative: 1.2",
 },
 "top_p": {
 "name": "Top-P (Nucleus Sampling)",
 "range": "0.0 - 1.0",
 "default": "0.9",
 "effect": "ต่ำ = เลือกคำที่น่าจะเป็นไปได้มากที่สุด",
 "recommend": "0.9 สำหรับทั่วไป, 0.5 สำหรับ precise",
 },
 "max_tokens": {
 "name": "Max New Tokens",
 "range": "1 - 4096+",
 "default": "512",
 "effect": "จำนวน tokens สูงสุดที่จะ generate",
 "recommend": "Chat: 512, Article: 2048, Code: 1024",
 },
 "repetition_penalty": {
 "name": "Repetition Penalty",
 "range": "1.0 - 2.0",
 "default": "1.15",
 "effect": "> 1.0 = ลดการพูดซ้ำ",
 "recommend": "1.1-1.2 สำหรับทั่วไป",
 },
 }

 GPU_OPTIMIZATION = """
# GPU Optimization Tips
# 1. ใช้ GGUF format กับ llama.cpp (เร็วที่สุด)
# 2. ตั้ง GPU layers ให้เต็มที่ VRAM รองรับ
# --n-gpu-layers 35 (สำหรับ 7B Q4 บน 8GB VRAM)
# 3. ใช้ Flash Attention
# --flash-attn
# 4. ตั้ง context length เท่าที่ต้องใช้
# --ctx-size 4096 (ลดลงถ้า VRAM ไม่พอ)
# 5. Batch size
# --batch-size 512
"""

 def show_params(self):
 print("=== Generation Parameters ===\n")
 for key, param in self.PARAMETERS.items():
 print(f"[{param['name']}] Range: {param['range']} | Default: {param['default']}")
 print(f" {param['effect']}")
 print(f" Recommend: {param['recommend']}")
 print()

 def show_gpu(self):
 print("=== GPU Optimization ===")
 print(self.GPU_OPTIMIZATION[:400])

 def benchmark(self):
 print(f"\n=== Performance Benchmark ===")
 configs = [
 {"model": "Mistral 7B Q4", "gpu": "RTX 3060 12GB", "speed": f"{random.randint(25, 40)} tokens/s"},
 {"model": "Mistral 7B Q4", "gpu": "RTX 4090 24GB", "speed": f"{random.randint(60, 100)} tokens/s"},
 {"model": "Mistral 7B Q4", "gpu": "CPU (i7)", "speed": f"{random.randint(3, 8)} tokens/s"},
 {"model": "LLaMA 3 8B Q4", "gpu": "RTX 4070 12GB", "speed": f"{random.randint(30, 50)} tokens/s"},
 ]
 for c in configs:
 print(f" [{c['model']}] {c['gpu']}: {c['speed']}")

config = Configuration()
config.show_params()
config.show_gpu()
config.benchmark()

API & Integration

# api.py — Text Generation WebUI API
import json
import random

class WebUIAPI:
 API_EXAMPLE = """
# api_client.py — Use Text Generation WebUI API
import requests

API_URL = "http://localhost:5000/v1"

def chat(messages, model="default"):
 response = requests.post(f"{API_URL}/chat/completions", json={
 "messages": messages,
 "temperature": 0.7,
 "max_tokens": 512,
 "stream": False,
 })
 return response.json()["choices"][0]["message"]["content"]

def complete(prompt, max_tokens=256):
 response = requests.post(f"{API_URL}/completions", json={
 "prompt": prompt,
 "max_tokens": max_tokens,
 "temperature": 0.7,
 })
 return response.json()["choices"][0]["text"]

# Chat example
result = chat([
 {"role": "system", "content": "You are a helpful Thai developer assistant."},
 {"role": "user", "content": "อธิบาย Python decorator"},
])
print(result)

# Completion example
code = complete("def fibonacci(n):\\n")
print(code)
"""

 OPENAI_COMPATIBLE = """
# OpenAI-compatible API — ใช้ openai library ได้เลย
from openai import OpenAI

client = OpenAI(
 base_url="http://localhost:5000/v1",
 api_key="not-needed" # Local server ไม่ต้องใช้ key
)

response = client.chat.completions.create(
 model="local-model",
 messages=[
 {"role": "user", "content": "สอน Python list comprehension"}
 ],
 temperature=0.7,
 max_tokens=512,
)
print(response.choices[0].message.content)
"""

 def show_api(self):
 print("=== API Usage ===")
 print(self.API_EXAMPLE[:500])

 def show_openai(self):
 print(f"\n=== OpenAI-Compatible API ===")
 print(self.OPENAI_COMPATIBLE[:400])

api = WebUIAPI()
api.show_api()
api.show_openai()

Extensions & Features

# extensions.py — Popular extensions
import json

class Extensions:
 POPULAR = {
 "characters": {
 "name": "Character/Persona",
 "description": "สร้างตัวละครกำหนด personality, knowledge, speaking style",
 },
 "rag": {
 "name": "RAG (Retrieval Augmented Generation)",
 "description": "ให้ model ตอบจากเอกสารที่อัปโหลด (PDF, TXT)",
 },
 "whisper": {
 "name": "Whisper STT (Speech-to-Text)",
 "description": "พูดคุยกับ AI ด้วยเสียง",
 },
 "tts": {
 "name": "TTS (Text-to-Speech)",
 "description": "AI ตอบกลับด้วยเสียง (Bark, XTTS)",
 },
 "gallery": {
 "name": "Gallery",
 "description": "แสดงรูปภาพที่ generate จาก Stable Diffusion",
 },
 "training": {
 "name": "Training (LoRA)",
 "description": "Fine-tune model ด้วย LoRA สำหรับ specific tasks",
 },
 }

 def show_extensions(self):
 print("=== Popular Extensions ===\n")
 for key, ext in self.POPULAR.items():
 print(f" [{ext['name']}] {ext['description']}")

 def use_cases(self):
 print(f"\n=== Use Cases ===")
 cases = [
 "Private AI Assistant — ไม่ส่งข้อมูลออก internet",
 "Code Assistant — ช่วยเขียนโค้ด debug refactor",
 "Document Q&A — ถามตอบจากเอกสารบริษัท (RAG)",
 "Content Writer — เขียนบทความ, สรุป, แปลภาษา",
 "Research — วิเคราะห์ข้อมูล, brainstorm, summarize papers",
 ]
 for case in cases:
 print(f" • {case}")

ext = Extensions()
ext.show_extensions()
ext.use_cases()

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

Q: ต้องมี GPU ไหม?

A: ไม่จำเป็น แต่แนะนำ CPU only: ใช้ได้แต่ช้า (3-8 tokens/s กับ 7B model) GPU (NVIDIA): เร็วกว่า 5-20x (25-100 tokens/s) Apple Silicon: ใช้ Metal acceleration ได้ดี AMD GPU: รองรับผ่าน ROCm (Linux) เริ่มด้วย GGUF Q4 model ถ้าไม่มี GPU

Q: Model ไหนรองรับภาษาไทย?

A: LLaMA 3.1: รองรับ Thai ดี (multilingual training) Qwen 2.5: รองรับ Asian languages ดี Mistral: ภาษาไทยปานกลาง Typhoon (SCB 10X): model ไทยโดยเฉพาะ ยิ่ง model ใหญ่ ยิ่งรองรับ Thai ดีกว่า

Q: GGUF คืออะไร ทำไมต้องใช้?

A: GGUF = GPT-Generated Unified Format สำหรับ llama.cpp ข้อดี: quantized ให้เล็กลง, รันบน CPU+GPU ได้, เร็ว Q4_K_M: สมดุลที่ดีที่สุดระหว่างคุณภาพและขนาด ไฟล์เล็กกว่า original 3-4 เท่า คุณภาพลดลงเล็กน้อย

Q: Text Gen WebUI กับ Ollama อันไหนดีกว่า?

A: Text Gen WebUI: UI สวย, features เยอะ (characters, LoRA, extensions) Ollama: ง่ายกว่า, CLI-focused, lightweight ใช้ Text Gen WebUI: ถ้าต้องการ UI + advanced features ใช้ Ollama: ถ้าต้องการ simplicity + API only ทั้งคู่ใช้ llama.cpp backend performance ใกล้เคียงกัน

📖 บทความที่เกี่ยวข้อง

Text Generation WebUI API Integration เชื่อมต่อระบบอ่านบทความ → Text Generation WebUI CI CD Automation Pipelineอ่านบทความ → Text Generation WebUI Incident Managementอ่านบทความ → Text Generation WebUI สำหรับมือใหม่ Step by Stepอ่านบทความ → Text Generation WebUI Code Review Best Practiceอ่านบทความ →

📚 ดูบทความทั้งหมด →