-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.nim
75 lines (57 loc) · 1.59 KB
/
app.nim
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
64
65
66
67
68
69
70
71
72
73
74
75
# Main native file
import happyx_native
const AppVersion = "v0.1.0"
var
token: string = ""
primaryColor: string = "pink"
usePCIB: bool = false
chats: string = "[]"
modelName: string = "gpt-3.5-turbo"
apiBase: string = "https://api.openai.com/v1"
proc saveData*() =
{.gcsafe.}:
var data = %*{
"token": token,
"primaryColor": primaryColor,
"usePCIB": usePCIB,
"chats": chats,
"model": modelName,
"apiBase": apiBase
}
save(fmt"chatgpt-client-{AppVersion}.save", data)
proc loadData*() =
{.gcsafe.}:
var source = loadString(fmt"chatgpt-client-{AppVersion}.save")
if source.len > 0:
var data = parseJson(source)
token = data["token"].getStr
primaryColor = data["primaryColor"].getStr
usePCIB = data["usePCIB"].getBool
chats = data["chats"].getStr
modelName = data["model"].getStr
apiBase = data["apiBase"].getStr
callback:
proc load() =
loadData()
if primaryColor == "":
primaryColor = "pink"
callJs("loadAll", token, primaryColor, $usePCIB, chats, modelName, apiBase)
proc saveToken(val: string) =
token = val
saveData()
proc savePrimaryColor(val: string) =
primaryColor = val
saveData()
proc saveUsePCInBack(val: string) =
usePCIB = val == "true"
saveData()
proc saveChats(val: string) =
chats = val
saveData()
proc saveModel(val: string) =
modelName = val
saveData()
proc saveApiBase(val: string) =
apiBase = val
saveData()
nativeApp("/assets", w = 900, h = 540, title = "ChatGPT Client", establish = false)