-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathmain.dpr
50 lines (38 loc) · 979 Bytes
/
main.dpr
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
program main;
{$APPTYPE CONSOLE}
{$ifdef fpc}{$mode delphi}{$endif}
uses
Math, LibChatLLM;
procedure _LLMPrint(UserData: Pointer; APrintType: Integer; AUTF8Str: PAnsiChar); cdecl;
var
T: TPrintType;
begin
T := TPrintType(APrintType);
case T of
PRINT_CHAT_CHUNK: Write(UTF8ToString(AUTF8Str));
else
if Assigned(AUTF8Str) then
WriteLn(UTF8ToString(AUTF8Str));
end;
end;
procedure _LLMEnd(UserData: Pointer); cdecl; begin end;
var
LLM: PChatLLMObj;
Input: string;
I: Integer;
begin
SetExceptionMask([Low(TFPUException)..High(TFPUException)]);
LLM := ChatLLMCreate;
for I := 1 to ParamCount do
ChatLLMAppendParam(LLM, PUTF8Char(UTF8Encode(ParamStr(I))));
if ChatLLMStart(LLM, @_LLMPrint, @_LLMEnd, nil) <> 0 then Exit;
while True do
begin
Write('You > ');
ReadLn(Input);
if Length(Input) < 1 then Continue;
Write('A.I. > ');
ChatLLMUserInput(LLM, PUTF8Char(UTF8Encode(Input)));
WriteLn;
end;
end.