-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOllama4Delphi.dpr
More file actions
55 lines (43 loc) · 1.12 KB
/
Copy pathOllama4Delphi.dpr
File metadata and controls
55 lines (43 loc) · 1.12 KB
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
program Ollama4Delphi;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Horse,
RESTRequest4D;
const
PORT_DEFAULT = 9004;
BASE_URL_OLLAMA = 'http://localhost:11434/api/chat';
var
FPort: Integer;
FPortStr: string;
begin
Write(Format('Enter the port number (default %d): ', [PORT_DEFAULT]));
Readln(FPortStr);
FPort := StrToIntDef(FPortStr, PORT_DEFAULT);
THorse.Get('/ping',
procedure(Req: THorseRequest; Res: THorseResponse)
begin
Res.Send('pong');
end);
THorse.Post('/api/chat',
procedure(Req: THorseRequest; Res: THorseResponse)
var
LResponse: IResponse;
begin
Writeln(Format('Request started %s', [FormatDateTime('yyyy/mm/dd HH:nn:ss', Now)]));
LResponse := TRequest.New
.BaseURL(BASE_URL_OLLAMA)
.ContentType('application/json')
//.Accept('application/json')
//.Token('Bearer ' + FSettings.ApiKeyOllama)
.AddBody(Req.Body)
.Post;
Res.Send(LResponse.Content);
end);
THorse.Listen(FPort,
procedure
begin
Writeln(Format('Ollama4Delphi running on the port %d ', [FPort]));
end);
end.