-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathParameters.py
More file actions
133 lines (119 loc) · 4.56 KB
/
Parameters.py
File metadata and controls
133 lines (119 loc) · 4.56 KB
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
import wx
import json
from Settings import settings
import os
class ParametersDialog(wx.Dialog):
def __init__(self, parent, title):
super(ParametersDialog, self).__init__(parent, title=title, size=(400, 600))
get_parameters()
self.controls = {} # Store controls here to access them later
self.InitUI()
def InitUI(self):
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
scroll_area = wx.ScrolledWindow(panel)
scroll_area.SetScrollbars(1, 1, 1, 1)
scroll_sizer = wx.BoxSizer(wx.VERTICAL)
for key, val in settings.parameters.items():
hbox = wx.BoxSizer(wx.HORIZONTAL)
label = wx.StaticText(
scroll_area, label=key.replace("_", " ").capitalize() + ":"
)
hbox.Add(label, 0, wx.ALL | wx.CENTER, 5)
if isinstance(val["value"], bool):
ctrl = wx.CheckBox(scroll_area)
ctrl.SetValue(val["value"])
elif val["value"] is None:
ctrl = wx.TextCtrl(scroll_area, value="")
elif isinstance(val["value"], int) or isinstance(val["value"], float):
ctrl = wx.TextCtrl(scroll_area, value=str(val["value"]))
else:
ctrl = wx.TextCtrl(
scroll_area,
value=(
", ".join(val["value"])
if isinstance(val["value"], list)
else str(val["value"])
),
)
ctrl.SetName(key) # Use the setting key as the control name
self.controls[key] = ctrl # Add control to the dictionary
hbox.Add(ctrl, 1, wx.EXPAND | wx.ALL, 5)
# Create a hint string and assign it as a tooltip to the control
hint = f"Hint: {val['description']} Range: {val['range']}"
ctrl.SetToolTip(hint)
scroll_sizer.Add(hbox, 0, wx.EXPAND)
scroll_area.SetSizer(scroll_sizer)
vbox.Add(scroll_area, 1, wx.EXPAND | wx.ALL, 10)
ok_button = wx.Button(panel, label="OK", id=wx.ID_OK)
cancel_button = wx.Button(panel, label="Cancel", id=wx.ID_CANCEL)
buttons_hbox = wx.BoxSizer(wx.HORIZONTAL)
buttons_hbox.Add(ok_button, 0, wx.ALL, 5)
buttons_hbox.Add(cancel_button, 0, wx.ALL, 5)
vbox.Add(buttons_hbox, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
panel.SetSizer(vbox)
def save(self):
ints = [
"num_ctx",
"num_predict",
"top_k",
"repeat_last_n",
"mirostat",
"num_keep",
"seed",
"num_gpu",
]
floats = [
"temperature",
"top_p",
"min_p",
"typical_p",
"tfs_z",
"repeat_penalty",
"presence_penalty",
"frequency_penalty",
"mirostat_tau",
"mirostat_eta",
]
for key, ctrl in self.controls.items():
if isinstance(ctrl, wx.CheckBox):
settings.parameters[key]["value"] = ctrl.IsChecked()
else:
value = ctrl.GetValue()
# Convert value back to the appropriate type based on its original type
if value == "":
value = None
elif key in ints:
value = int(value)
elif key in floats:
value = float(value)
elif isinstance(settings.parameters[key]["value"], list):
value = value.split(", ")
if value == [""]:
value = []
settings.parameters[key]["value"] = value
settings.parameters = settings.parameters
def get_parameters():
p = os.path.join(os.path.dirname(__file__), "default-parameters.json")
with open(p) as file:
default = json.load(file)
default = default["parameters"]
if not hasattr(settings, "parameters"):
settings.parameters = default
else:
parameters = settings.parameters
for key, value in default.items():
if key in parameters:
continue
parameters[key] = value
keys = list(parameters.keys())
for key in keys:
if key not in default:
del parameters[key]
settings.parameters = parameters
options = {}
for key, value in settings.parameters.items():
if value["value"] == []:
continue
options[key] = value["value"]
return options