Skip to content

Commit 238b88f

Browse files
committed
beta 0.8 添加設定
1 parent cc064d4 commit 238b88f

File tree

4 files changed

+228
-11
lines changed

4 files changed

+228
-11
lines changed

src/main/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ ipcMain.handle('open-models-folder', async () => {
402402

403403
ipcMain.handle('start-api-server', async (event, options) => {
404404
try {
405-
const { modelName, apiKey, rpcNodes, ngl, np } = options;
405+
const { modelName, apiKey, rpcNodes, ngl, np, ctxSize, flashAttention, cacheTypeK, cacheTypeV } = options;
406406

407407
if (apiServerProcess) {
408408
return { success: false, message: 'API 伺服器已在運行中' };
@@ -453,6 +453,22 @@ ipcMain.handle('start-api-server', async (event, options) => {
453453
args.push('-np', np.toString());
454454
}
455455

456+
if (ctxSize && ctxSize > 0) {
457+
args.push('--ctx-size', ctxSize.toString());
458+
}
459+
460+
if (flashAttention) {
461+
args.push('-fa');
462+
}
463+
464+
if (cacheTypeK && cacheTypeK !== 'f16') {
465+
args.push('-ctk', cacheTypeK);
466+
}
467+
468+
if (cacheTypeV && cacheTypeV !== 'f16') {
469+
args.push('-ctv', cacheTypeV);
470+
}
471+
456472
console.log('Starting API server with args:', args);
457473
apiServerProcess = spawn(serverPath, args);
458474

src/renderer/app.js

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const elements = {
1717
gpuSlider: document.getElementById('gpu-slider'),
1818
parallelRequests: document.getElementById('parallel-requests'),
1919
parallelSlider: document.getElementById('parallel-slider'),
20+
contextSize: document.getElementById('context-size'),
21+
contextSlider: document.getElementById('context-slider'),
22+
flashAttention: document.getElementById('flash-attention'),
23+
cacheTypeK: document.getElementById('cache-type-k'),
24+
cacheTypeV: document.getElementById('cache-type-v'),
25+
advancedSettingsToggle: document.getElementById('advanced-settings-toggle'),
26+
advancedSettingsContent: document.getElementById('advanced-settings-content'),
2027
mainActionBtn: document.getElementById('main-action-btn'),
2128
themeToggle: document.getElementById('theme-toggle'),
2229
modelsPathBtn: document.getElementById('models-path-btn'),
@@ -439,6 +446,10 @@ async function startApiServer() {
439446
const modelName = elements.modelSelect.value;
440447
const ngl = parseInt(elements.gpuLayers.value) || 0;
441448
const np = parseInt(elements.parallelRequests.value) || 1;
449+
const ctxSize = parseInt(elements.contextSize.value) || 2048;
450+
const flashAttention = elements.flashAttention.checked;
451+
const cacheTypeK = elements.cacheTypeK.value;
452+
const cacheTypeV = elements.cacheTypeV.value;
442453
const apiKey = elements.apiKeyInput.value;
443454

444455
if (!modelName) {
@@ -462,14 +473,22 @@ async function startApiServer() {
462473
apiKey,
463474
rpcNodes: rpcNodes, // 使用過濾後的RPC節點
464475
ngl,
465-
np
476+
np,
477+
ctxSize,
478+
flashAttention,
479+
cacheTypeK,
480+
cacheTypeV
466481
});
467482

468483
if (result.success) {
469484
logMessage('系統', result.message, 'success');
470485
logMessage('系統', `使用模型: ${modelName}`, 'info');
471486
logMessage('系統', `GPU 層數: ${ngl}`, 'info');
472487
logMessage('系統', `並行請求數: ${np}`, 'info');
488+
logMessage('系統', `Context Size: ${ctxSize}`, 'info');
489+
logMessage('系統', `Flash Attention: ${flashAttention ? '啟用' : '停用'}`, 'info');
490+
logMessage('系統', `KV Cache Type K: ${cacheTypeK}`, 'info');
491+
logMessage('系統', `KV Cache Type V: ${cacheTypeV}`, 'info');
473492
logMessage('系統', `RPC節點: ${rpcNodes.join(', ') || '無'}`, 'info');
474493
logMessage('系統', `本機作為API伺服器參與計算`, 'info');
475494
} else {
@@ -505,9 +524,9 @@ function syncGpuControls() {
505524
});
506525

507526
elements.gpuLayers.addEventListener('input', (e) => {
508-
const value = Math.max(0, Math.min(100, parseInt(e.target.value) || 0));
527+
const value = Math.max(0, parseInt(e.target.value) || 0);
509528
elements.gpuLayers.value = value;
510-
elements.gpuSlider.value = value;
529+
elements.gpuSlider.value = Math.min(value, 200); // 滑動條最大值限制為200,但輸入框無限制
511530
});
512531

513532
// 並行請求數控制
@@ -516,9 +535,39 @@ function syncGpuControls() {
516535
});
517536

518537
elements.parallelRequests.addEventListener('input', (e) => {
519-
const value = Math.max(1, Math.min(16, parseInt(e.target.value) || 1));
538+
const value = Math.max(1, parseInt(e.target.value) || 1);
520539
elements.parallelRequests.value = value;
521-
elements.parallelSlider.value = value;
540+
elements.parallelSlider.value = Math.min(value, 100); // 滑動條最大值限制為100,但輸入框無限制
541+
});
542+
543+
// Context Size 控制
544+
elements.contextSlider.addEventListener('input', (e) => {
545+
elements.contextSize.value = e.target.value;
546+
});
547+
548+
elements.contextSize.addEventListener('input', (e) => {
549+
const value = Math.max(512, parseInt(e.target.value) || 2048);
550+
// 確保值是512的倍數
551+
const roundedValue = Math.round(value / 512) * 512;
552+
elements.contextSize.value = roundedValue;
553+
elements.contextSlider.value = Math.min(roundedValue, 131072); // 滑動條最大值限制為128K,但輸入框無限制
554+
});
555+
}
556+
557+
// 設定進階設定摺疊功能
558+
function setupAdvancedSettings() {
559+
elements.advancedSettingsToggle.addEventListener('click', () => {
560+
const header = elements.advancedSettingsToggle;
561+
const content = elements.advancedSettingsContent;
562+
563+
header.classList.toggle('expanded');
564+
content.classList.toggle('expanded');
565+
566+
if (content.classList.contains('expanded')) {
567+
logMessage('系統', '已展開進階設定', 'info');
568+
} else {
569+
logMessage('系統', '已收合進階設定', 'info');
570+
}
522571
});
523572
}
524573

@@ -763,6 +812,9 @@ function setupEventListeners() {
763812
// GPU 控制同步
764813
syncGpuControls();
765814

815+
// 進階設定摺疊功能
816+
setupAdvancedSettings();
817+
766818
// API Key 模態框事件
767819
elements.saveApiKeyBtn.addEventListener('click', saveApiKey);
768820
elements.cancelApiKeyBtn.addEventListener('click', () => {

src/renderer/index.html

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,69 @@ <h2><i class="fas fa-sliders-h"></i> 控制面板</h2>
104104
<div class="control-item">
105105
<label for="gpu-layers">GPU Layers (-ngl)</label>
106106
<div class="slider-container">
107-
<input type="range" id="gpu-slider" min="0" max="100" value="35" class="gpu-slider">
108-
<input type="number" id="gpu-layers" value="35" min="0" max="100" class="gpu-input">
107+
<input type="range" id="gpu-slider" min="0" max="200" value="35" class="gpu-slider">
108+
<input type="number" id="gpu-layers" value="35" min="0" class="gpu-input">
109109
</div>
110110
</div>
111111

112112
<div class="control-item">
113-
<label for="parallel-requests">並行請求數 (-np)</label>
113+
<label for="context-size">Context Size (--ctx-size)</label>
114114
<div class="slider-container">
115-
<input type="range" id="parallel-slider" min="1" max="16" value="1" class="gpu-slider">
116-
<input type="number" id="parallel-requests" value="1" min="1" max="16" class="gpu-input">
115+
<input type="range" id="context-slider" min="512" max="131072" value="2048" step="512" class="gpu-slider">
116+
<input type="number" id="context-size" value="2048" min="512" step="512" class="gpu-input">
117+
</div>
118+
</div>
119+
120+
<!-- 進階設定區域 -->
121+
<div class="advanced-settings">
122+
<div class="advanced-settings-header" id="advanced-settings-toggle">
123+
<h3><i class="fas fa-cogs"></i> 進階設定</h3>
124+
<i class="fas fa-chevron-down toggle-icon"></i>
125+
</div>
126+
<div class="advanced-settings-content" id="advanced-settings-content">
127+
<div class="control-item">
128+
<label for="parallel-requests">並行請求數 (-np)</label>
129+
<div class="slider-container">
130+
<input type="range" id="parallel-slider" min="1" max="100" value="1" class="gpu-slider">
131+
<input type="number" id="parallel-requests" value="1" min="1" class="gpu-input">
132+
</div>
133+
</div>
134+
135+
<div class="control-item">
136+
<label for="flash-attention">
137+
<input type="checkbox" id="flash-attention" class="checkbox-input">
138+
Flash Attention (-fa)
139+
</label>
140+
<div class="control-description">啟用 Flash Attention 以提升性能(預設:停用)</div>
141+
</div>
142+
143+
<div class="control-item">
144+
<label for="cache-type-k">KV Cache Type K (-ctk)</label>
145+
<select id="cache-type-k" class="modern-select">
146+
<option value="f16">f16 (預設)</option>
147+
<option value="f32">f32</option>
148+
<option value="q8_0">q8_0</option>
149+
<option value="q4_0">q4_0</option>
150+
<option value="q4_1">q4_1</option>
151+
<option value="iq4_nl">iq4_nl</option>
152+
<option value="q5_0">q5_0</option>
153+
<option value="q5_1">q5_1</option>
154+
</select>
155+
</div>
156+
157+
<div class="control-item">
158+
<label for="cache-type-v">KV Cache Type V (-ctv)</label>
159+
<select id="cache-type-v" class="modern-select">
160+
<option value="f16">f16 (預設)</option>
161+
<option value="f32">f32</option>
162+
<option value="q8_0">q8_0</option>
163+
<option value="q4_0">q4_0</option>
164+
<option value="q4_1">q4_1</option>
165+
<option value="iq4_nl">iq4_nl</option>
166+
<option value="q5_0">q5_0</option>
167+
<option value="q5_1">q5_1</option>
168+
</select>
169+
</div>
117170
</div>
118171
</div>
119172

src/renderer/styles.css

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,73 @@ body.dark-mode .modern-select:focus {
735735
font-size: 0.9em;
736736
}
737737

738+
/* 進階設定樣式 */
739+
.advanced-settings {
740+
margin-top: 20px;
741+
border: 1px solid #d0d0d0;
742+
border-radius: 8px;
743+
overflow: hidden;
744+
transition: all 0.3s ease;
745+
}
746+
747+
.advanced-settings-header {
748+
display: flex;
749+
justify-content: space-between;
750+
align-items: center;
751+
padding: 15px 20px;
752+
background: #f8f8f8;
753+
cursor: pointer;
754+
transition: all 0.2s ease;
755+
user-select: none;
756+
}
757+
758+
.advanced-settings-header:hover {
759+
background: #e8e8e8;
760+
}
761+
762+
.advanced-settings-header h3 {
763+
margin: 0;
764+
font-size: 16px;
765+
font-weight: 600;
766+
color: #1a1a1a;
767+
display: flex;
768+
align-items: center;
769+
gap: 8px;
770+
}
771+
772+
.toggle-icon {
773+
transition: transform 0.3s ease;
774+
color: #6c757d;
775+
}
776+
777+
.advanced-settings-header.expanded .toggle-icon {
778+
transform: rotate(180deg);
779+
}
780+
781+
.advanced-settings-content {
782+
max-height: 0;
783+
overflow: hidden;
784+
transition: max-height 0.3s ease;
785+
background: #ffffff;
786+
}
787+
788+
.advanced-settings-content.expanded {
789+
max-height: 1000px;
790+
padding: 20px;
791+
}
792+
793+
.control-description {
794+
font-size: 12px;
795+
color: #6c757d;
796+
margin-top: 4px;
797+
font-style: italic;
798+
}
799+
800+
.checkbox-input {
801+
margin-right: 8px;
802+
transform: scale(1.2);
803+
}
804+
738805
.gpu-input:focus {
739806
outline: none;
740807
border-color: #2563eb;
@@ -763,6 +830,35 @@ body.dark-mode .gpu-input:focus {
763830
border-color: #7AA2F7;
764831
}
765832

833+
/* 深色模式進階設定 */
834+
body.dark-mode .advanced-settings {
835+
border: 1px solid #414868;
836+
}
837+
838+
body.dark-mode .advanced-settings-header {
839+
background: #24283B;
840+
}
841+
842+
body.dark-mode .advanced-settings-header:hover {
843+
background: #414868;
844+
}
845+
846+
body.dark-mode .advanced-settings-header h3 {
847+
color: #C0CAF5;
848+
}
849+
850+
body.dark-mode .advanced-settings-content {
851+
background: #1A1B26;
852+
}
853+
854+
body.dark-mode .control-description {
855+
color: #A9B1D6;
856+
}
857+
858+
body.dark-mode .toggle-icon {
859+
color: #A9B1D6;
860+
}
861+
766862
.main-action-btn {
767863
width: 100%;
768864
padding: 16px 22px;

0 commit comments

Comments
 (0)