-
Notifications
You must be signed in to change notification settings - Fork 2
/
co.lua
63 lines (49 loc) · 1.6 KB
/
co.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
51
52
53
54
55
56
57
58
59
60
61
62
63
-- Check for invalid repository name
local isMain = fs.exists("/DavinCC-main/")
local isDavin = fs.exists("/DavinCC/")
if isMain then
error("Incorrect repository name, please rename DavinCC-main to simply DavinCC.")
elseif not isDavin then
error("Incorrect repository location or name, please ensure DavinCC is installed on root, as /DavinCC/.")
end
-- Import completion and quill
package.path = "/DavinCC/?.lua;" .. package.path
local completion = require("lib/completion")
local quill = require("lib/quill")
-- User input for risk and personality
local personality, risk = ...
personality = personality or "standard"
personality = string.lower(personality)
risk = tonumber(risk)
-- Input testing for non-number
if type(risk) ~= "number" then
risk = 0
end
-- Input testing for out of range
if risk < 0 then
risk = 0
elseif risk > 1 then
risk = 1
end
-- Continuation variables
local greetFile
local cont
local prompt
local idxPrompt
local reply
-- Print arguments
print("Personality: \"" .. personality .. "\" Risk: " .. risk .. "\n")
-- Pathing to greeting file
personality = quill.firstUpper(personality)
greetFile = "/DavinCC/greetings/greet" .. personality .. ".txt"
-- Read and truncate greeting into prompt
prompt = quill.scribe(greetFile, "r")
prompt = quill.truncate(prompt)
idxPrompt = #prompt + 2
-- Continue with prompt (file input), risk (0-1), token limit
cont = completion.request(prompt, risk, 1000)
reply = string.sub(cont["choices"][1]["text"], idxPrompt)
quill.scribe("/DavinCC/data/out.txt", "w", reply)
-- Print output as orange
term.setTextColour(colours.orange)
print(reply .. "\n")