Reputation: 66
I have done a python program using the openai.ChatCompletion.create
to interface to the ChatGPT API.
I am using a messages
with two roles: user
with the user prompt as content
, and assistant
loaded with current sensor data as content
, which I get from a set of sensors using MQTT. The sensor data is original JSON, but I formatted it like this:
Temperature: 22.07 ºC
Humidity: 62.64 %RH
TVOC: 0 ppb
CO2: 400 ppm
PM1: 0 µg/m3
PM2.5: 0 µg/m3
PM10: 1 µg/m3
My idea is to use a clear language to ask What is the temperature?
and What is the dew point?
and expect ChatGPT to just give me the first and calculate the second based on the temperature and humidity available in the data.
I don't want to train a model, since the data changes constantly.
Is there a way to feed sensor data to ChatGPT API?
(I have also tried with role system
, btw)
Upvotes: 0
Views: 435
Reputation: 66
Ok, so I managed to figure it out with some trial and error:
My API call look like this:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=0.6,
messages=[
{
"role": "system",
"content": "You are a helful assistant that helps with sensor data as provided (temperatures all in ºC, humidity in %RH, light in lux and cloud base in meters). You can assist with calculating other values based on the sensor data. You can put the sensor data into context.",
},
{"role": "user", "content": prompt},
{"role": "assistant", "content": sensor_data},
],
)
The prompt
is from HTML input, such as "Is it dry?"
The sensor_data
is a text string with the data in a flat format like this:
Temperature: 15.21
Humidity: 82.97
Dew Point: 12.34
Heat Index: 14.96
Wet-Bulb Temperature: 13.27
Cloud Base: 350.38
Cloud Temperature: 11.77
Ambient Light: 30
UV Index: 0.02
The response to the above question looked like this:
Based on the provided data, the humidity is relatively high at 82.97%RH, which suggests that the air contains a significant amount of moisture. However, without additional information, it is difficult to determine if the conditions are considered dry.
The sensor_data
variable is updated every 5 seconds from a MQTT server, but that could be from anywhere.
Upvotes: 0