Using ChatGPT as a Well-Being Assistant.

In my late twenties, after detecting high cholesterol, I became more careful about my physical health. I joined a gym, started working out regularly, and eventually purchased my first sports watch. Being able to track progress and complete challenges took my fitness journey to a whole new level. Currently, I work out 5–6 times a week, engaging in activities like soccer, running, biking, and weightlifting.

Despite being active, I managed to gain weight and fall into the overweight range. Last year, I started using an app to log my calories and dropped 10 kg in just a few months. This experience confirmed the power of using technology to track progress and stay focused on health goals. I’ve also been tracking my blood pressure readings and attempting to keep a diary with emotion tags.

While tracking activities is easy with my watch and its accompanying app, logging calories, journal entries, and blood pressure requires manual input. This can be difficult and time-consuming, leading me to sometimes skip it when I’m busy.

With the advent of powerful Large Language Models like GPT-4/ChatGPT, automating some of these activities has become increasingly possible. I started using ChatGPT as a well-being assistant, providing it with information about my daily activities and meals. Here are the initial instructions I gave the assistant.

Instructions given to ChatGPT to turn it into my well-being assistant

After providing a description of my morning, the assistant quickly analyzed the data.

Logging my morning activities and meal

When I added a lunch entry, the assistant tried to repeat all the information from the morning. I stopped it and instructed it to just show the latest information.

And here is the output of only the latest entry.

As I continue logging information, I expect to be able to ask ChatGPT questions related to my health and how to improve it. For example, I’ve asked for dinner suggestions that won’t surpass my calorie goal.

The result was impressive (notice how it skipped the pizza and cakes lol). However, ChatGPT does not have infinite context, meaning it will eventually start forgetting the oldest information. This limitation prevents generating long-term reports and insights. I would also love to be able to keep older data to later ask questions that I haven’t thought about yet.

To overcome these limitations, I decided to use OpenAI’s API. I requested the assistant to provide output in JSON format, a data exchange language used to transmit and store data between computer systems.

Partial JSON output from the assistant

I played around with different formats for the data and then created Python code to call OpenAI’s API to obtain the JSON result.

import openai
import json

openai.api_key = "your-openai-key"

#model = "gpt-3.5-turbo"
model = "gpt-4"

def call_chatgpt(model, sentence):

    print("\nInput sentence:", sentence, "\n\n")
    task_in = "March 24, weight 72.95 bp 127/71 67 bpm, 25 km bike ride with moderate hills, breakfast 1 bowl of milk, one banana, 4 spoons of oat flakes. Super pumped right now with the news of OpenAI's release of the plugins, the only bad part is that it will be a bit stressful."
    task_out = '''[{"date":"03/24/2023","event":"weight","breakdown":{"weight":72.95}},
    {"date":"03/24/2023","event":"bp","breakdown":{"sys":127,"dia":71,"bpm":67}},
    {"date":"03/24/2023","workout":"cycling","breakdown":[{"item":"25 km bike ride with moderate hills","cals":643}]},
    {"date":"03/24/2023","meal":"breakfast","breakdown":[{"item":"1 bowl of milk","cals":100},
    {"item":"1 banana","cals":105},{"item":"4 spoons of oat flakes","cals":120}]},
    {"date":"03/24/2023","event":"journaling","breakdown":[{"item":"Super pumped right now with the news of OpenAI's release of the plugins","emotion":"positive"},
    {"item":"The only bad part is that it will be a bit stressful","emotion":"negative"}]}]'''

    task = "analyze text, estimate calories, return as json, example provided,  ---"

    prompt = task + " input: "+task_in + " output: " + task_out + " text: " + sentence
    print("Full prompt:",prompt)
    
    completion = openai.ChatCompletion.create(
    model=model,

    messages=[
          {"role": "system", "content": "you are to analyze text and return json based on examples"},
          {"role": "user", "content": prompt},  
      ]

    )

    output = completion["choices"][0]["message"]["content"]
    output = json.loads(output)

    json_formatted_str = json.dumps(output, indent=2)


    print("\n\n")
    print(json_formatted_str)

    return output 

sentence = "April 2, snack 3 taiwanese pork sausages with garlic. dinner 1 pork vietnamese banh mi, one small beer. 22 km bike ride in 49 mins. bp 130/69 60 bpm. So far enjoying the spring break"
call_chatgpt(model, sentence)
Calling the OpenAI API with my designed prompt
The JSON output

The code worked well, allowing me to save the output to a NoSQL database like MongoDB. With ChatGPT’s help, I created a simple web app as an interface for my well-being assistant.

Basic interface for my well-being assistant

The app calls OpenAI’s API, stores data in MongoDB, parses the result into human-readable text, and displays it on the interface. Later, I can use stored data to ask more powerful questions, like how my moods, activity levels, and blood pressure are related over the past two months. For now, I’m logging everything daily while considering advanced queries to create in the future.


Posted

in

by

Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: