Advertisement
appollon41

LUALLMHandler

Apr 29th, 2024 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. monitor = peripheral.wrap("left")
  2. recorder = peripheral.wrap("right")
  3.  
  4. monitor.setTextScale(0.5)
  5. monitor.clear()
  6. monitor.setCursorPos(1, 1)
  7.  
  8. LLMstatus = "sleeping"
  9.  
  10. while true do
  11. local ws, err = http.websocket("wss://api.kalipto.dev")
  12. if ws then
  13. local function mainThread()
  14. while true do
  15. local _, player, message, uuid = os.pullEvent("chat_message")
  16. if LLMstatus == "sleeping" then
  17. if message:find("^!![Bb]onjour [Cc]hat") then -- Triggers the chat
  18. monitor.clear()
  19. monitor.setCursorPos(1, 1)
  20. monitor.write("Coucou " .. player)
  21. recorder.say("<ChatJ'aiPété> " .. "Coucou " .. player)
  22. ws.send("Coucou " .. player .. ", activating LLM")
  23. response = ws.receive()
  24. LLMstatus = "awake"
  25. print("LLM is awake")
  26. end
  27. else
  28. if message:find("[Bb]ye [Cc]hat") then -- Triggers the chat end
  29. monitor.clear()
  30. monitor.setCursorPos(1, 1)
  31. monitor.write("Bye " .. player)
  32. recorder.say("<ChatJ'aiPété> " .. "Bye " .. player)
  33. LLMstatus = "sleeping"
  34. else -- Section to display the chat
  35. monitor.clear()
  36. monitor.setCursorPos(1, 1)
  37. monitor.setCursorPos(1, 2)
  38. ws.send(message)
  39.  
  40. response = ws.receive()
  41. monitor.write(response)
  42. recorder.say("<ChatJ'aiPété> " .. response)
  43. print(response)
  44. end
  45. end
  46. -- print(player .. " : " .. message .. " : " .. uuid)
  47. end
  48. end
  49. -- parallel.waitForAny(mainThread, keepAlive)
  50. mainThread()
  51. else
  52. print("WebSocket connection failed: " .. err)
  53. return
  54. end
  55. os.sleep(5)
  56. end
  57.  
  58. -- End of the program
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement