llm-quickstart
as a Project (RStudio) or Folder (Positron) in your IDE#hackathon-20
Clone https://github.com/jcheng5/llm-quickstart
Grab your OpenAI/Anthropic API keys; see the thread in #hackathon-20
For R: install.packages(c("ellmer", "shinychat", "dotenv", "shiny", "paws.common", "magick", "beepr"))
For Python: pip install -r requirements.txt
“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?"}
]
}'
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?"},
{"role": "assistant", "content": "The moon does not have a capital. It is not inhabited or governed."},
{"role": "user", "content": "Are you sure?"}
]
}'
un|con|ventional
ellmer
high-level, easy, much less ambitious than langchain
Open and run one of these options:
01-basics.R
01-basics-bedrock.R
for cloud01-basics-openai.py
(low level library)01-basics-langchain.py
(high level framework)01-basics-chatlas.py
(high level framework, similar to R)
01-basics-chatlas-bedrock.py
for cloudIf it errors, now is the time to debug.
If it works, study the code and try to understand how it maps to the low-level HTTP descriptions we just went through.
role
(“system”, “user”, “assistant”) and a content
string{shinychat
} package
https://github.com/posit-dev/shinychat
Creating chatbots in Shiny for Python
ui.Chat
for data privacy reasons, so instead…https://github.com/posit-dev/querychat (R and Python)
Another way to think of it:
Take a minute to look at one of the following docs. See if you can get them to run, and try to understand the code.
ellmer
docs (anticlimactically easy), or example 02-tools.R
in llm-quickstart
repoopenai
example: 02-tools-openai.py
(tedious, low-level, but understandable)langchain
example: 02-tools-langchain.py
(not bad)chatlas
example: 02-tools-chatlas.py
(easy, like ellmer
)Some solutions
Goal: Extract ingredient list from recipe and return in a structured format.
Example user input:
In a large bowl, cream together 1 cup of softened unsalted butter and ½ cup of white sugar until smooth. Beat in 1 egg and 1 teaspoon of vanilla extract. Gradually stir in 2 cups of all-purpose flour until the dough forms. Finally, fold in 1 cup of semisweet chocolate chips. Drop spoonfuls of dough onto an ungreased baking sheet and bake at 350°F (175°C) for 10-12 minutes, or until the edges are lightly browned. Let the cookies cool on the baking sheet for a few minutes before transferring to a wire rack to cool completely. Enjoy!
The user input contains a recipe. Extract a list of ingredients and return it in JSON format.
Assistant response:
The user input contains a recipe. Extract a list of ingredients and return it in JSON format. It should be an array of objects, where each object has keys `ingredient`, `quantity`, and `unit`. Put each object on one line of output.
Assistant response:
[
{"ingredient": "unsalted butter", "quantity": 1, "unit": "cup"},
{"ingredient": "white sugar", "quantity": 1/2, "unit": "cup"},
{"ingredient": "egg", "quantity": 1, "unit": "large"},
{"ingredient": "vanilla extract", "quantity": 1, "unit": "teaspoon"},
{"ingredient": "all-purpose flour", "quantity": 2, "unit": "cups"},
{"ingredient": "semisweet chocolate chips", "quantity": 1, "unit": "cup"}
]
The user input contains a recipe. Extract a list of ingredients and return it in JSON format.
Example Output:
```json
[
{ "ingredient": "Flour", "quantity": 1, "unit": "cup" },
{ "ingredient": "Vegetable oil", "quantity": 0.5, "unit": "tsp" },
{ "ingredient": "Onion", "quantity": 1, "unit": null },
]
```
Assistant response:
[
{ "ingredient": "Unsalted butter", "quantity": 1, "unit": "cup" },
{ "ingredient": "White sugar", "quantity": 0.5, "unit": "cup" },
{ "ingredient": "Egg", "quantity": 1, "unit": null },
{ "ingredient": "Vanilla extract", "quantity": 1, "unit": "teaspoon" },
{ "ingredient": "All-purpose flour", "quantity": 2, "unit": "cups" },
{ "ingredient": "Semisweet chocolate chips", "quantity": 1, "unit": "cup" }
]
LLMs are good at generating unstructured output, but with a little effort, you can get structured output as well.
/```json\n(.*?)\n```/
)set_result(object)
, where its implementation sets some variable. (Works great for ellmer.)Ask #hackathon-20
for help if you’re stuck! (Or ask ChatGPT/Claude to make an example.)
05-vision*