8000 Merge branch 'develop' · Code4Delphi/Delphi-AI-Developer@34cc94d · GitHub
[go: up one dir, main page]

Skip to content

Commit 34cc94d

Browse files
committed
Merge branch 'develop'
2 parents 203c879 + 4b4df62 commit 34cc94d

14 files changed

+390
-35
lines changed

Package/DelphiAIDeveloper.dpk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ contains
114114
DelphiAIDev.CodeCompletion.Search in '..\Src\CodeCompletion\DelphiAIDev.CodeCompletion.Search.pas',
115115
DelphiAIDev.Test.Client in '..\Src\Test\DelphiAIDev.Test.Client.pas',
116116
DelphiAIDev.CodeCompletion.KeyTab in '..\Src\CodeCompletion\DelphiAIDev.CodeCompletion.KeyTab.pas',
117-
DelphiAIDev.AI.Response in '..\Src\AI\DelphiAIDev.AI.Response.pas';
117+
DelphiAIDev.AI.Response in '..\Src\AI\DelphiAIDev.AI.Response.pas',
118+
DelphiAIDev.AI.Mistral in '..\Src\AI\DelphiAIDev.AI.Mistral.pas';
118119

119120
end.

Package/DelphiAIDeveloper.dproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@
245245
<DCCReference Include="..\Src\Test\DelphiAIDev.Test.Client.pas"/>
246246
<DCCReference Include="..\Src\CodeCompletion\DelphiAIDev.CodeCompletion.KeyTab.pas"/>
247247
<DCCReference Include="..\Src\AI\DelphiAIDev.AI.Response.pas"/>
248+
<DCCReference Include="..\Src\AI\DelphiAIDev.AI.Mistral.pas"/>
248249
<RcItem Include="Img\c4d_Logo.bmp">
249250
<ResourceType>BITMAP</Resourc E864 eType>
250251
<ResourceId>c4d_Logo</ResourceId>
@@ -307,8 +308,12 @@
307308
</Delphi.Personality>
308309
<Deployment Version="5">
309310
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule"/>
311+
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule"/>
312+
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libpcre.dylib" Class="DependencyModule"/>
310313
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libpcre.dylib" Class="DependencyModule"/>
311314
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule"/>
315+
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule"/>
316+
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\DelphiAIDeveloper.bpl" Configuration="Debug" Class="ProjectOutput"/>
312317
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\DelphiAIDeveloper.bpl" Configuration="Debug" Class="ProjectOutput"/>
313318
<DeployClass Name="AdditionalDebugSymbols">
314319
<Platform Name="OSX32">

Src/AI/DelphiAIDev.AI.Facade.pas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface
1313
DelphiAIDev.AI.Gemini,
1414
DelphiAIDev.AI.ChatGPT,
1515
DelphiAIDev.AI.Groq,
16+
DelphiAIDev.AI.Mistral,
1617
DelphiAIDev.AI.Ollama;
1718

1819
type
@@ -70,6 +71,8 @@ function TDelphiAIDevAIFacade.ProcessSend(const AQuestion: string): TDelphiAIDev
7071
LRequest := TDelphiAIDevAIChatGPT.Create(FSettings, FResponse);
7172
TC4DAiAvailable.Groq:
7273
LRequest := TDelphiAIDevAIGroq.Create(FSettings, FResponse);
74+
TC4DAiAvailable.Mistral:
75+
LRequest := TDelphiAIDevAIMistral.Create(FSettings, FResponse);
7376
TC4DAiAvailable.Ollama:
7477
LRequest := TDelphiAIDevAIOllama.Create(FSettings, FResponse);
7578
else

Src/AI/DelphiAIDev.AI.Mistral.pas

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
unit DelphiAIDev.AI.Mistral;
2+
3+
interface
4+
5+
uses
6+
System.SysUtils,
7+
System.JSON,
8+
System.Classes,
9+
RESTRequest4D,
10+
DelphiAIDev.Consts,
11+
DelphiAIDev.Utils,
12+
DelphiAIDev.Settings,
13+
DelphiAIDev.AI.Interfaces;
14+
15+
type
16+
TDelphiAIDevAIMistral = class(TInterfacedObject, IDelphiAIDevAI)
17+
private
18+
FSettings: TDelphiAIDevSettings;
19+
FResponse: IDelphiAIDevAIResponse;
20+
protected
21+
function GetResponse(const AQuestion: string): IDelphiAIDevAIResponse;
22+
public
23+
constructor Create(const ASettings: TDelphiAIDevSettings; const AResponse: IDelphiAIDevAIResponse);
24+
end;
25+
26+
implementation
27+
28+
const
29+
API_JSON_BODY_BASE = '{"messages": [{"role": "user", "content": "%s"}], "model": "%s"}';
30+
31+
constructor TDelphiAIDevAIMistral.Create(const ASettings: TDelphiAIDevSettings; const AResponse: IDelphiAIDevAIResponse);
32+
begin
33+
FSettings := ASettings;
34+
FResponse := AResponse;
35+
end;
36+
37+
function TDelphiAIDevAIMistral.GetResponse(const AQuestion: string): IDelphiAIDevAIResponse;
38+
var
39+
LResponse: IResponse;
40+
LJsonValueAll: TJSONVALUE;
41+
LJsonArrayChoices: TJsonArray;
42+
LJsonObjMessage: TJsonObject;
43+
LContent: string;
44+
LItemChoices: Integer;
45+
LResult: string;
46+
begin
47+
Result := FResponse;
48+
49+
LResponse := TRequest.New
50+
.BaseURL(FSettings.BaseUrlMistral)
51+
.ContentType(TConsts.APPLICATION_JSON)
52+
.Accept(TConsts.APPLICATION_JSON)
53+
.Token('Bearer ' + FSettings.ApiKeyMistral)
54+
.AddBody(Format(API_JSON_BODY_BASE, [AQuestion, FSettings.ModelMistral]))
55+
.Post;
56+
57+
FResponse.SetStatusCode(LResponse.StatusCode);
58+
59+
if LResponse.StatusCode <> 200 then
60+
begin
61+
FResponse.SetContentText('Question cannot be answered' + sLineBreak + 'Return: ' + LResponse.Content);
62+
Exit;
63+
end;
64+
65+
LJsonValueAll := TJsonObject.ParseJSONValue(LResponse.Content);
66+
if not(LJsonValueAll is TJSONObject) then
67+
begin
68+
FResponse.SetContentText('The question cannot be answered, return object not found.' + sLineBreak +
69+
'Return: ' + LResponse.Content);
70+
Exit;
71+
end;
72+
73+
LJsonArrayChoices := (LJsonValueAll as TJsonObject).GetValue<TJsonArray>('choices');
74+
for LItemChoices := 0 to Pred(LJsonArrayChoices.Count) do
75+
begin
76+
LJsonObjMessage := LJsonArrayChoices.Items[LItemChoices].GetValue<TJsonObject>('message');
77+
LContent := LJsonObjMessage.GetValue<string>('content');
78+
LResult := LResult + LContent.Trim + sLineBreak;
79+
end;
80+
81+
FResponse.SetContentText(LResult.Trim);
82+
end;
83+
84+
end.

Src/Chat/DelphiAIDev.Chat.View.dfm

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
1212
Font.Name = 'Tahoma'
1313
Font.Style = []
1414
KeyPreview = True
15-
OldCreateOrder = False
1615
Position = poScreenCenter
1716
ShowHint = True
1817
OnActivate = FormActivate
@@ -22,7 +21,6 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
2221
DesignSize = (
2322
975
2423
661)
25-
PixelsPerInch = 96
2624
TextHeight = 13
2725
object pnBack: TPanel
2826
Left = 0
@@ -80,7 +78,6 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
8078
ScrollBars = ssVertical
8179
ShowHint = True
8280
TabOrder = 1
83-
Zoom = 100
8481
end
8582
object pnBackQuestion: TPanel
8683
Left = 18
@@ -138,7 +135,7 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
138135
Left = 0
139136
Top = 3
140137
Width = 56
141-
Height = 13
138+
Height = 22
142139
Cursor = crHandPoint
143140
Hint = 'AI being used'
144141
Margins.Left = 0
@@ -149,6 +146,7 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
149146
Caption = 'lbCurrentAI'
150147
PopupMenu = pMenuCurrentAI
151148
OnClick = lbCurrentAIClick
149+
ExplicitHeight = 13
152150
end
153151
object btnSend: TButton
154152
AlignWithMargins = True
@@ -817,8 +815,13 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
817815
Caption = 'Groq'
818816
OnClick = Gemini1Click
819817
end
820-
object Ollama1: TMenuItem
818+
object Mistral1: TMenuItem
821819
Tag = 3
820+
Caption = 'Mistral'
821+
OnClick = Gemini1Click
822+
end
823+
object Ollama1: TMenuItem
824+
Tag = 4
822825
Caption = 'Ollama (offline)'
823826
OnClick = Gemini1Click
824827
end

Src/Chat/DelphiAIDev.Chat.View.pas

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ TDelphiAIDevChatView = class(TDockableForm)
7474
pMenuQuestions: TPopupMenu;
7575
btnCleanAll: TSpeedButton;
7676
Groq1: TMenuItem;
77+
Mistral1: TMenuItem;
7778
Ollama1: TMenuItem;
7879
procedure FormShow(Sender: TObject);
7980
procedure cBoxSizeFontKeyPress(Sender: TObject; var Key: Char);
@@ -612,6 +613,7 @@ procedure TDelphiAIDevChatView.pMenuCurrentAIPopup(Sender: TObject);
612613
Gemini1.Checked := False;
613614
ChatGPT1.Checked := False;
614615
Groq1.Checked := False;
616+
Mistral1.Checked := False;
615617
Ollama1.Checked := False;
616618
case FSettings.AIDefault of
617619
TC4DAiAvailable.Gemini:
@@ -620,6 +622,8 @@ procedure TDelphiAIDevChatView.pMenuCurrentAIPopup(Sender: TObject);
620622
ChatGPT1.Checked := True;
621623
TC4DAiAvailable.Groq:
622624
Groq1.Checked := True;
625+
TC4DAiAvailable.Mistral:
626+
Mistral1.Checked := True;
623627
TC4DAiAvailable.Ollama:
624628
Ollama1.Checked := True;
625629
end;
@@ -636,6 +640,8 @@ procedure TDelphiAIDevChatView.ConfLabelCurrentAI;
636640
lbCurrentAI.Hint := FSettings.ModelOpenAI;
637641
TC4DAiAvailable.Groq:
638642
lbCurrentAI.Hint := FSettings.ModelGroq;
643+
TC4DAiAvailable.Mistral:
644+
lbCurrentAI.Hint := FSettings.ModelMistral;
639645
TC4DAiAvailable.Ollama:
640646
lbCurrentAI.Hint := FSettings.ModelOllama;
641647
end;
@@ -650,7 +656,7 @@ procedure TDelphiAIDevChatView.Gemini1Click(Sender: TObject);
650656
begin
651657
//*SEVERAL
652658
LTag := TMenuItem(Sender).Tag;
653-
if not(LTag in [0, 1, 2, 3])then
659+
if not(LTag in [0, 1, 2, 3, 4])then
654660
Exit;
655661

656662
FSettings.AIDefault := TC4DAiAvailable(LTag);

Src/Consts/DelphiAIDev.Consts.pas

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface
55
type
66
TConsts = class
77
public const
8-
SEMANTIC_VERSION = '2.3.1';
8+
SEMANTIC_VERSION = '2.4.0';
99
SEMANTIC_VERSION_LB = 'Version: ' + SEMANTIC_VERSION;
1010
WIN_CONTROL_FOCU_NIL = nil;
1111
DELPHI_AI_DEVELOPER_DPROJ = 'DelphiAIDeveloper.dproj';
@@ -38,6 +38,9 @@ TConsts = class
3838
BASE_URL_GROQ = 'https://api.groq.com/openai/v1/chat/completions';
3939
MODEL_GROQ_DEFAULT = 'llama3-70b-8192'; //'llama3-8b-8192';;
4040

41+
BASE_URL_Mistral = 'https://api.mistral.ai/v1/chat/completions';
42+
MODEL_Mistral_DEFAULT = 'mistral-small-latest';
43+
4144
BASE_URL_OLLAMA = 'http://localhost:11434/api/chat';
4245
MODEL_OLLAMA_DEFAULT = ''; //'tinyllama' 'mistral';
4346

@@ -55,7 +58,7 @@ TConsts = class
5558

5659
//ABOUT AND SPLASH
5760
ABOUT_TITLE = 'Delphi AI Developer';
58-
ABOUT_COPY_RIGHT = 'Copyright 2024 Code4Delphi Team.';
61+
ABOUT_COPY_RIGHT = 'Copyright 2025 Code4Delphi Team.';
5962
ABOUT_DESCRIPTION = 'Plugin designed to be used in the Delphi IDE.';
6063
PLUGIN_LICENSE = 'MIT license';
6164
IS_UNREGISTERED = False;

Src/DB/Chat/DelphiAIDev.DB.Chat.View.dfm

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ object DelphiAIDevDBChatView: TDelphiAIDevDBChatView
1212
Font.Name = 'Tahoma'
1313
Font.Style = []
1414
KeyPreview = True
15-
OldCreateOrder = False
1615
Position = poScreenCenter
1716
ShowHint = True
1817
OnActivate = FormActivate
@@ -22,7 +21,6 @@ object DelphiAIDevDBChatView: TDelphiAIDevDBChatView
2221
DesignSize = (
2322
975
2423
661)
25-
PixelsPerInch = 96
2624
TextHeight = 13
2725
object pnBack: TPanel
2826
Left = 0
@@ -91,7 +89,6 @@ object DelphiAIDevDBChatView: TDelphiAIDevDBChatView
9189
ScrollBars = ssVertical
9290
ShowHint = True
9391
TabOrder = 1
94-
Zoom = 100
9592
end
9693
object pnBackQuestion: TPanel
9794
Left = 18
@@ -161,7 +158,7 @@ object DelphiAIDevDBChatView: TDelphiAIDevDBChatView
161158
Left = 0
162159
Top = 3
163160
Width = 56
164-
Height = 13
161+
Height = 22
165162
Cursor = crHandPoint
166163
Hint = 'AI being used'
167164
Margins.Left = 0
@@ -172,6 +169,7 @@ object DelphiAIDevDBChatView: TDelphiAIDevDBChatView
172169
Caption = 'lbCurrentAI'
173170
PopupMenu = pMenuCurrentAI
174171
OnClick = lbCurrentAIClick
172+
ExplicitHeight = 13
175173
end
176174
object btnSend: TButton
177175
AlignWithMargins = True
@@ -298,19 +296,21 @@ object DelphiAIDevDBChatView: TDelphiAIDevDBChatView
298296
Left = 899
299297
Top = 3
300298
Width = 36
301-
Height = 13
299+
Height = 21
302300
Align = alRight
303301
Caption = '000000'
304302
Layout = tlCenter
303+
ExplicitHeight = 13
305304
end
306305
object Label3: TLabel
307306
Left = 863
308307
Top = 3
309308
Width = 36
310-
Height = 13
309+
Height = 21
311310
Align = alRight
312311
Caption = 'Count: '
313312
Layout = tlCenter
313+
ExplicitHeight = 13
314314
end
315315
end
316316
end
@@ -332,24 +332,26 @@ object DelphiAIDevDBChatView: TDelphiAIDevDBChatView
332332
Left = 337
333333
Top = 0
334334
Width = 85
335-
Height = 13
335+
Height = 25
336336
Align = alLeft
337337
Caption = ' Last generation: '
338338
Layout = tlCenter
339+
ExplicitHeight = 13
339340
end
340341
object lbLastGeneration: TLabel
341342
AlignWithMargins = True
342343
Left = 422
343344
Top = 0
344345
Width = 81
345-
Height = 13
346+
Height = 25
346347
Margins.Left = 0
347348
Margins.Top = 0
348349
Margins.Right = 5
349350
Margins.Bottom = 0
350351
Align = alLeft
351352
Caption = 'lbLastGeneration'
352353
Layout = tlCenter
354+
ExplicitHeight = 13
353355
end
354356
object btnExecuteSQL: TButton
355357
AlignWithMargins = True
@@ -983,8 +985,13 @@ object DelphiAIDevDBChatView: TDelphiAIDevDBChatView
983985
Caption = 'Groq'
984986
OnClick = Gemini1Click
985987
end
986-
object Ollama1: TMenuItem
988+
object Mistral1: TMenuItem
987989
Tag = 3
990+
Caption = 'Mistral'
991+
OnClick = Gemini1Click
992+
end
993+
object Ollama1: TMenuItem
994+
Tag = 4
988995
Caption = 'Ollama (offline)'
989996
OnClick = Gemini1Click
990997
end

0 commit comments

Comments
 (0)
0