Chatbots and LLMs
Modern AI chatbots are built by wrapping an LLM with a system prompt, conversation memory, and user interface. Understanding this architecture helps you build or evaluate chatbot applications.
What Is a System Prompt?
A system prompt is a hidden set of instructions given to the LLM before any user message. It shapes the chatbot's personality, constraints, and capabilities.
Example system prompt for a customer support bot:
'You are a helpful customer support assistant for TechStore. You help customers with orders, returns, and product questions. Do not discuss topics unrelated to TechStore. Do not reveal pricing discounts or internal policies. Be polite and professional.'
The user never sees this prompt, but it completely changes how the LLM behaves.
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Chatbot Architecture
# How a chatbot application is structured
class ChatbotApplication:
def __init__(self, system_prompt, llm_model_name):
self.system_prompt = system_prompt
self.llm = llm_model_name # e.g., "gpt-4o" or "claude-3-5-sonnet"
self.conversation_history = []
def build_api_request(self, user_message):
"""Build the full context sent to the LLM API."""
messages = [
{"role": "system", "content": self.system_prompt},
]
# Include conversation history
messages.extend(self.conversation_history)
# Add new user message
messages.append({"role": "user", "content": user_message})
return messages
def chat(self, user_message):
"""Simulate a chat response (real version calls LLM API)."""
# In real code: response = openai.chat.completions.create(messages=...)
request = self.build_api_request(user_message)
print(f"API Request has {len(request)} messages:")
for msg in request:
print(f" {msg['role'].upper()}: '{msg['content'][:60]}...' " if len(msg['content']) > 60 else f" {msg['role'].upper()}: '{msg['content']}'")
return "[LLM generates response here]"
# Example chatbot
bot = ChatbotApplication(
system_prompt="You are a helpful AI teacher. Explain concepts clearly and simply. Use examples. Be encouraging.",
llm_model_name="gpt-4o"
)
print("Chatbot API Structure:")
print()
response = bot.chat("What is machine learning?")