Open Ai¶
In this jupyter notebook I will make a connection with the openAi platform of Azure
In [0]:
import os
from openai import AzureOpenAI
from dotenv import load_dotenv
load_dotenv()
client = AzureOpenAI(
azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"],
api_key=os.environ["OPENAI_API_KEY_AZURE"],
api_version = "2023-10-01-preview"
)
print(client)
model = "gpt35turbo16k"
# Define your prompt and messages
prompt = "Complete the following: Once upon a time there was a"
messages = [{"role": "user", "content": prompt}]
# Make the completion request
completion = client.chat.completions.create(model=model, messages=messages, max_tokens=100)
<openai.lib.azure.AzureOpenAI object at 0x000001C65F345F70>
ChatCompletion(id='chatcmpl-9t3zLFwHOWNmz5EPszYTG8ZXxveru', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content="beautiful princess named. She had long, flowing golden hair and eyes as blue as the ocean. Her name was Princess Isabella. Despite her mesmerizing beauty, Princess Isabella was known for her kindness and compassion towards everyone in her kingdom. She would spend her days helping the needy, visiting the sick, and making sure the villagers were taken care of.\n\nOne fateful day, a wicked sorceress named Morgana heard about Princess Isabella's remarkable traits. Morgana was envious of the princess and wanted to steal her beauty and power for herself. She devised a plan to kidnap Isabella and lock her away in a hidden tower.\n\nAs the sun set over the kingdom, Morgana's minions captured Princess Isabella while she was strolling through the palace gardens. They blindfolded her and whisked her away to the secret tower deep within the enchanted forest.\n\nDays turned into weeks, and weeks turned into months as Princess Isabella languished in her lonely prison. She missed her beloved kingdom and the people she cherished. Determined to escape and save her kingdom from Morgana's clutches, Isabella's spirit never faltered. \n\nOne moonlit night, while gazing up at the starry sky, Isabella discovered a tiny feathered creature peering in through the window. It was a magical bird known as a phoenix. With its all-knowing eyes, the phoenix understood her plight and vowed to help her escape.\n\nUsing its mystical powers, the phoenix opened the locked door of the tower. Princess Isabella cautiously stepped out into the night, her heart pounding with hope and determination. Together, they embarked on a treacherous journey through the dark and enchanted forest, evading Morgana's minions at every turn.\n\nThroughout their incredible adventure, Princess Isabella encountered mythical creatures who aided her and bestowed upon her special gifts. A wise old tree shared its wisdom, a river nymph granted her the ability to communicate with animals, and a gentle unicorn offered her protection. With each encounter, Princess Isabella grew stronger.\n\nFinally, after months of tireless efforts and endless battles, they reached the castle where Morgana resided. With the help of her newfound friends and her own bravery, Princess Isabella confronted Morgana and reclaimed her beauty and power.\n\nThe kingdom rejoiced as their beloved princess returned, bringing back peace and harmony. Isabella learned the true depth of her strength and the importance of never underestimating one's inner power. From that day forward, Princess Isabella ruled her kingdom with fairness and compassion, ensuring that her people always lived happily ever after.", role='assistant', function_call=None, tool_calls=None), content_filter_results={'hate': {'filtered': False, 'severity': 'safe'}, 'protected_material_code': {'filtered': False, 'detected': False}, 'protected_material_text': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'low'}})], created=1722910399, model='gpt-35-turbo-16k', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=521, prompt_tokens=18, total_tokens=539), prompt_filter_results=[{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}])
In [0]:
# Print the response
print(len(completion.choices[0].message.content))
print(completion.choices[0].message.content)
2634 beautiful princess named. She had long, flowing golden hair and eyes as blue as the ocean. Her name was Princess Isabella. Despite her mesmerizing beauty, Princess Isabella was known for her kindness and compassion towards everyone in her kingdom. She would spend her days helping the needy, visiting the sick, and making sure the villagers were taken care of. One fateful day, a wicked sorceress named Morgana heard about Princess Isabella's remarkable traits. Morgana was envious of the princess and wanted to steal her beauty and power for herself. She devised a plan to kidnap Isabella and lock her away in a hidden tower. As the sun set over the kingdom, Morgana's minions captured Princess Isabella while she was strolling through the palace gardens. They blindfolded her and whisked her away to the secret tower deep within the enchanted forest. Days turned into weeks, and weeks turned into months as Princess Isabella languished in her lonely prison. She missed her beloved kingdom and the people she cherished. Determined to escape and save her kingdom from Morgana's clutches, Isabella's spirit never faltered. One moonlit night, while gazing up at the starry sky, Isabella discovered a tiny feathered creature peering in through the window. It was a magical bird known as a phoenix. With its all-knowing eyes, the phoenix understood her plight and vowed to help her escape. Using its mystical powers, the phoenix opened the locked door of the tower. Princess Isabella cautiously stepped out into the night, her heart pounding with hope and determination. Together, they embarked on a treacherous journey through the dark and enchanted forest, evading Morgana's minions at every turn. Throughout their incredible adventure, Princess Isabella encountered mythical creatures who aided her and bestowed upon her special gifts. A wise old tree shared its wisdom, a river nymph granted her the ability to communicate with animals, and a gentle unicorn offered her protection. With each encounter, Princess Isabella grew stronger. Finally, after months of tireless efforts and endless battles, they reached the castle where Morgana resided. With the help of her newfound friends and her own bravery, Princess Isabella confronted Morgana and reclaimed her beauty and power. The kingdom rejoiced as their beloved princess returned, bringing back peace and harmony. Isabella learned the true depth of her strength and the importance of never underestimating one's inner power. From that day forward, Princess Isabella ruled her kingdom with fairness and compassion, ensuring that her people always lived happily ever after.
In [0]:
prompt = "Create a training program for a 5k run that spans over three weeks"
messages = [{"role": "user", "content": prompt}]
# Make the completion request
completion = client.chat.completions.create(model=model, messages=messages, max_tokens=100)
In [0]:
print(completion)
ChatCompletion(id='chatcmpl-9tSRLOcYdYdSlJte7prVBMNlyph2U', choices=[Choice(finish_reason='length', index=0, logprobs=None, message=ChatCompletionMessage(content='Week 1:\n- Day 1: Start with a 1-mile run at an easy pace.\n- Day 2: Rest day or cross-training activity like swimming or cycling for 30 minutes.\n- Day 3: Do a 2-mile run at a comfortable pace, focusing on maintaining a steady rhythm.\n- Day 4: Rest day or cross-training activity.\n- Day 5: Complete a 1.5-mile run, attempting to slightly increase your speed compared to previous runs', role='assistant', function_call=None, tool_calls=None), content_filter_results={'hate': {'filtered': False, 'severity': 'safe'}, 'protected_material_code': {'filtered': False, 'detected': False}, 'protected_material_text': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}})], created=1723004391, model='gpt-35-turbo-16k', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=100, prompt_tokens=22, total_tokens=122), prompt_filter_results=[{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}])
Now start working with functions to make it more static.
In [0]:
functions = [
{
"name":"create_training_program",
"description":"Creates a training program that for the user",
"parameters":{
"type":"object",
"properties":{
"exercise_type":{
"type":"string",
"description":"This is the type of exercise (e.g. running, swimming, cycling, body building, lifting weights)"
},
"program_length":{
"type":"string",
"description":"This is the length of the training program (e.g. a week, a day, a month, 2 weeks)"
},
"exercise_level":{
"type":"string",
"description":"This is the target of the training (e.g. 5km, 2 miles, 10kg, 20 reps)"
}
},
"required":[
"exercise_level",
"program_length",
"exercise_type"
]
}
}
]
In [0]:
# Define the prompt
prompt = "Create a training program for a 5k run that spans over three weeks"
messages = [{"role": "user", "content": prompt}]
completion = client.chat.completions.create(
model=model,
messages=messages,
functions=functions,
function_call="auto",
max_tokens=100
)
print(completion)
ChatCompletion(id='chatcmpl-9tTbPVO6PBgOyKetcEigWsmWcAEnU', choices=[Choice(finish_reason='function_call', index=0, logprobs=None, message=ChatCompletionMessage(content=None, role='assistant', function_call=FunctionCall(arguments='{\n "exercise_type": "running",\n "program_length": "3 weeks",\n "exercise_level": "5k"\n}', name='create_training_program'), tool_calls=None), content_filter_results={})], created=1723008859, model='gpt-35-turbo-16k', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=35, prompt_tokens=152, total_tokens=187), prompt_filter_results=[{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}])
In [0]:
import json
function_args = json.loads(completion.choices[0].message.function_call.arguments)
print(function_args)
response_prompt = f""" Create a training program for {function_args["exercise_type"]} that spans over {function_args["program_length"]} targeting {function_args["exercise_level"]}.
Provide the answer in a JSON structure with the following format:
"General":
"Instructions": "General instructions",
"WarmUpCooldownSuggestions": "Warm up and cooldown suggestions"
,
"majorDurations":
[
"DescriptionMajorDuration": "Name duration (e.g. day, week, month, year)
"minorDurations": [
"DescriptionMinorDuration": "Name duration (e.g. min, day, week, month)
"LengthExercise": "Length of exercise in min",
"ExerciseDescription": "Description of exercise"
"Specificattention": "Warning for any injuries"
]
]
"""
print(response_prompt)
{'exercise_type': 'running', 'program_length': '3 weeks', 'exercise_level': '5k'}
Create a training program for running that spans over 3 weeks targeting 5k.
Provide the answer in a JSON structure with the following format:
"General":
"Instructions": "General instructions",
"WarmUpCooldownSuggestions": "Warm up and cooldown suggestions"
,
"majorDurations":
[
"DescriptionMajorDuration": "Name duration (e.g. day, week, month, year)
"minorDurations": [
"DescriptionMinorDuration": "Name duration (e.g. min, day, week, month)
"LengthExercise": "Length of exercise in min",
"ExerciseDescription": "Description of exercise"
"Specificattention": "Warning for any injuries"
]
]
In [0]:
response_messages = [{"role": "user", "content": response_prompt}]
response = client.chat.completions.create(model=model, messages=response_messages, max_tokens=1000)
print(response)
ChatCompletion(id='chatcmpl-9tllQ7HaM7OyjaSl5QiOB5xYscbUf', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='{\n"General": {\n "Instructions": "Gradually increase the distance and intensity of your runs over the 3-week training period. Make sure to listen to your body and rest if needed.",\n "WarmUpCooldownSuggestions": "Before each run, warm up with 5-10 minutes of light jogging or dynamic stretches. After each run, cool down with 5-10 minutes of walking or static stretches."\n},\n"majorDurations": [\n {\n "DescriptionMajorDuration": "Week 1",\n "minorDurations": [\n {\n "DescriptionMinorDuration": "Day 1",\n "LengthExercise": "20",\n "ExerciseDescription": "Brisk walk for 10 minutes, then alternate between running for 1 minute and walking for 1.5 minutes for a total of 20 minutes.",\n "Specificattention": ""\n },\n {\n "DescriptionMinorDuration": "Day 2",\n "LengthExercise": "25",\n "ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 20 minutes.",\n "Specificattention": ""\n },\n {\n "DescriptionMinorDuration": "Day 3",\n "LengthExercise": "30",\n "ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 25 minutes.",\n "Specificattention": ""\n }\n ]\n },\n {\n "DescriptionMajorDuration": "Week 2",\n "minorDurations": [\n {\n "DescriptionMinorDuration": "Day 1",\n "LengthExercise": "35",\n "ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 30 minutes.",\n "Specificattention": ""\n },\n {\n "DescriptionMinorDuration": "Day 2",\n "LengthExercise": "40",\n "ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 35 minutes.",\n "Specificattention": ""\n },\n {\n "DescriptionMinorDuration": "Day 3",\n "LengthExercise": "45",\n "ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 40 minutes.",\n "Specificattention": ""\n }\n ]\n },\n {\n "DescriptionMajorDuration": "Week 3",\n "minorDurations": [\n {\n "DescriptionMinorDuration": "Day 1",\n "LengthExercise": "50",\n "ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 45 minutes.",\n "Specificattention": ""\n },\n {\n "DescriptionMinorDuration": "Day 2",\n "LengthExercise": "55",\n "ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 50 minutes.",\n "Specificattention": ""\n },\n {\n "DescriptionMinorDuration": "Day 3",\n "LengthExercise": "60",\n "ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 55 minutes.",\n "Specificattention": ""\n }\n ]\n }\n]\n}\n', role='assistant', function_call=None, tool_calls=None), content_filter_results={'hate': {'filtered': False, 'severity': 'safe'}, 'protected_material_code': {'filtered': False, 'detected': False}, 'protected_material_text': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}})], created=1723078672, model='gpt-35-turbo-16k', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=665, prompt_tokens=159, total_tokens=824), prompt_filter_results=[{'prompt_index': 0, 'content_filter_results': {'hate': {'filtered': False, 'severity': 'safe'}, 'jailbreak': {'filtered': False, 'detected': False}, 'self_harm': {'filtered': False, 'severity': 'safe'}, 'sexual': {'filtered': False, 'severity': 'safe'}, 'violence': {'filtered': False, 'severity': 'safe'}}}])
In [0]:
print(response.choices[0].message.content)
{
"General": {
"Instructions": "Gradually increase the distance and intensity of your runs over the 3-week training period. Make sure to listen to your body and rest if needed.",
"WarmUpCooldownSuggestions": "Before each run, warm up with 5-10 minutes of light jogging or dynamic stretches. After each run, cool down with 5-10 minutes of walking or static stretches."
},
"majorDurations": [
{
"DescriptionMajorDuration": "Week 1",
"minorDurations": [
{
"DescriptionMinorDuration": "Day 1",
"LengthExercise": "20",
"ExerciseDescription": "Brisk walk for 10 minutes, then alternate between running for 1 minute and walking for 1.5 minutes for a total of 20 minutes.",
"Specificattention": ""
},
{
"DescriptionMinorDuration": "Day 2",
"LengthExercise": "25",
"ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 20 minutes.",
"Specificattention": ""
},
{
"DescriptionMinorDuration": "Day 3",
"LengthExercise": "30",
"ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 25 minutes.",
"Specificattention": ""
}
]
},
{
"DescriptionMajorDuration": "Week 2",
"minorDurations": [
{
"DescriptionMinorDuration": "Day 1",
"LengthExercise": "35",
"ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 30 minutes.",
"Specificattention": ""
},
{
"DescriptionMinorDuration": "Day 2",
"LengthExercise": "40",
"ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 35 minutes.",
"Specificattention": ""
},
{
"DescriptionMinorDuration": "Day 3",
"LengthExercise": "45",
"ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 40 minutes.",
"Specificattention": ""
}
]
},
{
"DescriptionMajorDuration": "Week 3",
"minorDurations": [
{
"DescriptionMinorDuration": "Day 1",
"LengthExercise": "50",
"ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 45 minutes.",
"Specificattention": ""
},
{
"DescriptionMinorDuration": "Day 2",
"LengthExercise": "55",
"ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 50 minutes.",
"Specificattention": ""
},
{
"DescriptionMinorDuration": "Day 3",
"LengthExercise": "60",
"ExerciseDescription": "Brisk walk for 5 minutes, then run at a comfortable pace for 55 minutes.",
"Specificattention": ""
}
]
}
]
}
{'General': {'Instructions': 'Gradually increase the distance and intensity of your runs over the 3-week training period. Make sure to listen to your body and rest if needed.', 'WarmUpCooldownSuggestions': 'Before each run, warm up with 5-10 minutes of light jogging or dynamic stretches. After each run, cool down with 5-10 minutes of walking or static stretches.'}, 'majorDurations': [{'DescriptionMajorDuration': 'Week 1', 'minorDurations': [{'DescriptionMinorDuration': 'Day 1', 'LengthExercise': '20', 'ExerciseDescription': 'Brisk walk for 10 minutes, then alternate between running for 1 minute and walking for 1.5 minutes for a total of 20 minutes.', 'Specificattention': ''}, {'DescriptionMinorDuration': 'Day 2', 'LengthExercise': '25', 'ExerciseDescription': 'Brisk walk for 5 minutes, then run at a comfortable pace for 20 minutes.', 'Specificattention': ''}, {'DescriptionMinorDuration': 'Day 3', 'LengthExercise': '30', 'ExerciseDescription': 'Brisk walk for 5 minutes, then run at a comfortable pace for 25 minutes.', 'Specificattention': ''}]}, {'DescriptionMajorDuration': 'Week 2', 'minorDurations': [{'DescriptionMinorDuration': 'Day 1', 'LengthExercise': '35', 'ExerciseDescription': 'Brisk walk for 5 minutes, then run at a comfortable pace for 30 minutes.', 'Specificattention': ''}, {'DescriptionMinorDuration': 'Day 2', 'LengthExercise': '40', 'ExerciseDescription': 'Brisk walk for 5 minutes, then run at a comfortable pace for 35 minutes.', 'Specificattention': ''}, {'DescriptionMinorDuration': 'Day 3', 'LengthExercise': '45', 'ExerciseDescription': 'Brisk walk for 5 minutes, then run at a comfortable pace for 40 minutes.', 'Specificattention': ''}]}, {'DescriptionMajorDuration': 'Week 3', 'minorDurations': [{'DescriptionMinorDuration': 'Day 1', 'LengthExercise': '50', 'ExerciseDescription': 'Brisk walk for 5 minutes, then run at a comfortable pace for 45 minutes.', 'Specificattention': ''}, {'DescriptionMinorDuration': 'Day 2', 'LengthExercise': '55', 'ExerciseDescription': 'Brisk walk for 5 minutes, then run at a comfortable pace for 50 minutes.', 'Specificattention': ''}, {'DescriptionMinorDuration': 'Day 3', 'LengthExercise': '60', 'ExerciseDescription': 'Brisk walk for 5 minutes, then run at a comfortable pace for 55 minutes.', 'Specificattention': ''}]}]}
In [0]:
from pydantic import BaseModel, Field
from typing import Union, Optional, List
from openai import OpenAI
import json
import os
load_dotenv()
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
# Define the structure for minor durations
class MinorDuration(BaseModel):
description_minor_duration: str = Field(..., description="e.g. min 10, 20, 30, day 1, 2, 3, week 1, 2, 3, month.")
length_exercise: Union[str, int] = Field(..., description="The length of the exercise in minutes")
exercise_description: str = Field(..., description="Explains what exercise to do and how to do it. 3 to 5 exercises.")
specific_attention: Optional[str] = Field(None, description="Optional: Safety warning to prevent any injuries")
# Define the structure for major durations
class MajorDuration(BaseModel):
description_major_duration: str = Field(..., description="e.g. day 1, 2, 3, week 1, 2, 3, month, year. They should always be larger than a minorduration, but similar sequentially. Year > Month > Week > Day.")
minor_durations: list[MinorDuration] = Field(..., description="The minor duration should be smaller than major duration, so if week is a majorduration, it should be day 1, 2, 3, 4 etc. Focus on 3 to 5 Minordurations within a majorduration")
# Define the structure for the general instructions
class General(BaseModel):
instructions: str = Field(..., description="General instructions, keep it short")
warm_up_cooldown_suggestions: str = Field(..., description="Warm up and cooldown suggestions")
# Define the full structure for the training program
class TrainingProgram(BaseModel):
general: General
major_durations: list[MajorDuration] = Field(..., description="Focus on 2-3 majorduration, unless it is specified.")
# Function to call the OpenAI API
response = client.beta.chat.completions.parse(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a personal trainer (PT) that sets up a training program. Split the training in multiple durations."},
{"role": "user", "content": "Create a running program of 5 weeks"}
],
temperature=0,
max_tokens=1000,
response_format=TrainingProgram,
)
print(json.loads(response.choices[0].message.content))
{'general': {'instructions': 'Follow the schedule, gradually increasing your running distance and intensity.', 'warm_up_cooldown_suggestions': 'Always start with a 5-10 minute warm-up (walking or light jogging) and end with a cooldown (stretching).'}, 'major_durations': [{'description_major_duration': 'Week 1', 'minor_durations': [{'description_minor_duration': 'Day 1', 'length_exercise': 30, 'exercise_description': 'Run for 20 minutes at a comfortable pace, followed by a 10-minute walk.', 'specific_attention': 'Stay hydrated and listen to your body.'}, {'description_minor_duration': 'Day 3', 'length_exercise': 30, 'exercise_description': 'Run for 25 minutes at a comfortable pace, followed by a 5-minute walk.', 'specific_attention': 'Focus on maintaining a steady pace.'}, {'description_minor_duration': 'Day 5', 'length_exercise': 30, 'exercise_description': 'Run for 20 minutes, then do 5 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.', 'specific_attention': 'Ensure proper form during sprints.'}]}, {'description_major_duration': 'Week 2', 'minor_durations': [{'description_minor_duration': 'Day 1', 'length_exercise': 30, 'exercise_description': 'Run for 25 minutes at a comfortable pace, followed by a 5-minute walk.', 'specific_attention': 'Increase your pace slightly.'}, {'description_minor_duration': 'Day 3', 'length_exercise': 30, 'exercise_description': 'Run for 30 minutes at a comfortable pace.', 'specific_attention': 'Maintain a steady breathing pattern.'}, {'description_minor_duration': 'Day 5', 'length_exercise': 30, 'exercise_description': 'Run for 20 minutes, then do 10 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.', 'specific_attention': 'Warm up properly before intervals.'}]}, {'description_major_duration': 'Week 3', 'minor_durations': [{'description_minor_duration': 'Day 1', 'length_exercise': 30, 'exercise_description': 'Run for 30 minutes at a comfortable pace.', 'specific_attention': 'Focus on your running form.'}, {'description_minor_duration': 'Day 3', 'length_exercise': 30, 'exercise_description': 'Run for 35 minutes at a comfortable pace.', 'specific_attention': 'Stay hydrated.'}, {'description_minor_duration': 'Day 5', 'length_exercise': 30, 'exercise_description': 'Run for 25 minutes, then do 10 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.', 'specific_attention': 'Cool down properly after sprints.'}]}, {'description_major_duration': 'Week 4', 'minor_durations': [{'description_minor_duration': 'Day 1', 'length_exercise': 30, 'exercise_description': 'Run for 35 minutes at a comfortable pace.', 'specific_attention': 'Monitor your heart rate.'}, {'description_minor_duration': 'Day 3', 'length_exercise': 30, 'exercise_description': 'Run for 40 minutes at a comfortable pace.', 'specific_attention': 'Focus on your breathing.'}, {'description_minor_duration': 'Day 5', 'length_exercise': 30, 'exercise_description': 'Run for 30 minutes, then do 10 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.', 'specific_attention': 'Ensure you are well-rested before this session.'}]}, {'description_major_duration': 'Week 5', 'minor_durations': [{'description_minor_duration': 'Day 1', 'length_exercise': 30, 'exercise_description': 'Run for 40 minutes at a comfortable pace.', 'specific_attention': 'Keep a steady pace throughout.'}, {'description_minor_duration': 'Day 3', 'length_exercise': 30, 'exercise_description': 'Run for 45 minutes at a comfortable pace.', 'specific_attention': 'Stay focused on your form.'}, {'description_minor_duration': 'Day 5', 'length_exercise': 30, 'exercise_description': 'Run for 30 minutes, then do 15 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.', 'specific_attention': 'Cool down and stretch after the workout.'}]}]}
In [0]:
pretty = json.loads(response.choices[0].message.content)
print(json.dumps(pretty, indent=4))
{
"general": {
"instructions": "Follow the schedule, gradually increasing your running distance and intensity.",
"warm_up_cooldown_suggestions": "Always start with a 5-10 minute warm-up (walking or light jogging) and end with a cooldown (stretching)."
},
"major_durations": [
{
"description_major_duration": "Week 1",
"minor_durations": [
{
"description_minor_duration": "Day 1",
"length_exercise": 30,
"exercise_description": "Run for 20 minutes at a comfortable pace, followed by a 10-minute walk.",
"specific_attention": "Stay hydrated and listen to your body."
},
{
"description_minor_duration": "Day 3",
"length_exercise": 30,
"exercise_description": "Run for 25 minutes at a comfortable pace, followed by a 5-minute walk.",
"specific_attention": "Focus on maintaining a steady pace."
},
{
"description_minor_duration": "Day 5",
"length_exercise": 30,
"exercise_description": "Run for 20 minutes, then do 5 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.",
"specific_attention": "Ensure proper form during sprints."
}
]
},
{
"description_major_duration": "Week 2",
"minor_durations": [
{
"description_minor_duration": "Day 1",
"length_exercise": 30,
"exercise_description": "Run for 25 minutes at a comfortable pace, followed by a 5-minute walk.",
"specific_attention": "Increase your pace slightly."
},
{
"description_minor_duration": "Day 3",
"length_exercise": 30,
"exercise_description": "Run for 30 minutes at a comfortable pace.",
"specific_attention": "Maintain a steady breathing pattern."
},
{
"description_minor_duration": "Day 5",
"length_exercise": 30,
"exercise_description": "Run for 20 minutes, then do 10 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.",
"specific_attention": "Warm up properly before intervals."
}
]
},
{
"description_major_duration": "Week 3",
"minor_durations": [
{
"description_minor_duration": "Day 1",
"length_exercise": 30,
"exercise_description": "Run for 30 minutes at a comfortable pace.",
"specific_attention": "Focus on your running form."
},
{
"description_minor_duration": "Day 3",
"length_exercise": 30,
"exercise_description": "Run for 35 minutes at a comfortable pace.",
"specific_attention": "Stay hydrated."
},
{
"description_minor_duration": "Day 5",
"length_exercise": 30,
"exercise_description": "Run for 25 minutes, then do 10 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.",
"specific_attention": "Cool down properly after sprints."
}
]
},
{
"description_major_duration": "Week 4",
"minor_durations": [
{
"description_minor_duration": "Day 1",
"length_exercise": 30,
"exercise_description": "Run for 35 minutes at a comfortable pace.",
"specific_attention": "Monitor your heart rate."
},
{
"description_minor_duration": "Day 3",
"length_exercise": 30,
"exercise_description": "Run for 40 minutes at a comfortable pace.",
"specific_attention": "Focus on your breathing."
},
{
"description_minor_duration": "Day 5",
"length_exercise": 30,
"exercise_description": "Run for 30 minutes, then do 10 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.",
"specific_attention": "Ensure you are well-rested before this session."
}
]
},
{
"description_major_duration": "Week 5",
"minor_durations": [
{
"description_minor_duration": "Day 1",
"length_exercise": 30,
"exercise_description": "Run for 40 minutes at a comfortable pace.",
"specific_attention": "Keep a steady pace throughout."
},
{
"description_minor_duration": "Day 3",
"length_exercise": 30,
"exercise_description": "Run for 45 minutes at a comfortable pace.",
"specific_attention": "Stay focused on your form."
},
{
"description_minor_duration": "Day 5",
"length_exercise": 30,
"exercise_description": "Run for 30 minutes, then do 15 minutes of interval sprints (30 seconds fast, 1 minute slow), followed by a 5-minute walk.",
"specific_attention": "Cool down and stretch after the workout."
}
]
}
]
}