Skip to content

Commit 0e70900

Browse files
committed
bk/2024-07-01-2349
1 parent 72b65b8 commit 0e70900

File tree

5 files changed

+238
-102
lines changed

5 files changed

+238
-102
lines changed

Src/Chat/DelphiAIDev.Chat.View.pas

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ TDelphiAIDevChatView = class(TDockableForm)
127127
procedure DoProcessClickInItemDefaultQuestions(ACodeOnly: Boolean; AQuestion: string);
128128
procedure ProcessWordWrap;
129129
procedure ConfScreenOnCreate;
130+
procedure ValidateRegistrationOfSelectedAI;
130131
public
131132
constructor Create(AOwner: TComponent); override;
132133
destructor Destroy; override;
@@ -423,6 +424,8 @@ procedure TDelphiAIDevChatView.ProcessSend;
423424
if mmQuestion.Lines.Text.Trim.IsEmpty then
424425
TUtils.ShowMsgAndAbort('No questions have been added', mmQuestion);
425426

427+
Self.ValidateRegistrationOfSelectedAI;
428+
426429
mmReturn.Lines.Clear;
427430
Self.WaitingFormON;
428431

@@ -432,7 +435,7 @@ procedure TDelphiAIDevChatView.ProcessSend;
432435
LQuestion := TUtilsOTA.GetSelectedBlockOrAllCodeUnit.Trim + sLineBreak;
433436

434437
if btnCodeOnly.ImageIndex = CodeOnly_ImageIndex_ON then
435-
LQuestion := LQuestion + 'Faça a seguinte ação sem adicionar comentários: ' + sLineBreak;
438+
LQuestion := LQuestion + FSettings.LanguageQuestions.GetMsgCodeOnly;
436439

437440
LQuestion := LQuestion + mmQuestion.Lines.Text;
438441

@@ -475,6 +478,37 @@ procedure TDelphiAIDevChatView.ProcessSend;
475478
LTask.Start;
476479
end;
477480

481+
procedure TDelphiAIDevChatView.ValidateRegistrationOfSelectedAI;
482+
const
483+
MSG = '"%s" for IA %s not specified in settings.' + sLineBreak + sLineBreak +
484+
'Access menu > AI Developer > Settings';
485+
begin
486+
case FSettings.AIDefault of
487+
TC4DAIsAvailable.Gemini:
488+
begin
489+
if FSettings.BaseUrlGemini.Trim.IsEmpty then
490+
TUtils.ShowMsgAndAbort(Format(MSG, ['Base URL', 'Gemini']));
491+
492+
if FSettings.ModelGemini.Trim.IsEmpty then
493+
TUtils.ShowMsgAndAbort(Format(MSG, ['Model', 'Gemini']));
494+
495+
if FSettings.ApiKeyGemini.Trim.IsEmpty then
496+
TUtils.ShowMsgAndAbort(Format(MSG, ['API Key', 'Gemini']));
497+
end;
498+
TC4DAIsAvailable.OpenAI:
499+
begin
500+
if FSettings.BaseUrlOpenAI.Trim.IsEmpty then
501+
TUtils.ShowMsgAndAbort(Format(MSG, ['Base URL', 'ChatGPT']));
502+
503+
if FSettings.ModelOpenAI.Trim.IsEmpty then
504+
TUtils.ShowMsgAndAbort(Format(MSG, ['Model', 'ChatGPT']));
505+
506+
if FSettings.ApiKeyOpenAI.Trim.IsEmpty then
507+
TUtils.ShowMsgAndAbort(Format(MSG, ['API Key', 'ChatGPT']));
508+
end;
509+
end;
510+
end;
511+
478512
procedure TDelphiAIDevChatView.AddResponseSimple(const AString: string);
479513
begin
480514
Self.Last;

Src/Settings/DelphiAIDev.Settings.View.dfm

Lines changed: 115 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
22
Left = 0
33
Top = 0
44
Caption = 'Delphi AI Developer - Settings'
5-
ClientHeight = 516
5+
ClientHeight = 537
66
ClientWidth = 632
77
Color = clBtnFace
88
Font.Charset = DEFAULT_CHARSET
@@ -18,100 +18,32 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
1818
OnShow = FormShow
1919
PixelsPerInch = 96
2020
TextHeight = 13
21-
object pnBottom: TPanel
22-
Left = 0
23-
Top = 481
24-
Width = 632
25-
Height = 35
26-
Align = alBottom
27-
BevelEdges = [beLeft, beRight, beBottom]
28-
BevelOuter = bvNone
29-
Padding.Left = 2
30-
Padding.Top = 2
31-
Padding.Right = 2
32-
Padding.Bottom = 2
33-
ParentBackground = False
34-
TabOrder = 0
35-
object lbRestoreDefaults: TLabel
36-
AlignWithMargins = True
37-
Left = 18
38-
Top = 12
39-
Width = 80
40-
Height = 18
41-
Cursor = crHandPoint
42-
Margins.Left = 16
43-
Margins.Top = 10
44-
Align = alLeft
45-
Caption = 'Restore defaults'
46-
Font.Charset = DEFAULT_CHARSET
47-
Font.Color = clBlue
48-
Font.Height = -11
49-
Font.Name = 'Tahoma'
50-
Font.Style = []
51-
ParentFont = False
52-
ParentShowHint = False
53-
ShowHint = True
54-
Layout = tlCenter
55-
OnClick = lbRestoreDefaultsClick
56-
ExplicitHeight = 13
57-
end
58-
object btnConfirm: TButton
59-
AlignWithMargins = True
60-
Left = 404
61-
Top = 2
62-
Width = 110
63-
Height = 31
64-
Cursor = crHandPoint
65-
Margins.Left = 0
66-
Margins.Top = 0
67-
Margins.Bottom = 0
68-
Align = alRight
69-
Caption = 'Confirm'
70-
TabOrder = 0
71-
OnClick = btnConfirmClick
72-
end
73-
object btnClose: TButton
74-
AlignWithMargins = True
75-
Left = 517
76-
Top = 2
77-
Width = 110
78-
Height = 31
79-
Cursor = crHandPoint
80-
Margins.Left = 0
81-
Margins.Top = 0
82-
Margins.Bottom = 0
83-
Align = alRight
84-
Caption = 'Close'
85-
TabOrder = 1
86-
OnClick = btnCloseClick
87-
end
88-
end
89-
object pnlMain: TPanel
21+
object pnBackAll: TPanel
9022
Left = 0
9123
Top = 0
9224
Width = 632
93-
Height = 481
25+
Height = 537
9426
Align = alClient
9527
BevelOuter = bvNone
96-
TabOrder = 1
28+
TabOrder = 0
9729
object pnBody: TPanel
9830
Left = 0
9931
Top = 0
10032
Width = 632
101-
Height = 481
33+
Height = 502
10234
Align = alClient
10335
BevelOuter = bvNone
10436
ParentBackground = False
10537
TabOrder = 0
10638
object gBoxGemini: TGroupBox
10739
Left = 0
108-
Top = 84
40+
Top = 110
10941
Width = 632
11042
Height = 163
11143
Align = alTop
11244
Caption = ' Gemini (Google) '
11345
ParentBackground = False
114-
TabOrder = 0
46+
TabOrder = 1
11547
object pnGeminiBack: TPanel
11648
AlignWithMargins = True
11749
Left = 5
@@ -249,14 +181,14 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
249181
Width = 563
250182
Height = 21
251183
PasswordChar = '*'
252-
TabOrder = 1
184+
TabOrder = 2
253185
end
254186
object cBoxModelGemini: TComboBox
255187
Left = 267
256188
Top = 20
257189
Width = 333
258190
Height = 21
259-
TabOrder = 2
191+
TabOrder = 1
260192
Items.Strings = (
261193
'v1/models/gemini-1.5-flash:generateContent'
262194
'v1beta/models/gemini-pro:generateContent'
@@ -268,49 +200,66 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
268200
Left = 0
269201
Top = 0
270202
Width = 632
271-
Height = 84
203+
Height = 110
272204
Align = alTop
273205
Caption = ' Preferences '
274206
ParentBackground = False
275-
TabOrder = 1
207+
TabOrder = 0
276208
object Label11: TLabel
277-
Left = 17
209+
Left = 272
278210
Top = 23
279211
Width = 48
280212
Height = 13
281213
Caption = 'AI default'
282214
end
215+
object Label4: TLabel
216+
Left = 21
217+
Top = 23
218+
Width = 133
219+
Height = 13
220+
Caption = 'Language used in questions'
221+
end
283222
object cBoxAIDefault: TComboBox
284-
Left = 17
223+
Left = 272
285224
Top = 38
286-
Width = 249
225+
Width = 333
287226
Height = 21
288227
Style = csDropDownList
289-
TabOrder = 0
228+
TabOrder = 1
290229
Items.Strings = (
291-
'Gemini'
292-
'OpenAI (ChatGPT)')
230+
'')
293231
end
294232
object ColorBoxColorHighlightCodeDelphi: TColorBox
295-
Left = 472
296-
Top = 38
233+
Left = 218
234+
Top = 72
297235
Width = 133
298236
Height = 22
299-
TabOrder = 1
237+
TabOrder = 3
300238
end
301239
object ckColorHighlightCodeDelphiUse: TCheckBox
302-
Left = 272
303-
Top = 40
304-
Width = 197
240+
Left = 21
241+
Top = 74
242+
Width = 194
305243
Height = 17
306244
Caption = 'Color to highlight Delphi/Pascal code'
307245
TabOrder = 2
308246
OnClick = ckColorHighlightCodeDelphiUseClick
309247
end
248+
object cBoxLanguageQuestions: TComboBox
249+
Left = 21
250+
Top = 38
251+
Width = 249
252+
Height = 21
253+
Hint = 'What is the standard language for questions?'
254+
Style = csDropDownList
255+
ParentShowHint = False
256+
ShowHint = True
257+
TabOrder = 0
258+
end
310259
end
311260
object gBoxOpenAI: TGroupBox
312261
Left = 0
313-
Top = 247
262+
Top = 273
314263
Width = 632
315264
Height = 163
316265
Align = alTop
@@ -342,7 +291,7 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
342291
Caption = 'API key'
343292
end
344293
object Label2: TLabel
345-
Left = 476
294+
Left = 478
346295
Top = 5
347296
Width = 28
348297
Height = 13
@@ -436,15 +385,15 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
436385
Width = 563
437386
Height = 21
438387
PasswordChar = '*'
439-
TabOrder = 1
388+
TabOrder = 2
440389
end
441390
object cBoxModelOpenAI: TComboBox
442391
Left = 478
443392
Top = 21
444393
Width = 122
445394
Height = 21
446395
Style = csDropDownList
447-
TabOrder = 2
396+
TabOrder = 1
448397
Items.Strings = (
449398
'gpt-3.5-turbo'
450399
'gpt-3.5-turbo-16k'
@@ -454,5 +403,76 @@ object DelphiAIDevSettingsView: TDelphiAIDevSettingsView
454403
end
455404
end
456405
end
406+
object pnBottom: TPanel
407+
Left = 0
408+
Top = 502
409+
Width = 632
410+
Height = 35
411+
Margins.Left = 0
412+
Margins.Top = 0
413+
Margins.Right = 0
414+
Margins.Bottom = 0
415+
Align = alBottom
416+
BevelEdges = [beLeft, beRight, beBottom]
417+
BevelOuter = bvNone
418+
Padding.Top = 2
419+
Padding.Right = 2
420+
Padding.Bottom = 2
421+
ParentBackground = False
422+
TabOrder = 1
423+
object lbRestoreDefaults: TLabel
424+
AlignWithMargins = True
425+
Left = 16
426+
Top = 12
427+
Width = 80
428+
Height = 18
429+
Cursor = crHandPoint
430+
Margins.Left = 16
431+
Margins.Top = 10
432+
Align = alLeft
433+
Caption = 'Restore defaults'
434+
Font.Charset = DEFAULT_CHARSET
435+
Font.Color = clBlue
436+
Font.Height = -11
437+
Font.Name = 'Tahoma'
438+
Font.Style = []
439+
ParentFont = False
440+
ParentShowHint = False
441+
ShowHint = True
442+
Layout = tlCenter
443+
OnClick = lbRestoreDefaultsClick
444+
ExplicitHeight = 13
445+
end
446+
object btnConfirm: TButton
447+
AlignWithMargins = True
448+
Left = 404
449+
Top = 2
450+
Width = 110
451+
Height = 31
452+
Cursor = crHandPoint
453+
Margins.Left = 0
454+
Margins.Top = 0
455+
Margins.Bottom = 0
456+
Align = alRight
457+
Caption = 'Confirm'
458+
TabOrder = 0
459+
OnClick = btnConfirmClick
460+
end
461+
object btnClose: TButton
462+
AlignWithMargins = True
463+
Left = 517
464+
Top = 2
465+
Width = 110
466+
Height = 31
467+
Cursor = crHandPoint
468+
Margins.Left = 0
469+
Margins.Top = 0
470+
Margins.Bottom = 0
471+
Align = alRight
472+
Caption = 'Close'
473+
TabOrder = 1
474+
OnClick = btnCloseClick
475+
end
476+
end
457477
end
458478
end

0 commit comments

Comments
 (0)