Credits to Original Author: Andrew Zhu (andrz@seas.upenn.edu)
In this homework, we’ll use Kani to build a simple Game Master (GM) for the Mausritter TTRPG. Your GM will help walk you through creating a mouse and rolling dice to overcome challenges in the game. Along the way, you’ll learn the basics of the Kani library, function calling with LLMs, and how a LLM can use structured information to act as a game state manager.
We won’t implement more complex systems like combat or spellcasting in this homework, but extending this system to make a more comprehensive GM (e.g. adding inventory tracking, combat, spellcasting, structured tracking of NPCs, …) would make for a great class final project.
This assignment will have 3 main parts:
We have provided a Python Notebook for HW3. I recommend using Visual Studio Code
for this homework. You’ll be making changes to the hw3-aidm.ipynb
file. You should read through the whole Python Notebook
carefully, and add your code to all places marked TODO.
To run this code in your Python IDE, you’ll need to install a couple python packages via pip
, and you’ll need to set
the OPENAI_API_KEY
environment variable to your OpenAI API key.
First download the notebook, then create a virtual environment and install the dependencies. Here’s how I recommend that you set up your environment:
$ mkdir hw3
$ cd hw3
$ python3.10 -m venv venv
$ source venv/bin/activate
(venv) $ pip install jupyter 'kani[openai]' d20
If you’re using VS code then you can send your OPENAI_API_KEY to it when you launch it from the command line:
$ cd path/to/hw3
$ source venv/bin/activate
(venv) $ OPENAI_API_KEY=sk-helicone-XXXXXXX-XXXXXX code .
You should replace sk-helicone-XXXXXXX-XXXXXX
with your OpenAI API key which you can
find here.
Please submit the following:
hw3-aidm.ipynb
with all TODOs and free-response sections completedKani: A Lightweight and Highly Hackable Framework for Building Language Model Applications - Andrew Zhu, Liam Dugan, Alyssa Hwang, Chris Callison-Burch. NLP-OSS @ EMNLP 2024. |