Practice: LLM Prompt Architecture
Practice applying LLM concepts with a hands-on exercise.
12 min•By Priygop Team•Updated 2026
Practice: Build a Simple LLM Chat Interface
Practice: Build a Simple LLM Chat Interface
# Practice: Simulate an LLM chat application
# This illustrates the structure of LLM API calls
import random
random.seed(42)
# Simplified LLM responses (real version calls OpenAI/Anthropic API)
def simulate_llm_response(messages, temperature=0.7):
"""
Simulate an LLM response.
Real code: use openai.chat.completions.create(model="gpt-4o", messages=messages)
"""
# Find the last user message
user_message = ""
for msg in reversed(messages):
if msg["role"] == "user":
user_message = msg["content"].lower()
break
# Simplified pattern matching (real LLM would generate actual responses)
responses = {
"what is ai": "Artificial Intelligence is technology that enables computers to perform tasks that normally require human intelligence, like recognizing images, understanding language, and making decisions.",
"what is machine learning": "Machine Learning is a type of AI where computers learn patterns from data instead of following explicitly programmed rules.",
"what is an llm": "A Large Language Model (LLM) is a type of AI trained on vast amounts of text. It generates responses by predicting the most likely next token given the context.",
"hello": "Hello! I am your AI learning assistant. Ask me anything about Artificial Intelligence!",
"bye": "Goodbye! Keep learning and stay curious.",
}
for key, response in responses.items():
if key in user_message:
return response
return "That is a great question about AI! Could you be more specific? I can answer questions about what AI is, machine learning, LLMs, and more."
# Build the chatbot
class SimpleChat:
def __init__(self, system_prompt):
self.messages = [{"role": "system", "content": system_prompt}]
def chat(self, user_input):
self.messages.append({"role": "user", "content": user_input})
response = simulate_llm_response(self.messages)
self.messages.append({"role": "assistant", "content": response})
return response
def show_history(self):
print("Conversation History:")
for msg in self.messages:
if msg["role"] != "system":
print(f" {msg['role'].upper()}: {msg['content']}")
# Run the chatbot
chat = SimpleChat(
system_prompt="You are a helpful AI tutor. Explain concepts clearly and simply."
)
test_questions = [
"Hello",
"What is AI?",
"What is machine learning?",
"What is an LLM?",
"Bye",
]
print("Simulated LLM Chat Application:")
print()
for question in test_questions:
response = chat.chat(question)
print(f"User: {question}")
print(f"AI: {response}")
print()Diagram
Loading diagram…
Educational visual guide for practice llm prompt architecture.
Module 9 Quiz
Module 9 Quiz
Question 1 of 5