Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 5 min read

LLM vs Other Chatbot Models: A Comprehensive Guide

Most support teams do not need a large language model for every single inbound question. I am going to show you how to build a hybrid router that handles common requests with a lightweight keyword matcher, then escalates

Most support teams do not need a large language model for every single inbound question. I am going to show you how to build a hybrid router that handles common requests with a lightweight keyword matcher, then escalates to an LLM only when the query is ambiguous or complex. You will run both paths through Oxlo.ai, which makes it easy to mix deterministic logic and flat-priced inference in one stack.

What you'll need

  • An Oxlo.ai API key from https://portal.oxlo.ai
  • Python 3.10 or newer
  • The OpenAI SDK. Install it with pip install openai

Step 1: Set up the Oxlo.ai client

Start by importing the OpenAI SDK and pointing it at Oxlo.ai. Because Oxlo.ai is fully OpenAI API compatible, the only difference from calling OpenAI directly is the base URL.

from openai import OpenAI

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

Step 2: Build the rules-based intent matcher

This represents the traditional chatbot approach: fast, deterministic, and zero inference cost. A simple keyword map covers password resets, refunds, and hours without any neural call.

def rules_based_reply(user_message: str) -> str | None:
    msg = user_message.lower()
    if any(word in msg for word in ["password", "reset", "login"]):
        return "You can reset your password at https://example.com/reset. It takes about two minutes."
    if any(word in msg for word in ["refund", "money back"]):
        return "Refunds are processed within 5 to 7 business days. You can check status in your account dashboard."
    if any(word in msg for word in ["hours", "open", "closing"]):
        return "We are open Monday through Friday, 9 AM to 6 PM EST."
    return None

Step 3: Define the LLM system prompt

When the rules engine returns None, the request escalates to Llama 3.3 70B on Oxlo.ai. The system prompt keeps the agent focused, concise, and aware of its boundaries.

SYSTEM_PROMPT = """You are a helpful support assistant. Follow these rules:
- Answer technical and ambiguous questions using clear, plain language.
- If the user asks for legal, medical, or financial advice, decline and suggest they contact a professional.
- Keep responses under three sentences unless the user asks for detail.
- Do not make up policies. If you do not know something, say so."""

Step 4: Wire the router and call Oxlo.ai

The router tries the cheap, deterministic path first. If that fails, it calls the LLM with the exact OpenAI SDK pattern. Oxlo.ai uses request-based pricing, so the cost stays flat even when the conversation history grows. See https://oxlo.ai/pricing for current plan details.

from openai import OpenAI

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

SYSTEM_PROMPT = """You are a helpful support assistant. Follow these rules:
- Answer technical and ambiguous questions using clear, plain language.
- If the user asks for legal, medical, or financial advice, decline and suggest they contact a professional.
- Keep responses under three sentences unless the user asks for detail.
- Do not make up policies. If you do not know something, say so."""

def rules_based_reply(user_message: str) -> str | None:
    msg = user_message.lower()
    if any(word in msg for word in ["password", "reset", "login"]):
        return "You can reset your password at https://example.com/reset. It takes about two minutes."
    if any(word in msg for word in ["refund", "money back"]):
        return "Refunds are processed within 5 to 7 business days. You can check status in your account dashboard."
    if any(word in msg for word in ["hours", "open", "closing"]):
        return "We are open Monday through Friday, 9 AM to 6 PM EST."
    return None

def get_support_response(user_message: str) -> str:
    reply = rules_based_reply(user_message)
    if reply is not None:
        return reply

    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
    )
    return response.choices[0].message.content

Step 5: Add multi-turn conversation memory

Traditional chatbot models usually process single-turn exchanges. An LLM pulls ahead when it sees the full thread, and on Oxlo.ai you do not pay extra as that history gets longer because the pricing is per request, not per token.

from openai import OpenAI

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

SYSTEM_PROMPT = """You are a helpful support assistant. Follow these rules:
- Answer technical and ambiguous questions using clear, plain language.
- If the user asks for legal, medical, or financial advice, decline and suggest they contact a professional.
- Keep responses under three sentences unless the user asks for detail.
- Do not make up policies. If you do not know something, say so."""

def rules_based_reply(user_message: str) -> str | None:
    msg = user_message.lower()
    if any(word in msg for word in ["password", "reset", "login"]):
        return "You can reset your password at https://example.com/reset. It takes about two minutes."
    if any(word in msg for word in ["refund", "money back"]):
        return "Refunds are processed within 5 to 7 business days. You can check status in your account dashboard."
    if any(word in msg for word in ["hours", "open", "closing"]):
        return "We are open Monday through Friday, 9 AM to 6 PM EST."
    return None

def chat_loop():
    messages = [{"role": "system", "content": SYSTEM_PROMPT}]
    print("Support bot ready. Type 'exit' to quit.")
    while True:
        user_input = input("User: ")
        if user_input.lower() == "exit":
            break

        fast_reply = rules_based_reply(user_input)
        if fast_reply:
            print(f"Bot (rules): {fast_reply}")
            continue

        messages.append({"role": "user", "content": user_input})
        response = client.chat.completions.create(
            model="llama-3.3-70b",
            messages=messages,
        )
        assistant_msg = response.choices[0].message.content
        messages.append({"role": "assistant", "content": assistant_msg})
        print(f"Bot (LLM): {assistant_msg}")

if __name__ == "__main__":
    chat_loop()

Run it

Save the final script as support_bot.py and run it from your terminal.

$ python support_bot.py
Support bot ready. Type 'exit' to quit.
User: I forgot my password
Bot (rules): You can reset your password at https://example.com/reset. It takes about two minutes.
User: It says my account is locked after too many tries
Bot (LLM): Account lockouts usually clear after 30 minutes. If you need immediate access, contact support to unlock it manually.
User: Does that apply to SSO logins too?
Bot (LLM): For SSO accounts, the lockout policy is managed by your identity provider, so the timing may differ. Check with your IT admin for specifics.

Wrap-up and next steps

You now have a working example of how to pair deterministic chatbot logic with an LLM fallback. Two concrete ways to extend it: first, swap the keyword matcher for a retrieval step using Oxlo.ai's embedding models like BGE-Large to handle larger knowledge bases without full LLM latency. Second, add function calling to the LLM branch so it can query live APIs for order status or create support tickets directly.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.