-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
ChatGPT.Settings.pas
328 lines (292 loc) · 9.33 KB
/
ChatGPT.Settings.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
unit ChatGPT.Settings;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
ChatGPT.Overlay, FMX.Edit, FMX.Objects, FMX.Layouts, ChatGPT.Classes,
FMX.ComboEdit, FMX.ListBox, FMX.Controls.Presentation, FMX.ComboEdit.Style,
FMX.Memo.Types, FMX.ScrollBox, FMX.Memo;
{$IF DEFINED(ANDROID) OR DEFINED(IOS) OR DEFINED(IOS64)}
{$DEFINE MOBILE}
{$ENDIF}
type
TStyledComboEdit = class(FMX.ComboEdit.Style.TStyledComboEdit)
procedure MouseWheel(Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean); override;
protected
function CreateListBox: TComboEditListBox; override;
end;
TFrameSettings = class(TFrameOveraly)
LayoutClient: TLayout;
RectangleFrame: TRectangle;
Label1: TLabel;
Label3: TLabel;
Label4: TLabel;
Layout2: TLayout;
ButtonCancel: TButton;
ButtonOk: TButton;
Layout3: TLayout;
TrackBarTemp: TTrackBar;
LabelTemp: TLabel;
EditToken: TEdit;
ClearEditButton2: TClearEditButton;
Path1: TPath;
Label5: TLabel;
Label6: TLabel;
Layout4: TLayout;
ButtonGetToken: TButton;
VertScrollBoxContent: TVertScrollBox;
Label8: TLabel;
ComboEditModel: TComboEdit;
Label9: TLabel;
EditMaxTokens: TEdit;
ClearEditButton3: TClearEditButton;
Path2: TPath;
Layout1: TLayout;
TrackBarPP: TTrackBar;
LabelPP: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Layout5: TLayout;
TrackBarFP: TTrackBar;
LabelFP: TLabel;
Label15: TLabel;
Label16: TLabel;
EditQueryMaxToken: TEdit;
ClearEditButton4: TClearEditButton;
Path3: TPath;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
LabelAppearance: TLabel;
Label14: TLabel;
EditOrg: TEdit;
ClearEditButton5: TClearEditButton;
Path5: TPath;
Label20: TLabel;
EditBaseUrl: TEdit;
ClearEditButton6: TClearEditButton;
Path6: TPath;
Label21: TLabel;
Label22: TLabel;
LayoutOnTop: TLayout;
SwitchOnTop: TSwitch;
Label23: TLabel;
Label10: TLabel;
Label24: TLabel;
EditProxyServer: TEdit;
ClearEditButton7: TClearEditButton;
Path7: TPath;
Label25: TLabel;
EditProxyPort: TEdit;
ClearEditButton8: TClearEditButton;
Path8: TPath;
EditProxyUsername: TEdit;
ClearEditButton9: TClearEditButton;
Path9: TPath;
Label26: TLabel;
EditProxyPassword: TEdit;
ClearEditButton10: TClearEditButton;
Path10: TPath;
Label27: TLabel;
Label28: TLabel;
Layout6: TLayout;
TrackBarTopP: TTrackBar;
LabelTopP: TLabel;
Label30: TLabel;
Label29: TLabel;
LabelVersion: TLabel;
Label31: TLabel;
Label32: TLabel;
MemoCustomHeaders: TMemo;
Label33: TLabel;
Layout7: TLayout;
SwitchUseFunctions: TSwitch;
Label34: TLabel;
Label35: TLabel;
Label36: TLabel;
Layout8: TLayout;
ButtonLoadedFunctions: TButton;
Layout9: TLayout;
SwitchAutoExecFuncs: TSwitch;
Label37: TLabel;
Layout10: TLayout;
Label2: TLabel;
EditTimeout: TEdit;
ClearEditButton1: TClearEditButton;
Path4: TPath;
Label7: TLabel;
Label38: TLabel;
Layout11: TLayout;
SwitchSendEnter: TSwitch;
Label39: TLabel;
Label40: TLabel;
ALLine1: TLine;
ALLine2: TLine;
procedure TrackBarTempTracking(Sender: TObject);
procedure ButtonCancelClick(Sender: TObject);
procedure ButtonOkClick(Sender: TObject);
procedure ButtonGetTokenClick(Sender: TObject);
procedure FrameResize(Sender: TObject);
procedure RectangleBGClick(Sender: TObject);
procedure TrackBarPPTracking(Sender: TObject);
procedure TrackBarFPTracking(Sender: TObject);
procedure TrackBarTopPTracking(Sender: TObject);
procedure ButtonLoadedFunctionsClick(Sender: TObject);
procedure ComboEditModelMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; var Handled: Boolean);
private
FProcCallback: TProc<TFrameSettings, Boolean>;
FLayoutClientWidth, FLayoutClientHeight: Single;
protected
procedure SetMode(const Value: TWindowMode); override;
public
constructor Create(AOwner: TComponent); override;
procedure Cancel; override;
class procedure Execute(AParent: TControl; ProcSet: TProc<TFrameSettings>; ProcExecuted: TProc<TFrameSettings, Boolean>);
end;
var
FrameSettings: TFrameSettings;
implementation
uses
System.Math, FMX.Ani, FMX.Presentation.Style, FMX.Presentation.Factory,
HGM.FMX.Ani, ChatGPT.LoadedFunctions, ChatGPT.Manager;
{$R *.fmx}
{ TFrameSettings }
procedure TFrameSettings.ButtonCancelClick(Sender: TObject);
begin
Cancel;
end;
procedure TFrameSettings.ButtonGetTokenClick(Sender: TObject);
begin
OpenUrl('https://platform.openai.com/account/api-keys');
end;
procedure TFrameSettings.ButtonLoadedFunctionsClick(Sender: TObject);
begin
TFrameLoadedFunctions.Execute(TControl(Parent));
end;
procedure TFrameSettings.ButtonOkClick(Sender: TObject);
begin
if Assigned(FProcCallback) then
FProcCallback(Self, True);
Release;
end;
procedure TFrameSettings.Cancel;
begin
if Assigned(FProcCallback) then
FProcCallback(Self, False);
Release;
end;
procedure TFrameSettings.ComboEditModelMouseWheel(Sender: TObject;
Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
begin
Handled := True;
VertScrollBoxContent.AniCalculations.MouseWheel(0, -WheelDelta);
end;
constructor TFrameSettings.Create(AOwner: TComponent);
begin
inherited;
{$IFDEF MOBILE}
LabelAppearance.Visible := False;
LayoutOnTop.Visible := False;
{$ENDIF}
Name := '';
MemoCustomHeaders.Text := '';
MemoCustomHeaders.Lines.NameValueSeparator := ':';
ComboEditModel.Items.Clear;
var ActualModels: TArray<string> := [];
SetLength(ActualModels, Length(Manager.ActualModels));
for var i := 0 to High(Manager.ActualModels) do
ActualModels[i] := Manager.ActualModels[i].Name;
ComboEditModel.Items.AddStrings(ActualModels);
if ComboEditModel.Presentation is TStyledComboEdit then
begin
var Style := TStyledComboEdit(ComboEditModel.Presentation);
for var i := 0 to Style.ListBox.Count - 1 do
begin
Style.ListBox.ListItems[i].StyleLookup := 'listboxitemstyle_model';
Style.ListBox.ListItems[i].StylesData['context'] := Manager.ActualModels[i].Context.ToString;
Style.ListBox.ListItems[i].StylesData['tokens'] := Manager.ActualModels[i].Tokens.ToString;
Style.ListBox.ListItems[i].StylesData['datadate'] := Manager.ActualModels[i].DataDate;
Style.ListBox.ListItems[i].StylesData['legacy.Visible'] := Manager.ActualModels[i].Legacy;
end;
end;
FLayoutClientWidth := LayoutClient.Width;
FLayoutClientHeight := LayoutClient.Height;
VertScrollBoxContent.AniCalculations.Animation := True;
VertScrollBoxContent.AniCalculations.Interval := 1;
VertScrollBoxContent.ViewportPosition := TPoint.Zero;
end;
class procedure TFrameSettings.Execute(AParent: TControl; ProcSet: TProc<TFrameSettings>; ProcExecuted: TProc<TFrameSettings, Boolean>);
begin
var Frame := TFrameSettings.Create(AParent);
Frame.Parent := AParent;
Frame.FProcCallback := ProcExecuted;
Frame.Align := TAlignLayout.Contents;
Frame.BringToFront;
if Assigned(ProcSet) then
ProcSet(Frame);
Frame.TrackBarTempTracking(nil);
Frame.TrackBarPPTracking(nil);
Frame.TrackBarFPTracking(nil);
Frame.TrackBarTopPTracking(nil);
Frame.ButtonCancel.SetFocus;
end;
procedure TFrameSettings.FrameResize(Sender: TObject);
begin
LayoutClient.Width := Min(FLayoutClientWidth, Width);
LayoutClient.Height := Min(FLayoutClientHeight, Height);
end;
procedure TFrameSettings.RectangleBGClick(Sender: TObject);
begin
Cancel;
end;
procedure TFrameSettings.SetMode(const Value: TWindowMode);
begin
inherited;
if Mode = TWindowMode.Compact then
begin
LayoutClient.Align := TAlignLayout.Client;
RectangleFrame.Corners := [];
end
else
begin
LayoutClient.Align := TAlignLayout.Center;
RectangleFrame.Corners := AllCorners;
end;
FrameResize(nil);
end;
procedure TFrameSettings.TrackBarFPTracking(Sender: TObject);
begin
LabelFP.Text := FormatFloat('0.0', TrackBarFP.Value / 10);
end;
procedure TFrameSettings.TrackBarPPTracking(Sender: TObject);
begin
LabelPP.Text := FormatFloat('0.0', TrackBarPP.Value / 10);
end;
procedure TFrameSettings.TrackBarTempTracking(Sender: TObject);
begin
LabelTemp.Text := FormatFloat('0.0', TrackBarTemp.Value / 10);
end;
procedure TFrameSettings.TrackBarTopPTracking(Sender: TObject);
begin
LabelTopP.Text := FormatFloat('0.0', TrackBarTopP.Value / 10);
end;
{ TStyledComboEdit }
function TStyledComboEdit.CreateListBox: TComboEditListBox;
begin
Result := inherited;
Result.DefaultItemStyles.ItemStyle := 'listboxitemstyle_model';
Result.AniCalculations.Animation := True;
Result.AniCalculations.Interval := 1;
end;
procedure TStyledComboEdit.MouseWheel(Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
begin
Handled := False;
end;
initialization
//TPresentationProxyFactory.Current.Unregister(TComboEdit, TControlType.Styled, TStyledPresentationProxy<FMX.ComboEdit.Style.TStyledComboEdit>);
//TPresentationProxyFactory.Current.Register(TComboEdit, TControlType.Styled, TStyledPresentationProxy<TStyledComboEdit>);
finalization
//TPresentationProxyFactory.Current.Unregister(TComboEdit, TControlType.Styled, TStyledPresentationProxy<TStyledComboEdit>);
end.