创建界面组件
(self)
| 184 | self.update_log() |
| 185 | |
| 186 | def create_widgets(self): |
| 187 | """创建界面组件""" |
| 188 | style = ttk.Style(theme='flatly') |
| 189 | main_frame = ttk.Frame(self.master) |
| 190 | main_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=5) |
| 191 | |
| 192 | # 配置区域 |
| 193 | config_frame = ttk.LabelFrame(main_frame, text="API配置") |
| 194 | config_frame.grid(row=0, column=0, sticky="nsew", pady=5) |
| 195 | |
| 196 | # 第一行:API地址 |
| 197 | ttk.Label(config_frame, text="API地址:").grid(row=0, column=0, sticky="e", pady=2) |
| 198 | self.api_address = ttk.Entry(config_frame) |
| 199 | self.api_address.grid(row=0, column=1, padx=5, pady=2, sticky="ew", columnspan=2) |
| 200 | |
| 201 | # 第二行:API密钥 |
| 202 | ttk.Label(config_frame, text="API密钥:").grid(row=1, column=0, sticky="e", pady=2) |
| 203 | self.api_key = ttk.Entry(config_frame) |
| 204 | self.api_key.grid(row=1, column=1, padx=5, pady=2, sticky="ew", columnspan=2) |
| 205 | |
| 206 | # 第三行:模型名称(下拉框)及获取模型列表按钮 |
| 207 | ttk.Label(config_frame, text="模型名称:").grid(row=2, column=0, sticky="e", pady=2) |
| 208 | self.model_name = ttk.Combobox(config_frame) |
| 209 | # 初始时下拉框值为空,用户可手动输入 |
| 210 | self.model_name['values'] = [] |
| 211 | self.model_name.set(self.config['model_name']) |
| 212 | self.model_name.grid(row=2, column=1, padx=5, pady=2, sticky="ew") |
| 213 | self.get_models_btn = ttk.Button(config_frame, text="获取模型列表", command=self.fetch_model_list) |
| 214 | self.get_models_btn.grid(row=2, column=2, padx=5, pady=2) |
| 215 | |
| 216 | # 第四行:横向排列“监听端口”、“温度”和“上下文数量” |
| 217 | port_frame = ttk.Frame(config_frame) |
| 218 | port_frame.grid(row=3, column=0, columnspan=3, sticky="w", pady=2) |
| 219 | ttk.Label(port_frame, text="监听端口:").grid(row=0, column=0, padx=(0, 2)) |
| 220 | self.port = ttk.Entry(port_frame, width=8) |
| 221 | self.port.grid(row=0, column=1, padx=(0, 10)) |
| 222 | ttk.Label(port_frame, text="温度:").grid(row=0, column=2, padx=(0, 2)) |
| 223 | self.temperature = ttk.Spinbox(port_frame, from_=0.0, to=1.0, increment=0.1, width=5) |
| 224 | self.temperature.grid(row=0, column=3, padx=(0, 10)) |
| 225 | ttk.Label(port_frame, text="上下文数量:").grid(row=0, column=4, padx=(0, 2)) |
| 226 | self.context_num = ttk.Spinbox(port_frame, from_=0, to=10, width=5) |
| 227 | self.context_num.grid(row=0, column=5) |
| 228 | |
| 229 | # 第五行:系统提示框(放在横排配置项下方) |
| 230 | ttk.Label(config_frame, text="系统提示:").grid(row=4, column=0, sticky="ne", pady=2) |
| 231 | self.system_prompt = scrolledtext.ScrolledText(config_frame, height=8, wrap=tk.WORD) |
| 232 | self.system_prompt.grid(row=4, column=1, padx=5, pady=5, sticky="nsew", columnspan=2) |
| 233 | |
| 234 | # 第六行:前置文本框 |
| 235 | ttk.Label(config_frame, text="前置文本:").grid(row=5, column=0, sticky="e", pady=2) |
| 236 | self.pre_prompt = ttk.Entry(config_frame) |
| 237 | self.pre_prompt.grid(row=5, column=1, padx=5, pady=2, sticky="ew", columnspan=2) |
| 238 | |
| 239 | # 按钮区域 |
| 240 | btn_frame = ttk.Frame(main_frame) |
| 241 | btn_frame.grid(row=1, column=0, pady=5, sticky="ew") |
| 242 | buttons = [ |
| 243 | ('启动服务', self.start_server), |