Lab 6: Working with APIs

Link to updated lab

Lab Instructions

In this lab we will be learning about APIs.

See the “Instructions” section of the Introduction to Lab Assignments page for more information about the labs. That page also gives descriptions for the datasets we will be using.

Required reading:

Optional resources:


Note: The above readings are for when this lab used Twitter’s API. Some of the information might be helpful. Please refer to class slack for Zoom recording from class.

Exercises

Q1

Learn to use an API of your choice (this can be OpenAI, which we used in class, or another model).

# Write what API you are using here.

Q2

Write code in R to authenticate with this model (hint: you might find it useful to search for R packages that help you do this, and remember: you will need some type of API key or other “credential”).

# Your answer here

Q3

Write code to generate 25 fictional narratives less than 100 words each about a doctor and store them in a data frame.

# Your answer here

Q4

Write more code that uses an LLM to analyze the gender of the doctor described in each narrative.

# Your answer here

Q5

Report the percentage of times the LLM describes the doctor as having a “female” gender.

# Your answer here