openai-api - OpenAI ChatGPT API - 使用传感器数据

标签 openai-api chatgpt-api

我使用 openai.ChatCompletion.create 编写了一个 Python 程序来连接 ChatGPT API。 我使用的 messages 具有两个角色:user,用户提示符为 content,以及加载当前内容的 assistant传感器数据为 content,这是我使用 MQTT 从一组传感器获取的。传感器数据是原始的 JSON,但我将其格式化为这样:

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

我的想法是使用清晰的语言询问温度是多少?露点是多少?并期望ChatGPT只给我第一个并计算第二个基于数据中可用的温度和湿度。

我不想训练模型,因为数据不断变化。

有没有办法将传感器数据提供给 ChatGPT API? (我也尝试过使用角色system,顺便说一句)

最佳答案

好吧,我通过一些尝试和错误设法解决了这个问题:

我的 API 调用如下所示:

        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},
            ],
        )

提示来自HTML输入,例如“干了吗?”

sensor_data 是一个文本字符串,其数据采用平面格式,如下所示:

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

对上述问题的回答如下:

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.

sensor_data 变量每 5 秒从 MQTT 服务器更新一次,但可以来自任何地方。

关于openai-api - OpenAI ChatGPT API - 使用传感器数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76946561/

相关文章:

nlp - GPT-3 基于关键词的问答

excel - 如何从 Excel 宏 (vba) 使用 API 询问 ChatGPT?

python - ChatGPT API 定制训练的 AI 聊天机器人对 Python 查询应答 "None"

openai-api - ChatGPT 完成/v1/chat/completions 跨多个请求进行内存

openai-api - ChatGPT 免费版使用什么型号?

python - 获取ChatGPT API的流程是怎样的?

reactjs - 如何将来自 API 的响应保存到某个状态,以便我可以显示旧的搜索/响应?

python - 如何在 Langchain 中传输代理的响应?

python - 使用 Streamlit 和 Langchain 构建在线 AutoGPT 应用程序时出错

python - 使用 GPT API 创建多消息对话