Speaking Internet

Jed Rembold

November 19, 2025

Announcements

  • Feedback on Exam 2 will go out before I sleep tonight
    • It is a crazy amount of work to write, prep, and run a project for the first time ☹
  • Get a start on Project 5!
    • You already have what you need to get through the first few milestones
    • You’ll have what you need for Milestone 3 after today
  • Attend your sections this week! Help on Project 5!
    • Last “real” section!
    • No sections next week
    • Last week is optional and can serve as a “makeup” for one you’ve missed
  • Graphics Contest submissions due Monday night
  • Polling: polling.jedrembold.prof

Infinite Adventure Milestones Continued!

MS4: Generating New Scenes

  • Here is where you’ll get to write a function to use ChatGPT to make a new scene!
  • First need to construct the prompt
    • A template is provided for you! You’ll just need to substitute in the correct bits for any new scene. Things like:
      • This scene’s scene_key
      • An example of how we format a scene
      • The overall plot of the story
      • What choice a user selected to arrive here
      • What the previous scene key was
    • f-strings will be very useful here!

MS4: The API Call

  • Once you have your prompt, you need to package it up and send it off to ChatGPT
  • Example code provided for how to do this
  • You’ll need to provide your NotOpenAI API key at the top of the program
  • After a moment, you’ll get back a string of JSON information
    • Use json.loads(|||your string response|||) to convert this to nested data structures
  • Then you can print it off like usual, and add it to the scenes dictionary!
  • We’ll play more with API calls in just a moment!

NotOpenAI

  • In general, while simpler models do not cost much, they still cost something to access through OpenAI’s API
  • We didn’t want you to have to pay anything though, so instead you connect through our custom NotOpenAI library
    • Acts as a sort of “middle-man”, receiving your request and then forwarding that request on to ChatGPT, but using our API key (which we are paying for)
    • The way you make a request to ChatGPT with the NotOpenAI library is identical to how you would do so with the official OpenAI library
    • Your NotOpenAI keys are allocated around 1.5 million tokens of usage, which should correspond to somewhere between 750 to 1500 generated scenes, which is a LOT! But it isn’t infinite, so don’t abuse it.

MS5: Visualizing

  • Text descriptions are nice, but images can really bring a story to life
  • For all the pre-generated rooms, I have also generated a corresponding image using DallE
  • All images follow the naming pattern of img/|||scene_key|||.jpg
  • When you display the text of a room, you also want to display the corresponding image if it exists
    • Display a black box if it does not exist
  • This is just using existing PGL functionality that you are already familiar with

MS6: Reflecting

  • When we use generative AI, we are, by design, giving up some control to the AI
  • How do we evaluate or measure if the AI is making “good choices”?
  • This milestone asks you to generate a handful of scenes from a new story: engineer_story
  • You want to pay particular attention to the names of your coworkers, and then answer several questions about if “good” decisions are being made.
  • These questions will be answered in infinite_ethics.txt and uploaded along with your code

Final Thoughts

First Time!

  • This is the first time this project has been done at Willamette!
  • All the section leaders have prepped by completing the project
  • Other tutors will likely be less familiar, though they have had access to the materials
    • By patient with them if it takes them a bit longer to get up to speed
    • You can always direct questions to me!
  • I’m very excited to see what fun extensions you can come up with and what your general feelings on the project are!

LLM Problems

  • Generative AI is very provocative atm, for good reason. It can do some amazing things, but at some real cost
  • I personally have strong concerns with both the environmental impacts of generative AI training and the seemingly wanton disregard for intellectual property, copyright, and attribution that big tech has shown in training most models.
  • But usage of and discussions around generative AI have become the norm in especially many tech fields
  • I don’t think this is something we can improve or help guide or regulate without engaging with the technology on more than a surface level
  • Please keep both the benefits, but also the costs in mind as you engage with the technology on this project

Talking to the Web

Web Talk

  • To understand how we can talk to web tools like ChatGPT, we need to understand a bit about how the internet works
  • In a very broad stroke, computers are connected to a shared line and they send messages back and forth
  • What matters then is the software those computers run and how they communicate

Servers

  • A server is usually just a computer that is connected to the internet and running software that allows it to communicated over the internet
  • Usually running 24/7
  • Your internet service provider issues you an IP address when you connect to the internet, which gives other computers a way to “contact” you
  • Can host your own webpage if you run software on that computer to “listen” for those connections
    • When a computer contacts you, you send it back the HTML content of your webpage
  • This gets a bit more nebulous in the modern day “cloud” architecture, but a decent mental model is to still envision a computer at your house that listens for incoming connections and then sends something back

APIs

  • One type of software listens for incoming connections and sends back HTML
  • But why limit ourselves?
  • What if when I receive an incoming connection I want to:
    • Go look up some data that exists on my computer
    • Filter that data in some way
    • Send that data back to whoever contacted me
  • This more general case is often what we call an API, short for Application Programming Interface
  • APIs can be incredibly flexible in what they can do!

API Basics

  • Since an API is still software running on a computer connected to the internet, we need to contact it with its IP address (or domain name)
  • Most APIs will off many endpoints off that address, which correspond to different things you want the API to do
  • Example: Computer located at jedrembold.prof
    • /polling endpoint sends back the polling page HTML
    • /daily_results endpoint might send back a JSON dictionary of all the responses from the day
    • /new_poll endpoint might tell the server to start a new poll

Request Types

  • How do we communicate with these servers or APIs?
  • The HTTP protocol (as in, the letters that start every URL) define several forms of communication
  • Most important are:
    • GET requests: When a system just wants to retrieve information from another system
      • All that is necessary here is the address and endpoint
      • Your browser makes GET requests to access webpage content
    • POST requests: When a system wants to send information to another system
      • Requires both an address and endpoint, plus a payload
      • Often POST requests will also receive a response from the server, at least to say: “Message received”

The request library

  • Your browser can make GET requests, but how can we handle GET and POST requests in Python?

    • Through the very appropriately named requests library!
    • Not part of the default Python install, so need to install with pip
      • Downloading and running this script should also work
  • Import, and then functions for both GET and POST style requests:

    import requests
    
    resp = requests.get(|||URL|||)
    resp2 = requests.post(|||URL|||, |||payload|||)

Decoding request responses

  • When you make a request in Python, of either the GET or POST type, what is returned is a special Response class object
  • This object holds information about how the request went, as well as any information that it gave back to you
  • Can access that information through its various attributes
attribute/method Details
text Gets the content in a string format
content Gets the content in bytes
json() Returns parsed JSON content
status_code Returns a numeric code for how the request went
reason Returns text explaining the numeric code

Status Codes

  • When communicating over the internet, lots of bad things can happen (and some good things)
  • The returned status codes give you an idea of how things went
  • Most commonly:
    • 200 - Ok. All went fine.
    • 400 - You’ve messed something up in your request
    • 401 - You are unauthorized to access this
    • 403 - You are forbidden from accessing this
    • 404 - This is missing?
  • HTTP Cats

Making GET requests

  • GET requests are also what are done by the browser, so we can use them to access either webpage content or API content

  • If grabbing webpage content, use .text to retrieve just the HTML

    resp = requests.get("polling.jedrembold.prof")
    html = resp.text
  • If grabbing API content, you usually will want to use .json() to convert response to a Python data structure

    resp = requests.get(
      "http://api.open-notify.org/astros.json"
    )
    content = resp.json()

GET Demo

  • The REST Countries API gives a way to access lots of information about different countries
  • A variety of endpoints, but to get information about just a single country, we could use: https://restcountries.com/v3.1/name/{name}
  • Let’s write a program to prompt the user for a country name and then use the REST Countries API to report back the number of timezones in that country

Making POST requests

  • Unlike with GET requests, POST requests are sending some information
  • This information needs to be formatted correctly to be understood by the receiving program!
    • This format can take a variety of forms, but often some dictionary will suffice, with certain keys defined
    payload = {"name": "Jed", "class": "CS151"}
    resp = requests.post(|||URL|||, json=payload)
  • You will still always get a response, but there might not be any content (or there might be!)

POST Demo

  • The JSONPlaceholder API can be used to test all manner of HTTP requests
  • For POST requests, we can send it any payload we want, and it will return the data back to us but with an ID added
    • The URL is: https://jsonplaceholder.typicode.com/posts
  • Technically this is simulating how we could add something like a post on a social media site
  • Note that this same URL can also be used with a GET request!

Your Turn!

  • Your attendance (and understanding check) for today is to send a very simple payload with only a “name” key (and your name as the corresponding value) to the URL that I’ll announce in class
  • Should get a 201 status code in return if your name has been recorded in today’s attendance!
  • Ask me if you are struggling!

Relation to NotOpenAI

  • The NotOpenAI library (and the analogous OpenAI library) handle some of this for you
  • When you use the library to send a prompt to ChatGPT, for instance, the library is making the POST request for you, and then you are getting back the parsed JSON response.
  • Note that you can get back a string of JSON as part of a response!
    • In this case, you need to use json.loads(|||str of json|||) to convert that string into a Python data structure that you can work easily with
// reveal.js plugins