May 28, 2025
|
32 min
|
16k views
How to Use LLM APIs for Data Analysis in R and Python, from Zero to Deployed App
How to call a large language model from R or Python for data analysis: install ellmer in R or chatlas in Python, set an API key, and you have a chat object in a few lines. Add knowledge through the system prompt before you reach for anything more complicated. Get the model to write code rather than to produce the answer, because you can check code. Then use tool calling to let the model reach your functions, and querychat to turn a question into SQL against your own data. With Joe Cheng, CTO at Posit.
What you will learn
What LLMs are genuinely good at, and the specific ways they fail Which provider and which model to start with, and what to try first How to set up ellmer in R or chatlas in Python, and make your first call Why system prompt customisation beats retrieval as a starting point Why asking the model to write code is safer than asking it for the answer How to turn a chat object into a Shiny app, in either language What streaming and structured output give you What tool calling is, and what it lets the model do that a chat cannot How querychat turns a plain question into SQL against your own database Chapters 0:00 What an LLM is, and what this talk assumes you know 1:27 What LLMs are good at, and where they fall down 2:51 Where to start, and what not to start with 4:17 Setting up your environment and API keys 5:41 ellmer in R and chatlas in Python: your first chat from code 9:18 Adding knowledge: start with the system prompt, not RAG 10:37 Worked example: an expense policy bot 12:10 Worked example: a data analysis prompt 14:54 Why getting the model to write code beats getting it to answer 16:05 Customising behaviour with the system prompt 17:17 Turning a chat into a Shiny app 19:55 Streaming responses and structured output 22:11 Tool calling: letting the model call your functions 26:48 querychat: a sidebar chatbot that writes SQL 30:40 Closing and questions
Learn more ellmer: https://ellmer.tidyverse.org Posit AI: https://posit.co/products/ai/ Shiny: https://shiny.posit.co
chatlas
ellmer
querychat
Shiny
tidyverse
tidyverse.org
R and Ai
Ai in R
Llm Api
Ellmer R
Chatlas Python
Llm From Code
Tool Calling Llm
Querychat
Shiny Chatbot
Data Analysis With Ai
Joe Cheng
Llm for Data Analysis
Posit