AI Fundamentals
Build the parts of a docs assistant: model requests, context, structured output, document ranking, validated tool calls and evaluations.
What is an AI application?
An AI application uses a model to process inputs and produce outputs. These lessons focus on applications built around language models. A language model generates text from the request it receives and the weights learned during training. Application code chooses the instructions, documents, history and tools supplied with that request. These lessons separate those responsibilities before combining them.
Follow the fictional docuctl documentation assistant: ask a rollback question, supply the relevant page, then inspect tokens, structured replies, document ranking and one proposed tool call. The final evaluation checks answers against fixed cases.
What you'll learn
- Trace tokenization, next-token generation, context limits and sampling in recorded model runs.
- Call local and hosted models, validate structured responses, and distinguish runtime errors from incorrect answers.
- Rank docs with embeddings and check a model-proposed tool call before executing it.
- Test prompt injection controls and compare answers against fixed evaluation cases.
Lessons
Module 1 · 4 lessons · about 37 minHow LLMs work
Run inference, inspect tokens and next-token scores, then assemble messages for one model request.
Run inference with a local LLMRead
Run a language model with and without supplied documentation, and explain how request context differs from trained model weights.
Count tokens with the model's tokenizerRead
Tokenize docuctl docs, commands and IDs with Gemma's own tokenizer, then compare your counts with what Ollama actually processed, chat template included.
Trace next-token generationRead
Trace generation one token at a time, inspect the candidate scores, and compare how supplied documentation changes the model’s next-token predictions.
Send chat messages within the context windowRead
Build a multi-turn chat request for the docuctl docs assistant, resend the history Ollama needs, and detect when the configured context window loses input.
Module 2 · 4 lessons · about 40 minCalling models from code
Control generation, call local and hosted models, validate structured replies and compare document vectors.
Control sampling, output limits and streamingRead
Control response variation and length, stream a reply as it arrives, and distinguish a finished answer from a cutoff or timeout.
Call a local model and a hosted APIRead
Send one docuctl docs question to Gemma through Ollama and to Gemini through its API, compare latency and token usage, and handle each failure.
Get structured output and validate it with PydanticRead
Make the docuctl docs assistant return a typed answer: send a Pydantic JSON schema as the output format, validate every reply, and see its limits.
Rank documents with embeddingsRead
Embed the docuctl docs pages and questions with a local model, rank pages by cosine similarity, and see the two ways similarity search misleads.
Module 3 · 3 lessons · about 33 minTools, safety and evals
Validate proposed tool calls, keep people in control of consequential actions and check answers against cases.
Validate a model-proposed tool callRead
Send a read tool schema to a local model, inspect one proposed call, and reject unknown names or invalid page arguments before the tool function runs.
Defend a tool-using assistant against prompt injectionRead
Test whether document text can trigger an unauthorized tool call, and compare prompt warnings with application permission checks.
Write your first eval for an LLM appRead
Write fixed cases for the docuctl docs assistant, grade every answer in code, run three trials per case, and use the results to judge two attempted fixes.