πŸ€– AI/ML

Text Generation WebUI

Oobabooga WebUI

An open-source web interface for running and chatting with various large language models (LLMs) in a local environment. Highly extensible, based on Gradio, and supports various quantized models such as GGUF, GPTQ, and AWQ.

πŸ“– Detailed Explanation

Text Generation WebUI (commonly known as "Oobabooga") is an open-source project that lets you run LLMs on a local computer. While providing a chat interface similar to ChatGPT, it guarantees complete privacy without an internet connection. Built with Python and Gradio, it is easy to customize, and various extensions can be added in the form of plugins.

The core strength of this tool is its model format compatibility. It can load almost any form of LLM, including Hugging Face's Transformers models, llama.cpp's GGUF format, ExLlamaV2's EXL2 format, and GPTQ and AWQ quantized models. This allows users to choose the optimal model format for their own hardware specifications.

Text Generation WebUI provides a variety of loaders. The llama.cpp loader can use CPU and GPU together, which is useful in environments with limited VRAM. The ExLlamaV2 loader offers the fastest speed with pure GPU inference. The Transformers loader is fully compatible with standard Hugging Face models.

Extensions include speech recognition (Whisper), speech synthesis (TTS), image generation (Stable Diffusion integration), LoRA adapter loading, and long-context processing (RoPE scaling). An API server feature is also built in, so other applications can call the model through a REST API. In particular, it provides an OpenAI-compatible API, so it integrates easily with apps that use the existing OpenAI SDK.

πŸ’» Code Example

Example of installing Text Generation WebUI and using its API.

# 1. Text Generation WebUI μ„€μΉ˜ (Linux/WSL)
git clone https://github.com/oobabooga/text-generation-webui
cd text-generation-webui

# 원클릭 μ„€μΉ˜ 슀크립트 μ‹€ν–‰
# Linux: ./start_linux.sh
# Windows: start_windows.bat
# Mac: ./start_macos.sh

# 2. λͺ¨λΈ λ‹€μš΄λ‘œλ“œ (예: Llama-2-7B-Chat-GGUF)
python download-model.py TheBloke/Llama-2-7B-Chat-GGUF

# 3. API μ„œλ²„ λͺ¨λ“œλ‘œ μ‹€ν–‰
python server.py --api --model TheBloke_Llama-2-7B-Chat-GGUF

# ==========================================
# Pythonμ—μ„œ API ν˜ΈμΆœν•˜κΈ°
# ==========================================
import requests
import json

# Text Generation WebUI API μ—”λ“œν¬μΈνŠΈ
API_URL = "http://localhost:5000/api/v1/generate"

def generate_text(prompt, max_tokens=200, temperature=0.7):
    """Text Generation WebUI API둜 ν…μŠ€νŠΈ 생성"""
    payload = {
        "prompt": prompt,
        "max_new_tokens": max_tokens,
        "temperature": temperature,
        "top_p": 0.9,
        "top_k": 40,
        "repetition_penalty": 1.15,
        "do_sample": True,
        "seed": -1,
        "stopping_strings": ["", "User:", "\n\n"]
    }

    response = requests.post(API_URL, json=payload)
    if response.status_code == 200:
        result = response.json()
        return result['results'][0]['text']
    else:
        raise Exception(f"API Error: {response.status_code}")

# μ‚¬μš© μ˜ˆμ‹œ
prompt = """### System: 당신은 μΉœμ ˆν•œ AI μ–΄μ‹œμŠ€ν„΄νŠΈμž…λ‹ˆλ‹€.

### User: Pythonμ—μ„œ 리슀트λ₯Ό μ •λ ¬ν•˜λŠ” 방법을 μ•Œλ €μ£Όμ„Έμš”.

### Assistant:"""

response = generate_text(prompt)
print(response)


# ==========================================
# OpenAI ν˜Έν™˜ API μ‚¬μš© (--extensions openai ν”Œλž˜κ·Έ ν•„μš”)
# ==========================================
from openai import OpenAI

# 둜컬 Text Generation WebUI에 μ—°κ²°
client = OpenAI(
    base_url="http://localhost:5000/v1",
    api_key="not-needed"  # 둜컬 μ„œλ²„λŠ” API ν‚€ λΆˆν•„μš”
)

# ChatCompletion API 호좜
response = client.chat.completions.create(
    model="local-model",  # μ‹€μ œ λͺ¨λΈλͺ…은 λ¬΄μ‹œλ¨
    messages=[
        {"role": "system", "content": "당신은 μΉœμ ˆν•œ AI μ–΄μ‹œμŠ€ν„΄νŠΈμž…λ‹ˆλ‹€."},
        {"role": "user", "content": "λŒ€ν•œλ―Όκ΅­μ˜ μˆ˜λ„λŠ” μ–΄λ””μΈκ°€μš”?"}
    ],
    temperature=0.7,
    max_tokens=100
)

print(response.choices[0].message.content)

πŸ—£οΈ Say It Like This in Practice

"I ran Llama locally with Oobabooga and it was faster than I expected."

β†’ Sharing the experience of running a LLaMA model locally with Text Generation WebUI (Oobabooga)

"With a GGUF 4-bit quantized model, I can run a 13B on 8GB of VRAM."

β†’ Explaining that a quantized model makes it possible to run a large model on low-spec hardware

"If you turn on the OpenAI-compatible API, you can switch to a local model with almost no changes to your existing code."

β†’ Emphasizing that the OpenAI API-compatible feature makes migration easy

⚠️ Common Mistakes & Cautions

Crash due to insufficient VRAM

If a model exceeds VRAM when loading, a crash occurs. Use the n-gpu-layers option to adjust the number of layers loaded onto the GPU.

Mismatch between loader and model format

GGUF models must use the llama.cpp loader, and GPTQ models must use the AutoGPTQ/ExLlama loader. Selecting a loader that does not match the format causes an error.

Exceeding the context length

If a model's default context length is exceeded, the output becomes strange. Enable RoPE scaling or use a long-context version of the model.

Chat template not applied

Each model has its own prompt template. If you do not select the correct template in the Instruction tab, quality degrades.

πŸ”— Related Terms

πŸ“š Learn More