-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nim
38 lines (31 loc) · 905 Bytes
/
main.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
import system
import strutils
import os
import libchatllm
proc chatllm_print(user_data: pointer, print_type: PrintType, utf8_str: cstring) {.cdecl.} =
case print_type
of PRINT_CHAT_CHUNK:
stdout.write(utf8_str)
else:
echo utf8_str
stdout.flushFile()
proc chatllm_end(user_data: pointer) {.cdecl.} =
echo ""
proc main() =
let chat = chatllm_create()
for i in 1 .. paramCount():
chatllm_append_param(chat, paramStr(i).cstring)
let r = chatllm_start(chat, chatllm_print, chatllm_end, nil)
if r != 0:
echo ">>> chatllm_start error: ", r
quit(r)
while true:
stdout.write("You > ")
let input = stdin.readLine()
if input.isEmptyOrWhitespace(): continue
stdout.write("A.I. > ")
let r = chatllm_user_input(chat, input.cstring)
if r != 0:
echo ">>> chatllm_user_input error: ", r
break
main()