# Step 1 - install ellmer
install.package("ellmer")
# Step 2 - load ellmer
library(ellmer)
# Step 3 - create a chat object
<- chat_google_gemini()
my_chat_object
# Step 4 - query!
$chat("What preceding languages most influenced R?") my_chat_object
Draft: Getting started with {ellmer} X Google Gemini
A pre-steps mini workshop 🐘✨
Introduction
Getting started with {ellmer} looks easy enough. Install the package, load it, create a chat object and then, boom, start chatting! Right?
Yes! But, there are some pre-steps which might feel like blockers involving API key set up. So, for this mini-workshop, we focus on these pre-steps.
We’ll only assume 1) that you are an R user and 2) that you have a Google account.
After getting through the pre-steps, you should be able to query an LLM from R. Specifically, we’ll query Google Gemini about why {ellmer} features an elephant in its branding!
Pre-steps to getting started with {ellmer}
As discussed above, getting and API and setting it up as an environmental variable (recommended), are required before you can actually dive in and use {ellmer}. We go through these steps for using Google Gemini. Steps should be similar for other LLM providers.
Pre-step A. Get API key
Getting a Google geminani account involves five mini steps.
Actually don’t worry about this step! We’ll use a free tier of Google Gemini, which is free, so finding your credit card (and giving it to a third party) won’t be a blocker! However, note that your conversations and any uploaded will be used to further train the model. ⚠️
Pre-step B. Save API key as an environment variable
# if not yet installed
install.packages("usethis")
::edit_r_environ() usethis
The .Renviron file should open in your RStudio or Positron session.
Paste the API key that you copied in Prestep A.v on the right hand side and in quotation marks. Make sure to have an empty line as the last line in the file.
GOOGLE_API_KEY <- “xxxxYOURxAPIxKEYxHERExxxx”
Important: For ellmer’s function chat_google_gemini
to automatically recognize the API key, the variable must be named GOOGLE_API_KEY
Done with Pre-steps! Now we can do a ‘hello ellmer’!
Step 1.
install.package("ellmer")
Step 2.
library(ellmer)
Step 3 Create a chat object with ellmer::chat_google_gemini()
<- chat_google_gemini() my_chat_object
The environmental variable will automatically be retrieved and used as the api_key
argument in chat_google_gemini()
as long as it is named GOOGLE_API_KEY
, as shown in Prestep B.iii.
Step 4 Ready to query!
$chat("Who is the elephant that the ellmer R package aludes to?") my_chat_object
The `ellmer` R package alludes to **Elmer the Patchwork Elephant**.
Elmer is a beloved children's book character created by David McKee, known for
his unique patchwork of bright colors, rather than the typical elephant grey.
The name `ellmer` (with the extra 'l') is a playful twist on "Elmer" and likely
refers to the package's functionality in handling **mixed-effects models**
(often abbreviated as "LMM" for Linear Mixed Models, or "GLMM" for Generalized
Linear Mixed Models). The "patchwork" nature of Elmer can be seen as a metaphor
for the "mixed" or "layered" structure of data that mixed-effects models are
designed to analyze.