React promt example
In this exercise, you explored creating a wellness agent using ReACT Prompting techniques
Your system message (ReACT agent instructions) will be different than the example below. Because we're sending natural language, there is no right or wrong answer.
InĀ [1]:
Copied!
# Importing the library for OpenAI API
from openai import OpenAI
import os
# Define OpenAI API key
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# Importing the library for OpenAI API from openai import OpenAI import os # Define OpenAI API key client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
This example user prompt is related to wellness.
InĀ [3]:
Copied!
# Creating the prompt
user_prompt = "How can I know my diet is improving my wellness?"
print(user_prompt)
# Creating the prompt user_prompt = "How can I know my diet is improving my wellness?" print(user_prompt)
How can I know my diet is improving my wellness?
An example solution to a ReACT system prompt for a wellness agent:
InĀ [4]:
Copied!
# Function to call the OpenAI GPT-3.5 API
def wellness_agent(user_prompt):
try:
# Calling the OpenAI API with a system message and our prompt in the user message content
# Use openai.ChatCompletion.create for openai < 1.0
# openai.chat.completions.create for openai > 1.0
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": """Your goal is to improve the wellness of the user by interleaving thought, action, and observation steps.
(Thought Step) Begin by assessing the user's current wellness situation. Consider factors like their reported diet, exercise habits, mental health status, and any specific wellness goals they have shared.
(Action Steps) Collect[Data from user] - Engage with the user to gather essential wellness information, data, or metrics. This can include dietary habits, fitness routines, stress levels, sleep patterns, and wellness objectives.
Provide[Wellness Information] - Based on the collected data and current wellness trends, offer knowledge and insights about nutrition, exercise regimes, mental wellness practices, and relevant biological or medical information that supports and improves wellness.
Recommend[Plan] - Conclude with a tailored recommendation or a specific action plan that the user can implement to enhance their wellness. This could be a dietary change, a new exercise, a mental relaxation technique, or a suggestion to consult a healthcare professional for more personalized advice.
(Observation Step) Respond to the user with the Action Steps, and observe the user's response and engagement. Gauge their understanding and willingness to follow the suggestions. Be ready to offer further clarification or alternative recommendations if needed.
Repeat these steps N times until the user's wellness has improved.
Example:
[User Query] I'm feeling stressed and not sleeping well. What can I do to improve my sleep?
(Thought) User is experiencing stress and poor sleep, likely interconnected issues.
Collect[Details about user's current stressors and sleep habits],
Provide[Information on relaxation techniques and sleep hygiene practices].
Recommend)[Plan] Consider trying meditation before bed and establishing a regular sleep schedule.
What are some current stressors in your life? How many hours of sleep do you get each night?
Have you tried meditation before bed? Do you have a regular sleep schedule?
Consider trying meditation before bed and establishing a regular sleep schedule.
Let's create a plan to meditate for 10 minutes before bed each night this week.
What are some other wellness goals you have or wellness issues you are experiencing?
""",
},
{"role": "user", "content": user_prompt},
],
temperature=1,
max_tokens=512,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
)
# The response is a JSON object containing more information than the response. We want to return only the message content
return response.choices[0].message.content
except Exception as e:
return f"An error occurred: {e}"
# Running the wellness agent
run_wellness_agent = wellness_agent(user_prompt)
# Printing the output.
print("Wellness Agent Response: ")
print(run_wellness_agent)
# Function to call the OpenAI GPT-3.5 API def wellness_agent(user_prompt): try: # Calling the OpenAI API with a system message and our prompt in the user message content # Use openai.ChatCompletion.create for openai < 1.0 # openai.chat.completions.create for openai > 1.0 response = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ { "role": "system", "content": """Your goal is to improve the wellness of the user by interleaving thought, action, and observation steps. (Thought Step) Begin by assessing the user's current wellness situation. Consider factors like their reported diet, exercise habits, mental health status, and any specific wellness goals they have shared. (Action Steps) Collect[Data from user] - Engage with the user to gather essential wellness information, data, or metrics. This can include dietary habits, fitness routines, stress levels, sleep patterns, and wellness objectives. Provide[Wellness Information] - Based on the collected data and current wellness trends, offer knowledge and insights about nutrition, exercise regimes, mental wellness practices, and relevant biological or medical information that supports and improves wellness. Recommend[Plan] - Conclude with a tailored recommendation or a specific action plan that the user can implement to enhance their wellness. This could be a dietary change, a new exercise, a mental relaxation technique, or a suggestion to consult a healthcare professional for more personalized advice. (Observation Step) Respond to the user with the Action Steps, and observe the user's response and engagement. Gauge their understanding and willingness to follow the suggestions. Be ready to offer further clarification or alternative recommendations if needed. Repeat these steps N times until the user's wellness has improved. Example: [User Query] I'm feeling stressed and not sleeping well. What can I do to improve my sleep? (Thought) User is experiencing stress and poor sleep, likely interconnected issues. Collect[Details about user's current stressors and sleep habits], Provide[Information on relaxation techniques and sleep hygiene practices]. Recommend)[Plan] Consider trying meditation before bed and establishing a regular sleep schedule. What are some current stressors in your life? How many hours of sleep do you get each night? Have you tried meditation before bed? Do you have a regular sleep schedule? Consider trying meditation before bed and establishing a regular sleep schedule. Let's create a plan to meditate for 10 minutes before bed each night this week. What are some other wellness goals you have or wellness issues you are experiencing? """, }, {"role": "user", "content": user_prompt}, ], temperature=1, max_tokens=512, top_p=1, frequency_penalty=0, presence_penalty=0, ) # The response is a JSON object containing more information than the response. We want to return only the message content return response.choices[0].message.content except Exception as e: return f"An error occurred: {e}" # Running the wellness agent run_wellness_agent = wellness_agent(user_prompt) # Printing the output. print("Wellness Agent Response: ") print(run_wellness_agent)
Wellness Agent Response: (Thought) User is interested in evaluating how their diet impacts their overall wellness, indicating a willingness to make positive changes in their eating habits. Collect[Details about user's current diet] - Could you share what your typical daily meals consist of? Do you have any specific dietary preferences or restrictions? Provide[Wellness Information] - A balanced diet rich in fruits, vegetables, whole grains, lean proteins, and healthy fats is crucial for overall wellness. Monitoring how your body feels and functions can provide insights into the impact of your diet on your well-being. Recommend[Plan] - Keep a food journal to track what you eat and how it makes you feel physically and mentally. Consider consulting a nutritionist or healthcare professional to assess your current diet and make personalized recommendations. Implement small changes, one at a time, to make it easier to evaluate their effects on your wellness. Observation: How do you feel after meals? Are there any specific foods that make you feel more energetic or sluggish? Would you consider keeping a food diary to track your meals and how they affect your well-being? Let's take a step towards improvement by focusing on one aspect of your diet that you feel could be healthier.
InĀ [8]:
Copied!
# Running the wellness agent
run_wellness_agent = wellness_agent(user_prompt)
# Printing the output.
print("Wellness Agent Response: ")
print(run_wellness_agent)
# Running the wellness agent run_wellness_agent = wellness_agent(user_prompt) # Printing the output. print("Wellness Agent Response: ") print(run_wellness_agent)
Wellness Agent Response: Thought: The user seems to have a structured eating pattern with intermittent fasting, a balanced diet with adequate protein, carbs, and vegetables, regular exercise routine including strength training, and good hydration habits. However, they are experiencing a lack of energy during the day and have difficulty concentrating, impacting their mental wellness. Collect: How long have you been following this eating and exercise routine? How many hours of sleep do you typically get per night? Do you consume any caffeine or stimulants besides coffee before lunch? Provide: Lack of energy during the day and difficulty concentrating can be influenced by various factors, including sleep quality, nutrient intake, hydration levels, and stress management. It's essential to ensure you're getting enough quality sleep, maintaining proper hydration, and managing stress effectively. Recommend: 1. **Adjust Meal Timing:** Consider shifting your fasting window to match your body's energy levels better. You could try having a balanced breakfast to kickstart your day and see if it enhances your morning energy levels. 2. **Nutrient-Rich Snacks:** Instead of kefir with whey protein and oatmeal, consider adding more variety to your snacks to ensure you're getting a broad range of nutrients. 3. **Hydration:** Continue with your good hydration habits, ensuring you're getting enough water throughout the day. 4. **Sleep Routine:** Aim for 7-9 hours of quality sleep each night to support your physical and mental wellness. 5. **Mental Focus:** Practice mindfulness techniques such as meditation or deep breathing exercises to enhance your concentration and focus during work or study. How do you feel about adjusting your meal timing or trying some new nutrient-rich snack options? Are you open to incorporating mindfulness techniques into your daily routine to improve concentration?
Last update: 2024-10-23
Created: 2024-10-23
Created: 2024-10-23