Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.wrap("left")
- recorder = peripheral.wrap("right")
- monitor.setTextScale(0.5)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- LLMstatus = "sleeping"
- while true do
- local ws, err = http.websocket("wss://api.kalipto.dev")
- if ws then
- local function mainThread()
- while true do
- local _, player, message, uuid = os.pullEvent("chat_message")
- if LLMstatus == "sleeping" then
- if message:find("^!![Bb]onjour [Cc]hat") then -- Triggers the chat
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Coucou " .. player)
- recorder.say("<ChatJ'aiPété> " .. "Coucou " .. player)
- ws.send("Coucou " .. player .. ", activating LLM")
- response = ws.receive()
- LLMstatus = "awake"
- print("LLM is awake")
- end
- else
- if message:find("[Bb]ye [Cc]hat") then -- Triggers the chat end
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Bye " .. player)
- recorder.say("<ChatJ'aiPété> " .. "Bye " .. player)
- LLMstatus = "sleeping"
- else -- Section to display the chat
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.setCursorPos(1, 2)
- ws.send(message)
- response = ws.receive()
- monitor.write(response)
- recorder.say("<ChatJ'aiPété> " .. response)
- print(response)
- end
- end
- -- print(player .. " : " .. message .. " : " .. uuid)
- end
- end
- -- parallel.waitForAny(mainThread, keepAlive)
- mainThread()
- else
- print("WebSocket connection failed: " .. err)
- return
- end
- os.sleep(5)
- end
- -- End of the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement