The pieces to understand how these AI tools work
You can harness the power of LLMs in your own data science and Python work.
Warning
DO NOT send proprietary code, credentials, or sensitive data to any LLM unless you are certain your organizationâs IT policies permit it.
Local models (Ollama) stay on your machine.
Weâll treat LLMs as black boxes â you send text in, text comes back.
Goal: demystify the API so you can wire one into your own Python code (and a Shiny app).
The Moon doesnât have a capital city. Itâs not a country or independent political entityâitâs Earthâs natural satellite, with no permanent human population, government, or established territories.
Thereâs no nation that owns the Moon. The Outer Space Treaty of 1967, which most spacefaring nations have signed, actually prohibits any country from claiming sovereignty over celestial bodies like the Moon.
If youâre interested in space exploration, various missions have landed on the Moon (like the Apollo missions), and there are ongoing discussions about future lunar bases or settlements, but nothing like a âcapitalâ currently exists there.
Is there something specific about lunar exploration or space law you were curious about?
<chatlas._chat.ChatResponse at 0x11bfffdd0>
Yes, Iâm sure. The Moon has no capital because:
This might be a trick question, riddle, or maybe youâre thinking of something else? A few possibilities:
Let me know what you were actually going for!
<chatlas._chat.ChatResponse at 0x10cd9cbf0>
Whatâs the capital of the moon?
There isnât one.
Are you sure?
Yes, I am sure.
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-4.1",
"messages": [
{"role": "system", "content": "You are a terse assistant."},
{"role": "user", "content": "What is the capital of the moon?"}
]
}'The entire conversation is replayed on every request.
Whatâs the capital of the moon?
There isnât one.
Are you sure?
Yes, I am sure.
Whatâs the capital of the moon?
Itâs Long Beach, California.
I donât think thatâs correct.
Yeah youâre right. Itâs not Long Beach.
Language warning
Vancouver is the capital of the moon.
(Quick note for the room: thatâs a scripted, false answer baked into my system prompt for this demo â itâs meant to show how system-level instructions can steer a modelâs output, even to say things that are factually wrong. The moon doesnât have a capital â it has no sovereign government or permanent population.)
<chatlas._chat.ChatResponse at 0x10cd9d0d0>
Vancouver is the capital of the Moon.
<chatlas._chat.ChatResponse at 0x10cd9d250>
Tokens are the fundamental unit â roughly Ÿ of a word on average.
Try it: https://tiktokenizer.vercel.app/
Common words represented with a single number:
Other words may require multiple numbers
https://claude.com/pricing -> API tab

Claude Sonnet 4
For Claude Sonnet:
200k tokens seems like a lot of contextâŠ
âŠbut the entire chat is passed along on every request
{"role": "system", "content": "You are a terse assistant."},
{"role": "user", "content": "What is the capital of the moon?"},
{"role": "assistant", "content": "The moon does not have a capital. It is not inhabited or governed."},
{"role": "user", "content": "Are you sure?"},
{"role": "assistant", "content": "Yes, I am sure. The moon has no capital or formal governance."}| Provider | Models | Notes |
|---|---|---|
| OpenAI | GPT-4.1, o3 | OPENAI_API_KEY |
| Anthropic | Claude Sonnet/Opus | ANTHROPIC_API_KEY |
| Gemini 2.5 | GOOGLE_API_KEY |
|
| GitHub Models | Many (free) | GITHUB_TOKEN |
| Ollama | Llama, Qwen, ⊠| Local, free |
Free access to many frontier models using a GitHub PAT.
chatlas is a unified Python interface to all major LLM providers:
The capital of France is Paris.
<chatlas._chat.ChatResponse at 0x11bfff530>
Same API regardless of provider â swap one line to switch models.
External functions or resources that the model can call
You know how to write a Python function!
Helps with:
LLMs can call functions in your code:
from chatlas import ChatAnthropic, ChatGithub
def pycon_locations(year: int) -> str:
match year:
case 2027:
return "Anchorage, AK"
case 2026:
return "New York City"
case 2025:
return "Vancouver, BC"
chat = ChatAnthropic()
chat.register_tool(pycon_locations)
chat.chat("Where is PyCon US 2027 being held?")Let me look that up for you!
PyCon US 2027 will be held in Anchorage, Alaska! đ»ââïž How exciting â a unique and scenic location for the conference!
<chatlas._chat.ChatResponse at 0x11c0e2150>
The LLM decides when to call the tool and what arguments to pass.
Reproducible and Trustworthy Workflows for Data Science
But these are everything LLMs are notoriously bad at!
Three patterns, increasing complexity:
shinychat)querychat)pip install shiny
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| components: [editor, viewer]
#| layout: horizontal
#| viewerHeight: 500
from shiny.express import input, render, ui
ui.page_opts(title="Basic Shiny App", fillable=True)
ui.input_slider("n", "Number of points", min=10, max=100, value=50)
@render.text
def summary():
return f"You picked {input.n()} points."What if users could ask questions about your dataset in plain English?
querychat translates natural language â SQL â runs against a DuckDB table:
code/app-querychat.py
from querychat.express import QueryChat
from querychat.data import titanic
from shiny.express import render, ui
qc = QueryChat(
titanic(),
"titanic",
greeting="Ask me about the titanic dataset!",
)
qc.sidebar()
with ui.card():
with ui.card_header():
@render.text
def title():
return qc.title() or "Titanic Dataset"
@render.data_frame
def data_table():
return qc.df()
# 4. Set some page options (optional)
ui.page_opts(
fillable=True,
title="Titanic Dataset Explorer"
)Safe: only SQL SELECT statements
Reliable: database engine does the execution
Verifiable: see the generated SQL code
Privacy: only column metadata is shared
Use an LLM to drive filters in a dashboard via natural language:
Template: shiny create --mode core --github jcheng5/py-databot
Generative AI Shiny templates: https://shiny.posit.co/py/templates/#generative-ai
Upcoming tool: ggsql https://ggsql.org/
Try it: https://ggsql.org/wasm/
See also: querychat + vis docs: https://posit-dev.github.io/querychat/py/visualize.html
VISUALISE FROM ggsql:penguins
DRAW point
MAPPING
bill_dep AS x,
body_mass AS y,
species AS color

15 Ă 23 = 345
There isnât one universally agreed meaning of life.
Common answers include: - Happiness - Love and relationships - Growth and learning - Helping others - Creating meaning for yourself
A simple way to put it: the meaning of life is the meaning you choose to give it.
<chatlas._chat.ChatResponse at 0x11c0e1a90>
input,target
"What is 15 * 23?",345
"What is the capital of France?",Paris
"What is 100 / 4?",25
from chatlas import ChatOpenAI
from inspect_ai import Task, task
from inspect_ai.dataset import csv_dataset
from inspect_ai.scorer import model_graded_qa
chat = ChatOpenAI()
@task
def my_eval():
return Task(
dataset=csv_dataset("code/my_eval_dataset.csv"),
solver=chat.to_solver(),
scorer=model_graded_qa(model="openai/gpt-4o-mini")
)name + description, plus a body of instructionsname + description sits in context all the time â a short, standing table of contentsCloser to lazy imports than search: the signatures are always visible, the body loads on demand.
Everything you saw today, scaled up:
{"role": "system", "content": "You are a coding agent."},
{"role": "user", "content": "Fix the failing test."},
{"role": "assistant", "content": "", "tool_calls": [{"name": "bash", "arguments": {"cmd": "pytest -x"}}]},
{"role": "tool", "content": "FAILED test_foo.py::test_bar - AssertionError"},
{"role": "assistant", "content": "", "tool_calls": [{"name": "edit_file", "arguments": {"...": "..."}}]},
{"role": "tool", "content": "file updated"},
{"role": "assistant", "content": "Fixed â the off-by-one in `foo()`."}Same request/response/history pattern from the very first slide â just with more tools and a longer memory.
https://github.com/chendaniely/2026-07-06-pyladies-llm
@chendaniely
PyLadies Vancouver. 2026. https://github.com/chendaniely/2026-07-06-pyladies-llm