-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathoptionsform.pas
131 lines (110 loc) · 4.5 KB
/
optionsform.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
unit OptionsForm;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, Buttons,
StdCtrls, ExtCtrls,IniFiles;
type
{ TSettings }
TSettings = class(TForm)
BitBtnOK: TBitBtn;
BitBtnCancel: TBitBtn;
CheckBoxGPUOffloadCache: TCheckBox;
CheckBoxGPU: TCheckBox;
CheckBoxAutosave: TCheckBox;
ComboBoxThreads: TComboBox;
ComboBoxModels: TComboBox;
ComboBoxGPULayers: TComboBox;
EditPromptPersonalityName: TEdit;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
LabelGPU: TLabel;
LabeledEditTemperature: TLabeledEdit;
LabeledEditK: TLabeledEdit;
LabeledEditP: TLabeledEdit;
LabeledEditMaxLen: TLabeledEdit;
LabeledEditApiKey: TLabeledEdit;
MemoPersonalityDescription: TMemo;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
procedure BitBtnOKClick(Sender: TObject);
procedure CheckBoxGPUChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
IniFile: TIniFile;
end;
var
Settings: TSettings;
implementation
{$R *.lfm}
{ TSettings }
// Initializes settings form components based on values saved in .neurochat.ini file.
procedure TSettings.FormCreate(Sender: TObject);
begin
IniFile := TIniFile.Create(GetUserDir+'/.neurochat.ini');
try
self.CheckBoxAutosave.Checked:=IniFile.ReadBool('Common','autosave',True);
self.LabeledEditTemperature.Text:=FloatToStr(IniFile.ReadFloat('Common','temperature',1.0));
self.LabeledEditK.Text:=IntToStr(IniFile.ReadInteger('Common','top_k',40));
self.LabeledEditP.Text:=FloatToStr(IniFile.ReadFloat('Common','top_p',0.95));
self.LabeledEditMaxLen.Text:=IntToStr(IniFile.ReadInteger('Common','max_new_len',1024));
self.LabeledEditApiKey.Text:=IniFile.ReadString('ChatGPT-API', 'api-key','');
self.ComboBoxModels.Text:=IniFile.ReadString('ChatGPT-API', 'custom-model','');
self.CheckBoxGPU.Checked:=IniFile.ReadBool('local-ai','gpu',False);
self.ComboBoxThreads.Text:=IntToStr(IniFile.ReadInteger('local-ai','threads',4));
self.ComboBoxGPULayers.Text:=IntToStr(IniFile.ReadInteger('local-ai','gpulayers',2048));
self.CheckBoxGPUOffloadCache.Checked:=IniFile.ReadBool('local-ai','gpucache',False);
self.CheckBoxGPUChange(nil);
self.EditPromptPersonalityName.Text:=IniFile.ReadString('Custom-Personality', 'custom-name',self.EditPromptPersonalityName.Text);
self.MemoPersonalityDescription.Text:=IniFile.ReadString('Custom-Personality', 'custom-description',self.MemoPersonalityDescription.Text);
finally
IniFile.Free;
end;
end;
// Writes component properties into corresponding keys inside .neurochat.ini file when BitBtnOK is clicked.
procedure TSettings.BitBtnOKClick(Sender: TObject);
begin
IniFile := TIniFile.Create(GetUserDir+'/.neurochat.ini');
try
IniFile.WriteBool('Common','autosave',self.CheckBoxAutosave.Checked);
IniFile.WriteFloat('Common','temperature',StrToFloatDef(self.LabeledEditTemperature.Text,1.0));
IniFile.WriteInteger('Common','top_k',StrToIntDef(self.LabeledEditK.Text,40));
IniFile.WriteFloat('Common','top_p',StrToFloatDef(self.LabeledEditP.Text,0.95));
IniFile.WriteInteger('Common','max_new_len',StrToIntDef(self.LabeledEditMaxLen.Text,1024));
IniFile.WriteString('ChatGPT-API', 'api-key', self.LabeledEditApiKey.Text);
IniFile.WriteString('ChatGPT-API', 'custom-model',self.ComboBoxModels.Text);
IniFile.WriteBool('local-ai','gpu',self.CheckBoxGPU.Checked);
IniFile.WriteInteger('local-ai','threads',StrToIntDef(self.ComboBoxThreads.Text,4));
IniFile.WriteInteger('local-ai','gpulayers',StrToIntDef(self.ComboBoxGPULayers.Text,2048));
IniFile.WriteBool('local-ai','gpucache',self.CheckBoxGPUOffloadCache.Checked);
IniFile.WriteString('Custom-Personality', 'custom-name', self.EditPromptPersonalityName.Text);
IniFile.WriteString('Custom-Personality', 'custom-description', self.MemoPersonalityDescription.Text);
finally
IniFile.Free;
end;
end;
procedure TSettings.CheckBoxGPUChange(Sender: TObject);
begin
if CheckBoxGPU.State=cbChecked then
begin
self.CheckBoxGPUOffloadCache.Enabled:=True;
self.ComboBoxGPULayers.Enabled:=True;
self.LabelGPU.Enabled:=True;
end
else
begin
self.CheckBoxGPUOffloadCache.Enabled:=False;
self.ComboBoxGPULayers.Enabled:=False;
self.LabelGPU.Enabled:=False;
end
end;
end.