From f84357df08e4220fc5c4357dbd0b97f38134b0df Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 23 Jan 2025 15:34:25 +0100 Subject: [PATCH] aissist: nicer unit names --- components/aissist/api/aiclient.pas | 6 +++--- components/aissist/api/janai/janai_v1.pas | 4 +--- components/aissist/api/janai/janaiprotocol.pas | 12 +++--------- components/aissist/ide/aissistcontroller.pas | 6 +++--- components/aissist/ide/frmaissistfpdocedit.pas | 5 +++-- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/components/aissist/api/aiclient.pas b/components/aissist/api/aiclient.pas index aa5feb5e0c..08c2c389ba 100644 --- a/components/aissist/api/aiclient.pas +++ b/components/aissist/api/aiclient.pas @@ -90,7 +90,7 @@ Type function CreatePromptRequest(const aModel,aPrompt : string; aMaxResponseLength : Cardinal) : TJSONData; virtual; abstract; // All URLS are relative to the base URL, they MUST NOT start with / function GetAIURL(aURL : TAiUrl) : String; virtual; abstract; - class function protocolname : string; virtual; + class function ProtocolName : string; virtual; class function DefaultURL : String; virtual; property Client : TCustomAIClient Read FClient; end; @@ -217,7 +217,7 @@ begin FClient:=aClient; end; -class function TAIProtocol.protocolname: string; +class function TAIProtocol.ProtocolName: string; begin Result:=ClassName; end; @@ -487,7 +487,7 @@ begin CheckServerURL; json:=Nil; try -// Writeln('Response: ',aResponse.Response.GetContentAsString); + //Writeln('Response: ',aResponse.Response.GetContentAsString); JSON:=GetJSON(aResponse.Response.GetContentAsString); if Protocol.ResponseToPromptResponses(JSON,lResponses) then begin diff --git a/components/aissist/api/janai/janai_v1.pas b/components/aissist/api/janai/janai_v1.pas index fff292fdb1..653bb6a40c 100644 --- a/components/aissist/api/janai/janai_v1.pas +++ b/components/aissist/api/janai/janai_v1.pas @@ -12,7 +12,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **********************************************************************} -unit janai_v1; +unit JanAI_V1; {$mode objfpc}{$H+} @@ -20,10 +20,8 @@ interface uses SysUtils, Classes, fpJSON; - Type - { ----------------------------------------------------------------------- TMessageItem -----------------------------------------------------------------------} diff --git a/components/aissist/api/janai/janaiprotocol.pas b/components/aissist/api/janai/janaiprotocol.pas index df796eb8c5..20b14c1303 100644 --- a/components/aissist/api/janai/janaiprotocol.pas +++ b/components/aissist/api/janai/janaiprotocol.pas @@ -19,12 +19,10 @@ unit JanAIProtocol; interface uses - Classes, SysUtils, aiclient, fpjson; + Classes, SysUtils, fpjson, AIClient, JanAI_V1; type - { TJanAIServer } - { TJanAIServerProtocol } TJanAIServerProtocol = Class(TAIProtocol) @@ -33,18 +31,15 @@ type function ResponseToPromptResponses(aResponse: TJSONData; out Responses: TPromptResponseArray): boolean; override; function ResponseToModels(aResponse: TJSONData; out Models: TModelDataArray): boolean; override; function GetAIURL(aURL: TAIURL): String; override; - class function protocolname : string; override; + class function ProtocolName : string; override; class function DefaultURL : String; override; end; implementation -uses janai_v1; - { TJanAIServerProtocol } - -class function TJanAIServerProtocol.protocolname: string; +class function TJanAIServerProtocol.ProtocolName: string; begin Result:='JanAI'; end; @@ -54,7 +49,6 @@ begin Result:='http://localhost:1337/v1/'; end; - function TJanAIServerProtocol.ResponseToModels(aResponse: TJSONData; out Models: TModelDataArray): boolean; var diff --git a/components/aissist/ide/aissistcontroller.pas b/components/aissist/ide/aissistcontroller.pas index ef904118c3..9c75374444 100644 --- a/components/aissist/ide/aissistcontroller.pas +++ b/components/aissist/ide/aissistcontroller.pas @@ -18,8 +18,8 @@ interface uses Classes, SysUtils, Math, Forms, Dialogs, // ide - SrcEditorIntf, IDEOptionsIntf, IDEOptEditorIntf, BaseIDEIntf, LazIDEintf, IDEHelpIntf, IDEDialogs, - LazConfigStorage, LazLoggerBase, CodeCache, CodeTree, CodeToolManager, PascalParserTool, + SrcEditorIntf, IDEOptEditorIntf, BaseIDEIntf, LazIDEintf, IDEHelpIntf, IDEDialogs, + LazConfigStorage, LazLoggerBase, CodeTree, CodeToolManager, PascalParserTool, PascalReaderTool, // aissist AIClient, JanAIProtocol, @@ -206,7 +206,7 @@ begin if Node<>nil then ProcNode:=Node; - Src:=Tool.ExtractNode(ProcNode,[]); + Src:=copy(Tool.Src,ProcNode.StartPos,ProcNode.EndPos-ProcNode.StartPos); debugln(['TAIssistController.FPDocEditorInsertTextClick ProcNode: Start=',Tool.CleanPosToStr(ProcNode.StartPos),' [',NodePathAsString(ProcNode),'] Src={',Src,'}']); aForm:=TAissistFPDocEditDlg.Create(nil); diff --git a/components/aissist/ide/frmaissistfpdocedit.pas b/components/aissist/ide/frmaissistfpdocedit.pas index 6d66c09cef..6975725714 100644 --- a/components/aissist/ide/frmaissistfpdocedit.pas +++ b/components/aissist/ide/frmaissistfpdocedit.pas @@ -7,7 +7,7 @@ interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, // aissist - AIClient, StrAIssist, FrmAixplain; + AIClient, FrmAixplain, LazLoggerBase; const SDescribeProcPrompt = 'Explain the following function in one sentence:'; @@ -17,7 +17,7 @@ type { TAIssistFPDocEditDlg } TAIssistFPDocEditDlg = class(TAIxplainForm) - procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); + procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); override; procedure FormCreate(Sender: TObject); override; procedure OKButtonClick(Sender: TObject); protected @@ -77,6 +77,7 @@ begin Description:='' else Description:=aResponses[0].Response; + DebugLn(['TAIssistFPDocEditDlg.HandleAIResponse Description="',Description,'"']); end; function TAIssistFPDocEditDlg.Describe(aAIClient: TAIClient; const Src: string; out