DEV Community

shashank ms
shashank ms

Posted on

Few-Shot Learning with LLMs: A Beginner's Guide

We are going to build a support ticket classifier that learns from a handful of examples embedded directly in the prompt. No fine-tuning required. This helps small teams route tickets without maintaining a training pipeline.

What you'll need

Step 1: Connect to Oxlo.ai

I import the OpenAI SDK and point it at Oxlo.ai. Because the platform is fully OpenAI-compatible, this is a drop-in replacement.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

# Verify the connection
response = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Say connected"},
    ],
)

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

Step 2: Define the system prompt

The system prompt locks the output format. I keep it strict so the model returns only the category name. I verify that the model understands the constraint before moving on.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

SYSTEM_PROMPT = (
    "You classify support tickets into exactly one category: Billing, Technical, or Account. "
    "Respond with only the category name."
)

response = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=[
        {"role": "system", "content": SYSTEM_PROMPT},
        {"role": "user", "content": "List the allowed categories."},
    ],
)

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

Step 3: Add examples and classify one ticket

Few-shot learning works because we prepend example conversations to the prompt. I collected three representative tickets, then appended a live ticket. Because Oxlo.ai uses flat per-request pricing, padding the context with these examples does not change the cost of each call. You can iterate on long few-shot prompts without the bill scaling with token count, which makes the platform a practical choice for this workload. See the pricing page for details.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

SYSTEM_PROMPT = (
    "You classify support tickets into exactly one category: Billing, Technical, or Account. "
    "Respond with only the category name."
)

EXAMPLES = [
    {"ticket": "I was charged twice for my monthly subscription. Please refund the extra payment.", "label": "Billing"},
    {"ticket": "The API returns a 500 error every time I send a request with Unicode characters.", "label": "Technical"},
    {"ticket": "I need to add two more seats to my team plan and update the billing address.", "label": "Account"},
]

messages = [{"role": "system", "content": SYSTEM_PROMPT}]
for ex in EXAMPLES:
    messages.append({"role": "user", "content": ex["ticket"]})
    messages.append({"role": "assistant", "content": ex["label"]})

new_ticket = "My dashboard is blank after the latest update."
messages.append({"role": "user", "content": new_ticket})

response = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=messages,
)

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

Step 4: Batch process a queue

In production you will process many tickets. I wrap the logic in a helper so the few-shot prefix stays consistent across requests.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

SYSTEM_PROMPT = (
    "You classify support tickets into exactly one category: Billing, Technical, or Account. "
    "Respond with only the category name."
)

EXAMPLES = [
    {"ticket": "I was charged twice for my monthly subscription. Please refund the extra payment.", "label": "Billing"},
    {"ticket": "The API returns a 500 error every time I send a request with Unicode characters.", "label": "Technical"},
    {"ticket": "I need to add two more seats to my team plan and update the billing address.", "label": "Account"},
]

def build_messages(new_ticket):
    messages = [{"role": "system", "content": SYSTEM_PROMPT}]
    for ex in EXAMPLES:
        messages.append({"role": "user", "content": ex["ticket"]})
        messages.append({"role": "assistant", "content": ex["label"]})
    messages.append({"role": "user", "content": new_ticket})
    return messages

queue = [
    "I forgot my password and the reset email never arrives.",
    "Can I get an invoice for last quarter?",
    "The webhook stops firing after 100 requests.",
]

for ticket in queue:
    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=build_messages(ticket),
    )
    label = response.choices[0].message.content
    print(f"Ticket: {ticket}\nLabel: {label}\n")

Run it

Save the script as classify.py, export your key, and run it.

export OXLO_API_KEY="sk-..."
python classify.py

When I ran the batch script against Llama 3.3 70B on Oxlo.ai, I got:

Ticket: I forgot my password and the reset email never arrives.
Label: Account

Ticket: Can I get an invoice for last quarter?
Label: Billing

Ticket: The webhook stops firing after 100 requests.
Label: Technical

Wrap-up and next steps

The classifier is now working. If you want to make it more robust, add a confidence score by asking the model to return a number between 0 and 1, or switch to JSON mode so the output is machine-readable. Oxlo.ai supports both features on Llama 3.3 70B and Qwen 3 32B, so those upgrades are single-line changes.

Top comments (0)