Skip to content

Commit 8ade274

Browse files
committed
commit-initial
1 parent 837d2f1 commit 8ade274

6 files changed

Lines changed: 1153 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ __recovery/
7979

8080
# Boss dependency manager vendor folder https://github.com/HashLoad/boss
8181
modules/
82+
/bin

Ollama4Delphi.dpr

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
program Ollama4Delphi;
2+
3+
{$APPTYPE CONSOLE}
4+
5+
{$R *.res}
6+
7+
uses
8+
System.SysUtils,
9+
Horse,
10+
RESTRequest4D;
11+
12+
const
13+
PORT_DEFAULT = 9004;
14+
BASE_URL_OLLAMA = 'http://localhost:11434/api/chat';
15+
16+
var
17+
FPort: Integer;
18+
FPortStr: string;
19+
20+
begin
21+
Write(Format('Enter the port number (default %d): ', [PORT_DEFAULT]));
22+
Readln(FPortStr);
23+
FPort := StrToIntDef(FPortStr, PORT_DEFAULT);
24+
25+
THorse.Get('/ping',
26+
procedure(Req: THorseRequest; Res: THorseResponse)
27+
begin
28+
Res.Send('pong');
29+
end);
30+
31+
THorse.Post('/api/chat',
32+
procedure(Req: THorseRequest; Res: THorseResponse)
33+
var
34+
LResponse: IResponse;
35+
begin
36+
Writeln(Format('Request started %s', [FormatDateTime('yyyy/mm/dd HH:nn:ss', Now)]));
37+
38+
LResponse := TRequest.New
39+
.BaseURL(BASE_URL_OLLAMA)
40+
.ContentType('application/json')
41+
//.Accept('application/json')
42+
//.Token('Bearer ' + FSettings.ApiKeyOllama)
43+
.AddBody(Req.Body)
44+
.Post;
45+
46+
Res.Send(LResponse.Content);
47+
end);
48+
49+
THorse.Listen(FPort,
50+
procedure
51+
begin
52+
Writeln(Format('Ollama4Delphi running on the port %d ', [FPort]));
53+
end);
54+
55+
end.

0 commit comments

Comments
 (0)