『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 3244|回复: 34

[基础教程] 白嫖openai的api key把小爱音箱接入chatgpt

[复制链接]

73

主题

510

帖子

3091

积分

论坛元老

Rank: 8Rank: 8

积分
3091
金钱
2581
HASS币
0
发表于 2023-12-16 17:56:17 | 显示全部楼层 |阅读模式
之前申请的openai的apikey早已经过期了这就没再玩api,偶然发现github上大佬有免费api项目,拿过来用了用还挺好用,于是又折腾了一个流,把小爱音箱接入chatgpt,大佬网址:https://github.com/chatanywhere/GPT_API_free,感谢大佬



                               
登录/注册后可看大图

[
    {
        "id": "73f4cb07bcf61615",
        "type": "server-state-changed",
        "z": "8c8242e7b6ea02a8",
        "name": "小爱音箱",
        "server": "459a05598e74e156",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sensor.xiaomi_lx5a_7d9b_conversation",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 160,
        "y": 1400,
        "wires": [
            [
                "50ef668ebea29429",
                "3f3dabf2834007ca"
            ]
        ]
    },
    {
        "id": "3f3dabf2834007ca",
        "type": "switch",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "开启贾维斯",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "召唤贾维斯",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "打开贾维斯",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "退出贾维斯",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "关闭贾维斯",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 5,
        "x": 350,
        "y": 1320,
        "wires": [
            [
                "039fbd671807fa3f"
            ],
            [
                "039fbd671807fa3f"
            ],
            [
                "039fbd671807fa3f"
            ],
            [
                "5121643a1fa5d572"
            ],
            [
                "5121643a1fa5d572"
            ]
        ]
    },
    {
        "id": "4b01a0e4fc04ec84",
        "type": "debug",
        "z": "8c8242e7b6ea02a8",
        "name": "debug 334",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 810,
        "y": 1360,
        "wires": []
    },
    {
        "id": "d5960fdc46d6972a",
        "type": "inject",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "props": [
            {
                "p": "wt",
                "v": "帮我策划一个十岁小孩的生日",
                "vt": "str"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 190,
        "y": 1580,
        "wires": [
            [
                "8773f238830b2caa"
            ]
        ]
    },
    {
        "id": "8773f238830b2caa",
        "type": "function",
        "z": "8c8242e7b6ea02a8",
        "name": "function 32",
        "func": "msg.headers = {\n    'Content-Type': 'application/json',\n    'Authorization': 'Bearer your key'\n    }\n\n\nmsg.payload = {\n    "model": "gpt-3.5-turbo",\n    "messages": [\n        {\n            "role": "system",\n            "content": "You are a helpful assistant."\n        },\n        {\n            "role": "user",\n            "content": msg.wt\n        }\n    ]\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 1580,
        "wires": [
            [
                "efabfcb91ec074c3"
            ]
        ]
    },
    {
        "id": "efabfcb91ec074c3",
        "type": "http request",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://api.chatanywhere.tech/v1/chat/completions",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 520,
        "y": 1580,
        "wires": [
            [
                "0977d103cb1ba3f9"
            ]
        ]
    },
    {
        "id": "0977d103cb1ba3f9",
        "type": "json",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 650,
        "y": 1580,
        "wires": [
            [
                "f02c68977360528a"
            ]
        ]
    },
    {
        "id": "82e28a5544ebc505",
        "type": "debug",
        "z": "8c8242e7b6ea02a8",
        "name": "debug 335",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1030,
        "y": 1580,
        "wires": []
    },
    {
        "id": "f02c68977360528a",
        "type": "change",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.choices[0].message.content",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 830,
        "y": 1580,
        "wires": [
            [
                "82e28a5544ebc505",
                "db79d520a7ee4b61"
            ]
        ]
    },
    {
        "id": "db79d520a7ee4b61",
        "type": "api-call-service",
        "z": "8c8242e7b6ea02a8",
        "name": "小爱播放结果",
        "server": "459a05598e74e156",
        "version": 5,
        "debugenabled": false,
        "domain": "xiaomi_miot",
        "service": "intelligent_speaker",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "media_player.xiaomi_lx5a_7d9b_play_control"
        ],
        "data": "{"text":msg.payload}",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 940,
        "y": 1680,
        "wires": [
            []
        ]
    },
    {
        "id": "039fbd671807fa3f",
        "type": "api-call-service",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "server": "459a05598e74e156",
        "version": 5,
        "debugenabled": false,
        "domain": "input_boolean",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "input_boolean.xiao_ai_yin_xiang_chatgptkai_guan"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 540,
        "y": 1300,
        "wires": [
            []
        ]
    },
    {
        "id": "a14c57cda204418c",
        "type": "api-current-state",
        "z": "8c8242e7b6ea02a8",
        "name": "贾维斯开关",
        "server": "459a05598e74e156",
        "version": 3,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "input_boolean.xiao_ai_yin_xiang_chatgptkai_guan",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 630,
        "y": 1480,
        "wires": [
            [
                "4b01a0e4fc04ec84",
                "2dfa531005c8b19c"
            ],
            []
        ]
    },
    {
        "id": "499eac86a8f557c6",
        "type": "api-call-service",
        "z": "8c8242e7b6ea02a8",
        "name": "小爱播放结果",
        "server": "459a05598e74e156",
        "version": 5,
        "debugenabled": false,
        "domain": "xiaomi_miot",
        "service": "intelligent_speaker",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "media_player.xiaomi_lx5a_7d9b_play_control"
        ],
        "data": "{"text":"贾维斯正在查询,请稍后"}",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1000,
        "y": 1440,
        "wires": [
            []
        ]
    },
    {
        "id": "50ef668ebea29429",
        "type": "change",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "wt",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 310,
        "y": 1480,
        "wires": [
            [
                "b825827679c20f63"
            ]
        ]
    },
    {
        "id": "5121643a1fa5d572",
        "type": "api-call-service",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "server": "459a05598e74e156",
        "version": 5,
        "debugenabled": false,
        "domain": "input_boolean",
        "service": "turn_off",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "input_boolean.xiao_ai_yin_xiang_chatgptkai_guan"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 540,
        "y": 1360,
        "wires": [
            []
        ]
    },
    {
        "id": "b825827679c20f63",
        "type": "delay",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 480,
        "y": 1480,
        "wires": [
            [
                "a14c57cda204418c"
            ]
        ]
    },
    {
        "id": "2dfa531005c8b19c",
        "type": "switch",
        "z": "8c8242e7b6ea02a8",
        "name": "",
        "property": "wt",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "打开贾维斯",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "召唤贾维斯",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "启动贾维斯",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 4,
        "x": 810,
        "y": 1480,
        "wires": [
            [],
            [],
            [],
            [
                "8773f238830b2caa",
                "499eac86a8f557c6"
            ]
        ]
    },
    {
        "id": "459a05598e74e156",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": ": ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "default",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": false
    }
]









flows (3).zip (2.62 KB, 下载次数: 143)

回复

使用道具 举报

7

主题

1072

帖子

3361

积分

论坛元老

Rank: 8Rank: 8

积分
3361
金钱
2289
HASS币
0
发表于 2023-12-16 18:54:45 | 显示全部楼层
这个大佬真会玩。
回复

使用道具 举报

2

主题

104

帖子

1364

积分

金牌会员

Rank: 6Rank: 6

积分
1364
金钱
1260
HASS币
0
发表于 2023-12-16 21:42:18 | 显示全部楼层
测试一下,可以用,但是不能连续问。
回复

使用道具 举报

0

主题

16

帖子

144

积分

注册会员

Rank: 2

积分
144
金钱
128
HASS币
0
发表于 2023-12-16 22:16:40 | 显示全部楼层
具体怎么搭建呢 好像还要见一个模拟开关?
回复

使用道具 举报

73

主题

510

帖子

3091

积分

论坛元老

Rank: 8Rank: 8

积分
3091
金钱
2581
HASS币
0
 楼主| 发表于 2023-12-16 22:29:28 | 显示全部楼层
maple2271 发表于 2023-12-16 22:16
具体怎么搭建呢 好像还要见一个模拟开关?

模拟开关从ha里边辅助元素
回复

使用道具 举报

0

主题

33

帖子

146

积分

注册会员

Rank: 2

积分
146
金钱
113
HASS币
0
发表于 2023-12-16 23:36:05 | 显示全部楼层
1.png
2.png
已经建立了辅助开关,怎么一直提示not found ,是不是要和小爱关联啊,大佬
回复

使用道具 举报

73

主题

510

帖子

3091

积分

论坛元老

Rank: 8Rank: 8

积分
3091
金钱
2581
HASS币
0
 楼主| 发表于 2023-12-16 23:40:21 | 显示全部楼层
gthh62d 发表于 2023-12-16 23:36
已经建立了辅助开关,怎么一直提示not found ,是不是要和小爱关联啊,大佬
...

nr中判断开关状态id你得和ha里边辅助元素id一致
回复

使用道具 举报

73

主题

510

帖子

3091

积分

论坛元老

Rank: 8Rank: 8

积分
3091
金钱
2581
HASS币
0
 楼主| 发表于 2023-12-16 23:41:57 | 显示全部楼层
jole 发表于 2023-12-16 21:42
测试一下,可以用,但是不能连续问。

设置个全局变量就行了
回复

使用道具 举报

2

主题

104

帖子

647

积分

高级会员

Rank: 4

积分
647
金钱
543
HASS币
0
发表于 2023-12-17 09:33:35 | 显示全部楼层
请教老大这个api token放在哪个节点里。
回复

使用道具 举报

73

主题

510

帖子

3091

积分

论坛元老

Rank: 8Rank: 8

积分
3091
金钱
2581
HASS币
0
 楼主| 发表于 2023-12-17 09:50:25 | 显示全部楼层
6907367 发表于 2023-12-17 09:33
请教老大这个api token放在哪个节点里。

function节点
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-29 08:01 , Processed in 0.197765 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表