いきなりmicroPythonプログラムーRASAエンジン利用による自然言語処理チャットボットー | 秋葉は外神田ですがなにか?

秋葉は外神田ですがなにか?

ガッチャマン背景だったものを、映画不振とは関係なく、
ふつーのCoolTypeに変更しました。
少しは文字が読みやすくなったのではないでしょうか?
・・・と、思ったけど、やっぱりガッチャマンにもどしました。2013.10.15
※トップページ放置確認w2021.Aug

 

 以下、ChatGPTからの回答です。

 

 動作未検証です。

ターゲットマシンはESP32 microPythonです。

 

 

import network

import urequests

 

WIFI_SSID = "YourWiFiSSID"

WIFI_PASSWORD = "YourWiFiPassword"

RASA_ENDPOINT = "http://rasa_server_ip:5005/webhooks/rest/webhook"

 

def connect_to_wifi():

    wifi = network.WLAN(network.STA_IF)

    if not wifi.isconnected():

        print("Connecting to WiFi...")

        wifi.active(True)

        wifi.connect(WIFI_SSID, WIFI_PASSWORD)

        while not wifi.isconnected():

            pass

    print("WiFi connected!")

    print("IP:", wifi.ifconfig()[0])

 

def send_message(message):

    payload = {

        "message": message

    }

    response = urequests.post(RASA_ENDPOINT, json=payload)

    data = response.json()

    response.close()

    return data

 

def main():

    connect_to_wifi()

 

    while True:

        user_input = input("ユーザー: ")

        response_data = send_message(user_input)

 

        if response_data:

            for message in response_data:

                bot_response = message["text"]

 

                print("ボット:", bot_response)

 

 

if __name__ == "__main__":

    main()

 

ChatGPTが言っている内容です。

 

 

信じるか信じないかはあなた次第です。