-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatgpt.lua
50 lines (41 loc) · 1.33 KB
/
chatgpt.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local url = "http://localhost:8000/minecraft"
function wipe()
term.clear()
term.setCursorPos(1, 1)
end
wipe()
term.setTextColor(colors.orange)
print("")
print(" _|_|_| _| _| _|_|_| _|_|_| _|_|_| ")
print(" _| _|_|_| _|_|_| _|_|_|_| _| _| _| _| ")
print(" _| _| _| _| _| _| _| _|_| _|_|_| _| ")
print(" _| _| _| _| _| _| _| _| _| _| ")
print(" _|_|_| _| _| _|_|_| _|_| _|_|_| _| _| ")
print("")
term.setTextColor(colors.lightGray)
print("Send messages to ChatGPT. Type \"exit\" to go back to terminal.")
print("")
while true do
term.setTextColor(colors.magenta)
io.write("<me> ")
term.setTextColor(colors.white)
local message = io.read()
if message == "exit" then
wipe()
break
end
local body = textutils.serialiseJSON({question = message})
local response = http.post(url, body, headers)
if response then
local body = response.readAll()
local answer = textutils.unserialiseJSON(body)
term.setTextColor(colors.lime)
io.write("<ChatGPT> ")
term.setTextColor(colors.white)
print(answer.message)
print("")
response.close()
else
print("Failed to connect to the server.")
end
end