Skip to content

Commit 9110b32

Browse files
committed
bk/2024-07-26-0227
1 parent ce478ca commit 9110b32

12 files changed

+313
-85
lines changed

Package/DelphiAIDeveloper.dpk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ contains
4949
DelphiAIDev.MainMenu in '..\Src\MainMenu\DelphiAIDev.MainMenu.pas',
5050
DelphiAIDev.MainMenu.Clicks in '..\Src\MainMenu\DelphiAIDev.MainMenu.Clicks.pas',
5151
DelphiAIDev.View.About in '..\Src\View\DelphiAIDev.View.About.pas' {DelphiAIDevViewAbout},
52-
Test in '..\Src\Test\Test.pas',
52+
DelphiAIDev.Test in '..\Src\Test\DelphiAIDev.Test.pas',
5353
DelphiAIDev.Settings.View in '..\Src\Settings\DelphiAIDev.Settings.View.pas' {DelphiAIDevSettingsView},
5454
DelphiAIDev.Settings in '..\Src\Settings\DelphiAIDev.Settings.pas',
5555
DelphiAIDev.Chat in '..\Src\Chat\DelphiAIDev.Chat.pas',

Package/DelphiAIDeveloper.dproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
<DCCReference Include="..\Src\View\DelphiAIDev.View.About.pas">
147147
<Form>DelphiAIDevViewAbout</Form>
148148
</DCCReference>
149-
<DCCReference Include="..\Src\Test\Test.pas"/>
149+
<DCCReference Include="..\Src\Test\DelphiAIDev.Test.pas"/>
150150
<DCCReference Include="..\Src\Settings\DelphiAIDev.Settings.View.pas">
151151
<Form>DelphiAIDevSettingsView</Form>
152152
<FormType>dfm</FormType>

Src/AI/DelphiAIDev.AI.ChatGPT.pas

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

4040
function TDelphiAIDevAIChatGPT.GetResponse(const AQuestion: string): string;
4141
var
42-
LApiUrl: string;
4342
LQuestion: string;
4443
LResponse: IResponse;
4544
LJsonValueAll: TJSONValue;
@@ -51,11 +50,10 @@ function TDelphiAIDevAIChatGPT.GetResponse(const AQuestion: string): string;
5150
LItemChoices: Integer;
5251
begin
5352
Result := '';
54-
LApiUrl := FSettings.BaseUrlOpenAI;
5553
LQuestion := TUtils.AdjustQuestionToJson(AQuestion); //AQuestion.Replace(sLineBreak, '\n', [rfReplaceAll, rfIgnoreCase]);
5654

5755
LResponse := TRequest.New
58-
.BaseURL(LApiUrl)
56+
.BaseURL(FSettings.BaseUrlOpenAI)
5957
.ContentType('application/json')
6058
.Accept('application/json')
6159
.Token('Bearer ' + FSettings.ApiKeyOpenAI)

Src/AI/DelphiAIDev.AI.Groq.pas

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

4040
function TDelphiAIDevAIGroq.GetResponse(const AQuestion: string): string;
4141
var
42-
LApiUrl: string;
4342
LQuestion: string;
4443
LResponse: IResponse;
4544
LJsonValueAll: TJSONVALUE;
@@ -49,18 +48,14 @@ function TDelphiAIDevAIGroq.GetResponse(const AQuestion: string): string;
4948
LItemChoices: Integer;
5049
begin
5150
Result := '';
52-
//LApiUrl := FSettings.BaseUrlGemini + FSettings.ModelGemini + '?key=' + FSettings.ApiKeyGemini;
53-
LApiUrl := 'https://api.groq.com/openai/v1/chat/completions';
5451
LQuestion := TUtils.AdjustQuestionToJson(AQuestion);
5552

5653
LResponse := TRequest.New
57-
.BaseURL(LApiUrl)
54+
.BaseURL(FSettings.BaseUrlGroq)
5855
.ContentType('application/json')
5956
.Accept('application/json')
60-
//.Token('Bearer ' + FSettings.ApiKeyOpenAI)
61-
.Token('Bearer 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')
62-
//.AddBody(Format(API_JSON_BODY_BASE, [FSettings.ModelOpenAI, LQuestion]))
63-
.AddBody(Format(API_JSON_BODY_BASE, [LQuestion, 'Llama3-8b-8192']))
57+
.Token('Bearer ' + FSettings.ApiKeyGroq)
58+
.AddBody(Format(API_JSON_BODY_BASE, [LQuestion, FSettings.ModelGroq]))
6459
.Post;
6560

6661
if LResponse.StatusCode <> 200 then

Src/Consts/DelphiAIDev.Consts.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ TConsts = class
2525
BASE_URL_GEMINI_DEFAULT = 'https://generativelanguage.googleapis.com/';
2626
MODEL_GEMINI_DEFAULT = 'v1/models/gemini-1.5-flash:generateContent';
2727
BASE_URL_OPEN_AI = 'https://api.openai.com/v1/chat/completions/';
28-
API_AI_TIMEOUT_DEFAULT = 20;
28+
BASE_URL_GROQ = 'https://api.groq.com/openai/v1/chat/completions';
2929

3030
//NAMES FILES .INI
3131
FILE_INI_GENERAL_SETTINGS = 'delphi-ai-developer.ini';

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface
1414
type
1515
TDelphiAIDevIDEShortcuts = class(TNotifierObject, IOTAKeyboardBinding)
1616
private
17-
procedure KeyProcBlockReturn(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
17+
//procedure KeyProcBlockReturn(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
1818
procedure KeyProcBlockReturnAndAlt(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
1919
protected
2020
function GetBindingType: TBindingType;
@@ -38,8 +38,8 @@ implementation
3838

3939
procedure RegisterSelf;
4040
begin
41-
// if Index < 0 then
42-
// Index := TUtilsOTA.GetIOTAKeyboardServices.AddKeyboardBinding(TDelphiAIDevIDEShortcuts.New);
41+
if Index < 0 then
42+
Index := TUtilsOTA.GetIOTAKeyboardServices.AddKeyboardBinding(TDelphiAIDevIDEShortcuts.New);
4343
end;
4444

4545
procedure UnRegisterSelf;
@@ -79,36 +79,41 @@ function TDelphiAIDevIDEShortcuts.GetName: string;
7979

8080
procedure TDelphiAIDevIDEShortcuts.BindKeyboard(const BindingServices: IOTAKeyBindingServices);
8181
begin
82-
if TUtilsOTA.CurrentProjectIsDelphiAIDeveloperDPROJ then
83-
Exit;
82+
// if TUtilsOTA.CurrentProjectIsDelphiAIDeveloperDPROJ then
83+
// Exit;
8484

85-
Exit;
86-
BindingServices.AddKeyBinding([Shortcut(VK_RETURN, [])], Self.KeyProcBlockReturn, nil);
85+
//BindingServices.AddKeyBinding([Shortcut(VK_RETURN, [])], Self.KeyProcBlockReturn, nil);
8786
BindingServices.AddKeyBinding([Shortcut(VK_RETURN, [ssAlt])], Self.KeyProcBlockReturnAndAlt, nil);
8887
end;
8988

90-
procedure TDelphiAIDevIDEShortcuts.KeyProcBlockReturn(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
91-
begin
92-
Exit;
93-
94-
TUtils.AddLog(GetCurrentLineOrBlock(CnOtaGetTopMostEditView));
95-
BindingResult := krNextProc; //krUnhandled;
96-
end;
89+
//procedure TDelphiAIDevIDEShortcuts.KeyProcBlockReturn(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
90+
//begin
91+
// if KeyCode <> Shortcut(VK_RETURN, []) then
92+
// Exit;
93+
//
94+
// TUtils.AddLog(GetCurrentLineOrBlock(CnOtaGetTopMostEditView));
95+
// BindingResult := TKeyBindingResult.krNextProc; //krUnhandled;
96+
//end;
9797

9898
procedure TDelphiAIDevIDEShortcuts.KeyProcBlockReturnAndAlt(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
9999
var
100100
LTextCurrentLineOrBlock: string;
101101
begin
102-
//TUtils.AddLog('Enter and Alt' + GetCurrentLineOrBlock(CnOtaGetTopMostEditView));
102+
if KeyCode <> Shortcut(VK_RETURN, [ssAlt]) then
103+
Exit;
103104

104-
LTextCurrentLineOrBlock := GetCurrentLineOrBlock(CnOtaGetTopMostEditView);
105+
//LTextCurrentLineOrBlock := Context.EditBuffer.EditBlock.Text;
106+
LTextCurrentLineOrBlock := GetCurrentLineOrBlock(CnOtaGetTopMostEditView).Trim;
105107
if LTextCurrentLineOrBlock.Trim.IsEmpty then
106108
Exit;
107109

110+
if copy(LTextCurrentLineOrBlock, 1, 2) = '//' then
111+
LTextCurrentLineOrBlock := copy(LTextCurrentLineOrBlock, 3, LTextCurrentLineOrBlock.Length);
112+
108113
DelphiAIDev.Chat.View.DelphiAIDevChatView.QuestionOnShow := LTextCurrentLineOrBlock;
109114
DelphiAIDev.Chat.View.DelphiAIDevChatViewShowDockableForm;
110115

111-
BindingResult := krNextProc; //krUnhandled;
116+
BindingResult := TKeyBindingResult.krUnhandled; //krNextProc;
112117
end;
113118

114119
initialization

0 commit comments

Comments
 (0)