Course Contents
- 31.1 LLM Development Overview
- 31.2 API Basics: Your First Call
- 31.3 Prompting in Code
- 31.4 RAG: Retrieval-Augmented Generation
- 31.5 Vector Databases
- 31.6 Fine-Tuning: When and Why
- 31.7 Development Frameworks
- 31.8 Build: A Working Example
- 31.9 Safety in Development
- 31.10 Deployment
- 31.11 Monitoring and Optimisation
- 31.12 Enterprise Case Studies
- 31.13 Summary
31.1 LLM Development Overview
Building with LLMs follows a maturity ladder: prompt engineering → retrieval (RAG) → fine-tuning. Each rung costs roughly 10x more in time and data than the last. The professional path is to exhaust each rung before climbing: most "we need fine-tuning" requests are actually retrieval or prompting problems in disguise.
31.2 API Basics: Your First Call
- Get an API key from any major provider; $5 of credit goes a long way for learning.
- Make a request: POST your prompt, receive structured JSON with the response.
- Learn three parameters: model (which engine), temperature (0 = deterministic, 1 = creative), max_tokens (output length cap).
- Read the usage field: token consumption is your bill — this is how you forecast costs.
from openai import OpenAI
client = OpenAI(api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="gpt-4o-mini",
temperature=0.3,
messages=[{"role":"user","content":"Explain tokens in one sentence"}])
print(resp.choices[0].message.content)
print(resp.usage) # your token bill
31.3 Prompting in Code
Every prompt-engineering technique applies directly in code — plus two new ones: system messages and structured outputs. System messages set persistent behaviour across a session; requesting JSON output with a fixed schema turns the model into a reliable component other software can consume. Version-control your prompts like code: change one variable at a time and keep a test set.
31.4 RAG: Retrieval-Augmented Generation
RAG = open-book exam for AI. Instead of hoping the model memorised your documents during training, you store them in a searchable index, retrieve the relevant passages per question, and hand them to the model as context. Benefits: answers grounded in your real documents, citations possible, knowledge updatable in minutes — no retraining.
A pet-supplies wholesaler indexed 3,000 SKUs of product docs, quote history and logistics FAQs. Customer-service staff were asked daily: "When will this cat food restock?" "What's the MOQ?" With RAG, the system retrieves the right passages and generates grounded answers. Hallucination rates fell sharply; new-staff onboarding dropped from two weeks to three days.
31.5 Vector Databases
A vector database stores text as embeddings — numeric vectors capturing meaning — so "similar meaning" is findable by distance, not keywords. It is the index that makes RAG's retrieval step fast and semantically aware: "why is my order late" finds the shipping-delay section even though no word overlaps. Managed options (Pinecone, cloud-native services) remove most operational work for SMB-scale projects.
31.6 Fine-Tuning: When and Why
31.7 Development Frameworks
Frameworks (LangChain, LlamaIndex and friends) package the common patterns: document loaders, retrieval chains, agent loops. For prototypes they accelerate; for production, evaluate honestly whether a thin custom layer is simpler — every abstraction has failure modes you'll eventually debug. The no-code alternative (Zapier + APIs) covers many SMB automation needs without code.
31.8 Build: A Working Example
- Pick one repetitive text task with clear input/output (e.g. summarising customer emails into tickets).
- Collect 30 real examples: input + what the ideal output looks like.
- Write the prompt with few-shot examples; test against all 30, score accuracy.
- Add a fallback: confidence low → route to human.
- Automate the plumbing: schedule, email integration, logging.
31.9 Safety in Development
- Input filtering: strip or flag personal data before it reaches the model.
- Injection defence: system-prompt guardrails + output filtering; never let user text directly rewrite instructions.
- Human escalation: always an exit path from AI to a person.
- Rate and cost limits: cap per-user usage to prevent runaway bills.
31.10 Deployment
Start inside your team, not with customers. Internal deployment surfaces failure modes cheaply; customer-facing rollouts deserve a staged percentage ramp with monitoring. Keep prompts and schemas in version control so any regression can be rolled back in minutes.
31.11 Monitoring and Optimisation
- Quality metrics: sample 5% of outputs weekly for human scoring; track the trend.
- Cost metrics: tokens per task; alert on spikes (usually a looping bug or abuse).
- Latency: users forgive imperfect answers more than slow ones — measure p95.
- Feedback loop: every user correction is a free test case for your next prompt iteration.
31.12 Enterprise Case Studies
- Support copilot: draft answers from your knowledge base (RAG), human sends. CSAT up, handle time down.
- Document pipeline: extract structured fields from invoices/quotes into your systems. Accuracy beats manual entry; exceptions route to humans.
- Internal Q&A: policy and product knowledge indexed for staff. Onboarding time collapses.
31.13 Summary
You know the ladder (prompt → RAG → tune), your first API call, the RAG architecture and its vector index, safety guardrails, and the deployment path. Security details next: AI Security in Practice →
Keep learning
Frequently Asked Questions
Ready to put AI to work in your business?
Buddylala.ai assigns you a dedicated AI account manager — zero technical overhead, integrating ERP/CRM/Shopify.
Free WhatsApp consultation →