TLDR; Summary
- AI can be used to provide personalized exercise experiences with Peloton.
- Building a working prototype is easy and cheap.
- Chain-of-though reasoning is a helpful technique.
Background
An AI use case that I've wanted to explore is how it can help reduce decision fatigue. A lot of services overwelm users with choices and burden the user with sifting through the content. I'd hardly call this a personal experience.
One place to apply this is with my Peloton workouts. When I log into the bike I'm faced with nearly twenty different options. What one is best for right now? They're all cycling classes should I even be doing a cycling class today? The other week I mentioned I needed to workout more. Eliminating decisions around what workout to do is one way to help reestablish a routine and keep workouts fresh, so I started building an AI system connected to my Peloton account to provide me with a workout of the day based on my personal fitness goal.
Results
All of the code and prompts are in this GitHub Repo if you want to follow along.
What I wanted to do is define a goal that's unique to me. Given the goal and my recent workouts I want GPT-4 to suggest a Peloton workout for me. For example, given the goal of:
I want to go from couch to 5k in the next month.
GPT-4 generates the following workout recommendation:
5 min Warm Up Run
15 min Hip Hop Run
The selected classes are designed to gradually increase the client's running capacity. The '5 min Warm Up Run' is a good start to prepare the body for the workout and prevent injuries. The '15 min Hip Hop Run' is a moderate-intensity run that will help the client build endurance and stamina, which are crucial for a 5k run. The total workout time is exactly 20 minutes, which aligns with the client's workout duration preference. The difficulty levels of the classes are also suitable for someone transitioning from a sedentary lifestyle to running a 5k.
Seems pretty reasonable! If I change my goal to be focused on building strength GPT-4 makes sure I'm not skipping leg day:
30 min Glutes & Legs Strength
The '30 min Glutes & Legs Strength' class is suggested as it aligns with the client's goal of building strength and muscle mass. This class focuses on lower body strength, which is part of the client's fitness goal. The difficulty level is high, which is suitable for muscle building. The duration of the class is exactly 30 minutes, which fits the client's workout duration preference. The client's recent workouts have been more focused on cardio and upper body strength, so this class will help balance their routine by focusing on lower body strength.
Challenges
There were a couple of challenges. First, I needed to get my recent workouts and available classes from the Peloton API. The peloton.py
file contains a class that handles this.
Next, I had to write the prompts. The prompts.py
file contains the templates for the different prompts I used. A system prompt instructs the model about the user's fitness goal and provides information about class difficulties. Data from the API is then inserted into the prompts.
I split up the workout recommendation class into two parts:
- What type of workout should the user do (i.e. cycling, strength, running etc.)?
- What classes should be included in the workout?
Using this chain-of-thought reasoning simplifies the code a bit. Instead of stuffing the class prompt with hundreds of classes from different disciplines only the classes for the discipline chosen by the model are included in the prompt reducing its size and cost.
An ongoing challenge has been forcing the model to not build a workout that exceeds the user's time limit. The model periodically constructs a longer workout and acknowledges it has done so and will provide an explanation for why it's over the time limit. Almost like it's purposely exceeding the limit.
Finally, there are a couple issues with the Streamlit flow I had to work through related to having nested buttons.
Wrapping Up.
I've been using these workout suggestions for about a week and have been pleased with the results. One takeaway was how quickly I could stand up this project. A few hours of effort and I had a workout prototype that cost me the equivalent of a good cup of coffee.
There are still some bugs I'm working through, but it's still fun to use. Let me know what you think over at the GitHub Repo and feel free to add your own goals to the project!
/October 29, 2023