Section 1: Your First Queries - calisley/dpi-681 GitHub Wiki
Part 1: ChatGPT Clone
Open VSCode and the chat.py file
If you've properly completed the setup from Section 0, you should have a folder called section-1 in your DPI-681/dpi-681 folder. Find that folder, and open the chat.py file in your code editor. You can do this a few ways, including:
- Using VSCode:
-
Option 1: Open VSCode, select "Open Folder" and find
DPI-681/dpi-681/section-1. Click onchat.pyand it will open. -
Option 2: Alternatively, open your file explorer (Finder on Mac or File Explorer on Windows), locate the
chat.pyfile, right-click it, and select "Open with Visual Studio Code" (or your preferred code editor). -
Option 3 (stylish, but no real benefit): In your terminal (from the root directory of the cloned repo), run:
code .And similarly click on
chat.pyin VSCode's file explorer.
-
Note: This script far more complicated than what we'll be normally doing. I'm just using it as an illustrative exercise. If you would like to understand more about what's going on, don't hesitate to reach out.
Add Your API Key
Within chat.py, find line 11, where it says
# Explicitly set your OpenAI API key here:
OPENAI_API_KEY = "" # Replace with your actual API key
Replace the placeholder text with your actual OpenAI API key (the one you generated in Section 0) and save the file. If you lost it, refer back to Section 0 Step 4.
Talk to ChatGPT from the Command Line.
Open up terminal or powershell, ensure you're in the directory where chat.py is located. This should be DPI-681/dpi-681/section-1/. As a reminder, to get there, run
- On Mac/Linux:
cd ~/DPI-681/dpi-681/section-1 - On Windows:
cd C:\DPI-681\dpi-681\section-1
And then finally run the script:
- For Mac/Linux:
python3 chat.py
-
For Windows:
python chat.py
If everything is set up correctly, you should now be interacting with ChatGPT through your terminal!
(Optional) Tweak the system prompt
On line 13 you should see a variable called SYSTEM_PROMPT with a string next to it, telling the model what to do. Feel free to play around with these instructions and see what you find!
Part 2: Vibe-Coding Challenge
In this exercise, you will use generative AI to create and expand code for a policy application. Building on the code provided in example.py, you are encouraged to leverage AI-generated code as a starting point and extend it to address a policy issue of interest. This activity is designed to give you practical, hands-on experience with coding and API interaction.
Objectives
- Utilize Generative AI:
Use a generative AI tool to help generate code snippets and ideas. - Extend the Base Code:
Expand the provided example beyond generating a simple haiku. - Extend and Apply to Policy Applications:
Adapt the generated content to explore topics such as policy memos, summaries, debates, or narratives.
Instructions
- Use Generative AI as Your Primary Coder:
Use your favorite LLM for assistance in generating new code or expanding on the provided example. If you don't understand the Python code that is being generated that's okay! (for now.) The goal is not to understand everything but to get experience using Generative AI to code. - Expand and Modify:
Enhance the code to add features or alter functionality to better address a policy issue of your choice. - Experiment:
There is no single correct solution. The focus is on exploring creative ways to use AI-generated code for policy applications. - Timeframe:
We will work on this until there are about 5-10 minutes left in section. Please be ready to share what you came up with!
Suggested Starting Points
-
Policy-Themed Haiku or Poem Generator: (easy)
Modify the prompt to generate a haiku, poem, or short narrative about a specific policy issue (e.g., climate change, public health, housing policy).messages=[{ "role": "user", "content": "Write a haiku about the challenges of urban housing policy." }] -
Policy Summary Bot: (medium)
Create a tool that takes a policy text or issue and generates a concise summary or creative policy recommendation. Your prompt might look like this:messages=[{ "role": "user", "content": "Summarize the main policy challenges in affordable housing and suggest a creative solution." }]But think about how you might feed the document you want to analyze into the model. Maybe multiple documents?
-
Interactive Issue of Interest Chat: (hard)
Develop a command-line interface that accepts a policy issue from the user and returns a creative narrative or analysis. (HINT: You may want to steal some code fromchat.py).user_input = input("Enter a policy issue of interest: ") completion = client.chat.completions.create( model="gpt-4o", messages=[{ "role": "user", "content": f"Discuss the policy implications of {user_input} in a creative and engaging manner." }] ) print(completion.choices[0].message.content) -
Debate Simulator: (ranges from easy to hard)
Use the AI to simulate a brief debate by generating arguments both for and against a specific policy.messages=[ {"role": "user", "content": "Provide one argument in favor of and one argument against universal basic income."} ]To expand this you set up two different agents, each with their own set of "opinions" or "beliefs" and pit them against each other in a debate. Further, you could have another bot then analyze the text to see who is more convincing, and why!
Reporting
At the end of the session, we will reconvene to discuss your approaches and share insights. Be prepared to briefly explain your application, the policy issue you addressed, and any interesting challenges or discoveries.
Happy coding!