Skip to content

Commit 029cc90

Browse files
committed
bk/2024-06-24-1119
1 parent 23e7fb3 commit 029cc90

File tree

10 files changed

+103
-43
lines changed

10 files changed

+103
-43
lines changed

Src/AI/DelphiAIDev.AI.ChatGPT.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ constructor TDelphiAIDevAIChatGPT.Create(const ASettings: TDelphiAIDevSettings);
3939

4040
function TDelphiAIDevAIChatGPT.GetResponse(const AQuestion: string): string;
4141
var
42-
LQuestion: string;
4342
LApiUrl: string;
43+
LQuestion: string;
4444
LResponse: IResponse;
4545
LReturnValue: TJSONValue;
4646
LChoicesValue: TJSONValue;
@@ -52,14 +52,14 @@ function TDelphiAIDevAIChatGPT.GetResponse(const AQuestion: string): string;
5252
begin
5353
Result := '';
5454
LApiUrl := FSettings.BaseUrlOpenAI;
55-
LQuestion := AQuestion.Replace(sLineBreak, '\n', [rfReplaceAll, rfIgnoreCase]);
55+
LQuestion := TUtils.AdjustQuestionToJson(AQuestion); //AQuestion.Replace(sLineBreak, '\n', [rfReplaceAll, rfIgnoreCase]);
5656

5757
LResponse := TRequest.New
5858
.BaseURL(LApiUrl)
5959
.ContentType('application/json')
6060
.Accept('application/json')
6161
.Token('Bearer ' + FSettings.ApiKeyOpenAI)
62-
.AddBody(Format(API_JSON_BODY_BASE, [FSettings.ModelOpenAI, LQuestion.Trim]))
62+
.AddBody(Format(API_JSON_BODY_BASE, [FSettings.ModelOpenAI, LQuestion]))
6363
.Post;
6464

6565
if LResponse.StatusCode <> 200 then

Src/AI/DelphiAIDev.AI.Gemini.pas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ constructor TDelphiAIDevAIGemini.Create(const ASettings: TDelphiAIDevSettings);
4040
function TDelphiAIDevAIGemini.GetResponse(const AQuestion: string): string;
4141
var
4242
LApiUrl: string;
43+
LQuestion: string;
4344
LResponse: IResponse;
4445
LJsonValue: TJSONVALUE;
4546
LJsonArray: TJsonArray;
@@ -51,11 +52,12 @@ function TDelphiAIDevAIGemini.GetResponse(const AQuestion: string): string;
5152
begin
5253
Result := '';
5354
LApiUrl := FSettings.BaseUrlGemini + FSettings.ModelGemini + '?key=' + FSettings.ApiKeyGemini;
55+
LQuestion := TUtils.AdjustQuestionToJson(AQuestion);
5456

5557
LResponse := TRequest.New
5658
.BaseURL(LApiUrl)
5759
.Accept('application/json')
58-
.AddBody(Format(API_JSON_BODY_BASE, [AQuestion.Trim]))
60+
.AddBody(Format(API_JSON_BODY_BASE, [LQuestion]))
5961
.Post;
6062

6163
if LResponse.StatusCode <> 200 then

Src/Chat/DelphiAIDev.Chat.View.dfm

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
8181
ShowHint = True
8282
TabOrder = 1
8383
Zoom = 100
84+
ExplicitTop = 12
8485
end
8586
object pnBackQuestion: TPanel
8687
Left = 18
@@ -167,16 +168,16 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
167168
OnClick = btnSendClick
168169
end
169170
object pnBackConfigurableButtons: TPanel
170-
Left = 528
171+
Left = 395
171172
Top = 3
172-
Width = 333
173+
Width = 466
173174
Height = 20
174175
Align = alRight
175176
BevelOuter = bvNone
176177
TabOrder = 1
177178
object btnUseCurrentUnitCode: TButton
178179
AlignWithMargins = True
179-
Left = 128
180+
Left = 261
180181
Top = 0
181182
Width = 205
182183
Height = 20
@@ -191,10 +192,11 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
191192
Images = ImageList1
192193
TabOrder = 0
193194
OnClick = btnUseCurrentUnitCodeClick
195+
ExplicitLeft = 128
194196
end
195197
object btnCodeOnly: TButton
196198
AlignWithMargins = True
197-
Left = 16
199+
Left = 149
198200
Top = 0
199201
Width = 109
200202
Height = 20
@@ -209,6 +211,26 @@ object DelphiAIDevChatView: TDelphiAIDevChatView
209211
Images = ImageList1
210212
TabOrder = 1
211213
OnClick = btnCodeOnlyClick
214+
ExplicitLeft = 16
215+
end
216+
object Button1: TButton
217+
AlignWithMargins = True
218+
Left = 37
219+
Top = 0
220+
Width = 109
221+
Height = 20
222+
Cursor = crHandPoint
223+
Hint = 'Return only code without comments or explanations'
224+
Margins.Top = 0
225+
Margins.Right = 0
226+
Margins.Bottom = 0
227+
Align = alRight
228+
Caption = 'Question '
229+
ImageIndex = 2
230+
Images = ImageList1
231+
TabOrder = 2
232+
OnClick = btnCodeOnlyClick
233+
ExplicitLeft = 16
212234
end
213235
end
214236
end

Src/Chat/DelphiAIDev.Chat.View.pas

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ TDelphiAIDevChatView = class(TDockableForm)
6969
pnBackConfigurableButtons: TPanel;
7070
btnUseCurrentUnitCode: TButton;
7171
btnCodeOnly: TButton;
72+
Button1: TButton;
7273
procedure FormShow(Sender: TObject);
7374
procedure cBoxSizeFontKeyPress(Sender: TObject; var Key: Char);
7475
procedure Cut1Click(Sender: TObject);
@@ -356,8 +357,6 @@ procedure TDelphiAIDevChatView.ProcessSend;
356357

357358
LQuestion := LQuestion + mmQuestion.Lines.Text;
358359

359-
TUtils.ShowMsg(LQuestion);
360-
361360
LTask := TTask.Create(
362361
procedure
363362
begin

Src/IDE/Shortcuts/DelphiAIDev.IDE.Shortcuts.pas

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,23 @@ function TDelphiAIDevIDEShortcuts.GetName: string;
7878

7979
procedure TDelphiAIDevIDEShortcuts.BindKeyboard(const BindingServices: IOTAKeyBindingServices);
8080
begin
81+
if TUtilsOTA.CurrentProjectIsDelphiAIDeveloperDPROJ then
82+
Exit;
83+
8184
BindingServices.AddKeyBinding([Shortcut(VK_RETURN, [])], Self.KeyProcBlockReturn, nil);
8285
BindingServices.AddKeyBinding([Shortcut(VK_RETURN, [ssAlt])], Self.KeyProcBlockReturnAndAlt, nil);
8386
end;
8487

8588
procedure TDelphiAIDevIDEShortcuts.KeyProcBlockReturn(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
8689
begin
8790
TUtils.AddLog(GetCurrentLineOrBlock(CnOtaGetTopMostEditView));
88-
BindingResult := krUnhandled;
91+
BindingResult := krNextProc; //krUnhandled;
8992
end;
9093

9194
procedure TDelphiAIDevIDEShortcuts.KeyProcBlockReturnAndAlt(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
9295
begin
9396
TUtils.AddLog('Enter and Alt' + GetCurrentLineOrBlock(CnOtaGetTopMostEditView));
94-
BindingResult := krUnhandled;
97+
BindingResult := krNextProc; //krUnhandled;
9598
end;
9699
initialization
97100

Src/MainMenu/DelphiAIDev.MainMenu.pas

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ TDelphiAIDevIDEMainMenu = class(TInterfacedObject, IDelphiAIDevIDEMainMenu)
1717
constructor Create;
1818
procedure CreateMenuDelphiAIDeveloperInIDEMenu;
1919
function CreateSubMenu(AName: string; ACaption: string; AOnClick: TNotifyEvent; AImgIndex: Integer = -1; AShortCutStr: string = ''): TMenuItem;
20+
function GetShortCutStrChat: string;
2021
protected
2122
procedure CreateMenus;
2223
public
@@ -62,7 +63,8 @@ procedure TDelphiAIDevIDEMainMenu.CreateMenus;
6263
Self.CreateSubMenu(TConsts.MENU_IDE_CHAT_NAME,
6364
TConsts.MENU_IDE_CHAT_CAPTION,
6465
TDelphiAIDevIDEMainMenuClicks.ChatClick,
65-
TDelphiAIDevIDEImageListMain.GetInstance.ImgIndexMessage
66+
TDelphiAIDevIDEImageListMain.GetInstance.ImgIndexMessage,
67+
Self.GetShortCutStrChat
6668
);
6769

6870
Self.CreateSubMenu('C4DSeparator50', '-', nil);
@@ -126,6 +128,11 @@ function TDelphiAIDevIDEMainMenu.CreateSubMenu(AName: string; ACaption: string;
126128
Result := LMenuItem;
127129
end;
128130

131+
function TDelphiAIDevIDEMainMenu.GetShortCutStrChat: string;
132+
begin
133+
Result := 'Ctrl+Shift+Alt+A';
134+
end;
135+
129136
initialization
130137

131138
finalization

Src/Settings/DelphiAIDev.Settings.View.dfm

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
3737
Left = 18
3838
Top = 12
3939
Width = 80
40-
Height = 13
40+
Height = 18
4141
Cursor = crHandPoint
4242
Margins.Left = 16
4343
Margins.Top = 10
@@ -53,6 +53,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
5353
ShowHint = True
5454
Layout = tlCenter
5555
OnClick = lbRestoreDefaultsClick
56+
ExplicitHeight = 13
5657
end
5758
object btnConfirm: TButton
5859
AlignWithMargins = True
@@ -68,7 +69,6 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
6869
Caption = 'Confirm'
6970
TabOrder = 0
7071
OnClick = btnConfirmClick
71-
ExplicitTop = 3
7272
end
7373
object btnClose: TButton
7474
AlignWithMargins = True
@@ -143,7 +143,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
143143
Height = 13
144144
Caption = 'Model'
145145
end
146-
object lbLink01: TLabel
146+
object lbLinkGemini01: TLabel
147147
Left = 16
148148
Top = 103
149149
Width = 86
@@ -159,9 +159,9 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
159159
ParentFont = False
160160
ParentShowHint = False
161161
ShowHint = True
162-
OnClick = lbLink03Click
162+
OnClick = lbLinkGpt01Click
163163
end
164-
object lbLink02: TLabel
164+
object lbLinkGemini02: TLabel
165165
Left = 128
166166
Top = 103
167167
Width = 72
@@ -177,7 +177,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
177177
ParentFont = False
178178
ParentShowHint = False
179179
ShowHint = True
180-
OnClick = lbLink03Click
180+
OnClick = lbLinkGpt01Click
181181
end
182182
object btnApiKeyGeminiView: TSpeedButton
183183
Left = 582
@@ -218,6 +218,24 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
218218
ShowHint = True
219219
OnClick = btnApiKeyGeminiViewClick
220220
end
221+
object lbLinkGemini03: TLabel
222+
Left = 232
223+
Top = 103
224+
Width = 67
225+
Height = 13
226+
Cursor = crHandPoint
227+
Hint = 'https://ai.google.dev/gemini-api/docs/models/gemini?hl=pt-br'
228+
Caption = 'Gemini Models'
229+
Font.Charset = DEFAULT_CHARSET
230+
Font.Color = clBlue
231+
Font.Height = -11
232+
Font.Name = 'Tahoma'
233+
Font.Style = []
234+
ParentFont = False
235+
ParentShowHint = False
236+
ShowHint = True
237+
OnClick = lbLinkGpt01Click
238+
end
221239
object edtBaseUrlGemini: TEdit
222240
Left = 16
223241
Top = 20
@@ -330,7 +348,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
330348
Height = 13
331349
Caption = 'Model'
332350
end
333-
object lbLink03: TLabel
351+
object lbLinkGpt01: TLabel
334352
Left = 16
335353
Top = 103
336354
Width = 86
@@ -346,7 +364,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
346364
ParentFont = False
347365
ParentShowHint = False
348366
ShowHint = True
349-
OnClick = lbLink03Click
367+
OnClick = lbLinkGpt01Click
350368
end
351369
object btnApiKeyOpenAIView: TSpeedButton
352370
Left = 582
@@ -387,7 +405,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
387405
ShowHint = True
388406
OnClick = btnApiKeyOpenAIViewClick
389407
end
390-
object lbLink04: TLabel
408+
object lbLinkGpt02: TLabel
391409
Left = 128
392410
Top = 103
393411
Width = 72
@@ -403,7 +421,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
403421
ParentFont = False
404422
ParentShowHint = False
405423
ShowHint = True
406-
OnClick = lbLink03Click
424+
OnClick = lbLinkGpt01Click
407425
end
408426
object edtBaseUrlOpenAI: TEdit
409427
Left = 16

Src/Settings/DelphiAIDev.Settings.View.pas

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,34 @@ TDelphiAIDevSettingsView = class(TForm)
3030
Label5: TLabel;
3131
Label6: TLabel;
3232
Label7: TLabel;
33-
lbLink01: TLabel;
33+
lbLinkGemini01: TLabel;
3434
edtBaseUrlGemini: TEdit;
3535
edtApiKeyGemini: TEdit;
3636
cBoxModelGemini: TComboBox;
37-
lbLink02: TLabel;
37+
lbLinkGemini02: TLabel;
3838
GroupBox2: TGroupBox;
3939
gBoxOpenAI: TGroupBox;
4040
pnOpenAIBack: TPanel;
4141
Label1: TLabel;
4242
Label3: TLabel;
4343
Label2: TLabel;
44-
lbLink03: TLabel;
44+
lbLinkGpt01: TLabel;
4545
edtBaseUrlOpenAI: TEdit;
4646
edtApiKeyOpenAI: TEdit;
4747
cBoxModelOpenAI: TComboBox;
4848
Label11: TLabel;
4949
cBoxAIDefault: TComboBox;
5050
btnApiKeyGeminiView: TSpeedButton;
5151
btnApiKeyOpenAIView: TSpeedButton;
52-
lbLink04: TLabel;
52+
lbLinkGpt02: TLabel;
5353
lbRestoreDefaults: TLabel;
5454
ColorBoxColorHighlightCodeDelphi: TColorBox;
5555
ckColorHighlightCodeDelphiUse: TCheckBox;
56+
lbLinkGemini03: TLabel;
5657
procedure FormCreate(Sender: TObject);
5758
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
5859
procedure btnCloseClick(Sender: TObject);
59-
procedure lbLink03Click(Sender: TObject);
60+
procedure lbLinkGpt01Click(Sender: TObject);
6061
procedure FormShow(Sender: TObject);
6162
procedure btnConfirmClick(Sender: TObject);
6263
procedure btnApiKeyGeminiViewClick(Sender: TObject);
@@ -105,12 +106,16 @@ procedure TDelphiAIDevSettingsView.FormClose(Sender: TObject; var Action: TClose
105106
end;
106107

107108
procedure TDelphiAIDevSettingsView.ConfigScreen;
109+
var
110+
LColor: TColor;
108111
begin
109-
lbLink01.Font.Color := TUtilsOTA.ActiveThemeColorLink;
110-
lbLink02.Font.Color := lbLink01.Font.Color;
111-
lbLink03.Font.Color := lbLink01.Font.Color;
112-
lbLink04.Font.Color := lbLink01.Font.Color;
113-
lbRestoreDefaults.Font.Color := lbLink01.Font.Color;
112+
LColor := TUtilsOTA.ActiveThemeColorLink;
113+
lbLinkGemini01.Font.Color := LColor;
114+
lbLinkGemini02.Font.Color := LColor;
115+
lbLinkGemini03.Font.Color := LColor;
116+
lbLinkGpt01.Font.Color := LColor;
117+
lbLinkGpt02.Font.Color := LColor;
118+
lbRestoreDefaults.Font.Color := LColor;
114119
end;
115120

116121
procedure TDelphiAIDevSettingsView.btnApiKeyGeminiViewClick(Sender: TObject);
@@ -141,7 +146,7 @@ procedure TDelphiAIDevSettingsView.FormKeyDown(Sender: TObject; var Key: Word; S
141146
end;
142147
end;
143148

144-
procedure TDelphiAIDevSettingsView.lbLink03Click(Sender: TObject);
149+
procedure TDelphiAIDevSettingsView.lbLinkGpt01Click(Sender: TObject);
145150
begin
146151
//**Several
147152
TUtils.OpenLink(TLabel(Sender).Hint.Trim);

0 commit comments

Comments
 (0)