Fix broken JavaScript in dashboard.html - correct malformed split chip HTML and other syntax errors
Browse files197 unmodified lines19819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533614 unmodified lines3513523533543553563573583593603613623633643653663673688 unmodified lines3773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074086 unmodified lines415416417418419420421245 unmodified lines6676686696706716726736746756765 unmodified lines6826836846856866876886896906916926936941 unmodified line6966976986997007017021 unmodified line7047057067077087097101 unmodified line7127137147157167177181 unmodified line7207217227237247257261 unmodified line7287297307317327337341 unmodified line7367377387397407417421 unmodified line7447457467477487497504 unmodified lines755756757758759760761228 unmodified lines9909919929939949959962 unmodified lines999100010011002100310041005261 unmodified lines126712681269127012711272127312741275127612779 unmodified lines12871288128912901291129212935 unmodified lines12991300130113021303130413051306130713081309131013111312131329 unmodified lines13431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713886 unmodified lines139513961397139813991400140113 unmodified lines14151416141714181419142014211 unmodified line142314241425142614271428142914301431143214331434143514361437143814391440144114427 unmodified lines145014511452145314541455145613 unmodified lines14701471147214731474147514761 unmodified line1478147914801481148214831484148514862 unmodified lines1489149014911492149314941495149614971498149915001501150215033 unmodified lines15071508150915101511151215131 unmodified line15151516151715181519152015211522152315241525152616 unmodified lines154315441545154615471548154915501 unmodified line1552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715786 unmodified lines1585158615871588158915901591159215938 unmodified lines1602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616375 unmodified lines1643164416451646164716481649165016511652165316541655165643 unmodified lines1700170117021703170417051 unmodified line1707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571 unmodified line175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180113 unmodified lines1815181618171818181918201821182218231824182518261827182828 unmodified lines185718581859186018611862186323 unmodified lines1887188818891890189118921893189418951896189734 unmodified lines193219331934193519361937193835 unmodified lines1974197519761977197819791980198119821983198419851986197 unmodified linesborder-radius: 8px;margin-top: 10px;}.debug-panel {background: #f8f9fa;border: 1px solid #dee2e6;border-radius: 8px;padding: 10px;margin-top: 10px;font-family: monospace;font-size: 0.8rem;}/* Dataset Column Mapping Styles */.column-mapping-card {border: 1px solid #e0e0e0;border-radius: 8px;padding: 10px;margin-bottom: 10px;background: #fafafa;}.column-badge {display: inline-block;padding: 4px 12px;border-radius: 20px;font-size: 0.75rem;font-weight: 600;margin: 2px;}.column-badge.text-col { background: #e3f2fd; color: #1565c0; }.column-badge.label-col { background: #f3e5f5; color: #7b1fa2; }.column-badge.id-col { background: #e8f5e9; color: #2e7d32; }/* Prompt Template Builder */.prompt-section {border: 1px solid #dee2e6;border-radius: 8px;margin-bottom: 10px;overflow: hidden;}.prompt-section-header {background: #f8f9fa;padding: 10px 15px;cursor: pointer;display: flex;justify-content: space-between;align-items: center;}.prompt-section-body {padding: 15px;display: none;}.prompt-section-body.show {display: block;}.template-preview {background: #1e1e1e;color: #d4d4d4;font-family: 'Fira Code', monospace;font-size: 0.85rem;padding: 15px;border-radius: 8px;white-space: pre-wrap;max-height: 300px;overflow-y: auto;}.template-preview .system { color: #569cd6; }.template-preview .user { color: #4ec9b0; }.template-preview .assistant { color: #ce9178; }.template-preview .context { color: #dcdcaa; }.template-preview .reasoning { color: #c586c0; }.variable-tag {background: #667eea;color: white;padding: 2px 8px;border-radius: 4px;font-family: monospace;font-size: 0.85rem;cursor: pointer;}.variable-tag:hover {background: #764ba2;}/* Dataset Preview Table */.preview-table {font-size: 0.85rem;}.preview-table th {background: #f8f9fa;position: sticky;top: 0;}.preview-table td {max-width: 200px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}.split-chip {display: inline-block;padding: 4px 12px;border-radius: 20px;font-size: 0.8rem;margin: 2px;cursor: pointer;border: 2px solid transparent;}.split-chip.available { background: #e8f5e9; color: #2e7d32; }.split-chip.selected { border-color: #667eea; background: #667eea; color: white; }.split-chip:hover { border-color: #667eea; }/* Column Selector */.column-selector {display: grid;grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));gap: 10px;}.column-option {border: 1px solid #e0e0e0;border-radius: 8px;padding: 10px;cursor: pointer;transition: all 0.2s;}.column-option:hover {border-color: #667eea;}.column-option.selected {border-color: #667eea;background: #667eea15;}.step-indicator {display: flex;justify-content: center;margin-bottom: 30px;}.step-indicator .step {display: flex;align-items: center;}.step-indicator .step-number {width: 40px;14 unmodified linesbackground: #4caf50;color: white;}.step-indicator .step-label {font-weight: 500;}.step-indicator .step-connector {width: 60px;height: 2px;background: #e0e0e0;margin: 0 10px;}.step-indicator .step-connector.completed {background: #4caf50;}</style></head><body>8 unmodified lines<div class="collapse navbar-collapse" id="navbarNav"><ul class="navbar-nav ms-auto"><li class="nav-item"><a class="nav-link active" href="#" onclick="showSection('dashboard')"><i class="bi bi-speedometer2 me-1"></i>Dashboard</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('new-training')"><i class="bi bi-plus-circle me-1"></i>New Training</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('jobs')"><i class="bi bi-list-task me-1"></i>Jobs</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('models')"><i class="bi bi-box me-1"></i>Models</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('datasets')"><i class="bi bi-database me-1"></i>Datasets</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('settings')"><i class="bi bi-gear me-1"></i>Settings</a></li>6 unmodified lines<div class="container text-center"><h1><i class="bi bi-rocket-takeoff me-3"></i>Train Any Model</h1><p class="lead mb-4">Fine-tune models from HuggingFace Hub with full control over data formatting</p><button class="btn btn-light btn-lg" onclick="showSection('new-training')"><i class="bi bi-plus-circle me-2"></i>Start New Training</button></div>245 unmodified lines<div id="dataset-recommendations" class="mt-3"></div></div><!-- Step 4: Dataset Configuration (Split & Columns) --><div class="mb-4" id="form-step-4" style="display: none;"><h5 class="mb-3"><i class="bi bi-4-circle me-2"></i>Configure Dataset</h5><div id="dataset-config-container"><div class="text-center text-muted py-4"><i class="bi bi-database fs-1 d-block mb-2"></i>5 unmodified lines<!-- Step 5: Prompt Template Configuration --><div class="mb-4" id="form-step-5" style="display: none;"><h5 class="mb-3"><i class="bi bi-5-circle me-2"></i>Configure Prompt Template</h5><div id="prompt-config-container"><!-- Template Preset Selection --><div class="mb-4"><label class="form-label fw-bold">Quick Start: Choose a Template Preset</label><div class="row g-2"><div class="col-md-3"><div class="card task-card" onclick="selectPromptPreset('none')" data-preset="none"><div class="card-body py-2 text-center"><small class="fw-bold">None</small><br>1 unmodified line</div></div></div><div class="col-md-3"><div class="card task-card" onclick="selectPromptPreset('alpaca')" data-preset="alpaca"><div class="card-body py-2 text-center"><small class="fw-bold">Alpaca</small><br>1 unmodified line</div></div></div><div class="col-md-3"><div class="card task-card" onclick="selectPromptPreset('chatml')" data-preset="chatml"><div class="card-body py-2 text-center"><small class="fw-bold">ChatML</small><br>1 unmodified line</div></div></div><div class="col-md-3"><div class="card task-card" onclick="selectPromptPreset('llama3')" data-preset="llama3"><div class="card-body py-2 text-center"><small class="fw-bold">Llama 3</small><br>1 unmodified line</div></div></div><div class="col-md-3"><div class="card task-card" onclick="selectPromptPreset('mistral')" data-preset="mistral"><div class="card-body py-2 text-center"><small class="fw-bold">Mistral</small><br>1 unmodified line</div></div></div><div class="col-md-3"><div class="card task-card" onclick="selectPromptPreset('reasoning')" data-preset="reasoning"><div class="card-body py-2 text-center"><small class="fw-bold">Reasoning</small><br>1 unmodified line</div></div></div><div class="col-md-3"><div class="card task-card" onclick="selectPromptPreset('vicuna')" data-preset="vicuna"><div class="card-body py-2 text-center"><small class="fw-bold">Vicuna</small><br>1 unmodified line</div></div></div><div class="col-md-3"><div class="card task-card" onclick="selectPromptPreset('phi3')" data-preset="phi3"><div class="card-body py-2 text-center"><small class="fw-bold">Phi-3</small><br>4 unmodified lines</div></div><!-- Custom Template Builder --><div class="accordion" id="prompt-accordion"><!-- System Section --><div class="prompt-section">228 unmodified lines<div class="accordion-body"><div class="form-check form-switch mb-3"><input class="form-check-input" type="checkbox" id="use_peft" name="use_peft" checked><label class="form-check-label" for="use_peft">Enable PEFT/LoRA (Recommended for resource-efficient training)</label></div><div id="peft-options"><div class="row g-3">2 unmodified lines<select class="form-select" id="peft_method" name="peft_method"><option value="lora">LoRA</option><option value="adalora">AdaLoRA</option><option value="ia3">IA³</option><option value="prefix_tuning">Prefix Tuning</option></select></div>261 unmodified lineslet datasetSplits = [];let datasetInfo = null;let columnMapping = {};let promptConfig = {};function debug(message, data) {console.log('[DEBUG]', message, data || '');}function showSection(sectionId) {document.querySelectorAll('.section').forEach(s => s.style.display = 'none');9 unmodified linesfor (let i = 1; i <= 6; i++) {const stepEl = document.getElementById('step-' + i);stepEl.classList.remove('active', 'completed');if (i === 1 && selectedTask) stepEl.classList.add('completed');else if (i === 1) stepEl.classList.add('active');else if (i === 2 && selectedModel) stepEl.classList.add('completed');5 unmodified lineselse if (i === 5 && selectedTask) stepEl.classList.add('active');else if (i === 6) stepEl.classList.add('active');}// Update connectorsfor (let i = 1; i <= 5; i++) {const connector = document.getElementById('connector-' + i + '-' + (i+1));const step = document.getElementById('step-' + i);if (step.classList.contains('completed')) {connector.classList.add('completed');} else {connector.classList.remove('completed');}}}29 unmodified linesfunction renderRecentJobs(jobs) {const container = document.getElementById('recent-jobs-list');if (jobs.length === 0) {container.innerHTML = '<div class="text-center text-muted py-4"><i class="bi bi-inbox fs-1 d-block mb-2"></i>No jobs yet</div>';return;}container.innerHTML = jobs.map(job => '<div class="card mb-2 model-card" onclick="showJobDetail(\'' + job.job_id + '\')"><div class="card-body py-2"><div class="row align-items-center"><div class="col-md-4"><strong>' + job.model_name + '</strong><br><small class="text-muted">' + job.dataset_name + '</small></div><div class="col-md-3"><span class="job-status status-' + job.status + '">' + job.status + '</span></div><div class="col-md-3"><div class="progress" style="height: 20px;"><div class="progress-bar" style="width: ' + job.progress + '%">' + job.progress.toFixed(0) + '%</div></div></div><div class="col-md-2 text-end"><small class="text-muted">' + formatDate(job.created_at) + '</small></div></div></div></div>').join('');}function selectTask(task) {selectedTask = task;document.querySelectorAll('.task-card').forEach(card => card.classList.remove('selected'));document.querySelector('.task-card[data-task="' + task + '"]').classList.add('selected');document.getElementById('selected-task').value = task;updateStepIndicator();loadRecommendations();// Show prompt configurationdocument.getElementById('form-step-5').style.display = 'block';}async function loadRecommendations() {if (!selectedTask) return;try {const modelRecRes = await fetch(API_BASE + '/models/recommend/' + selectedTask);if (modelRecRes.ok) {const modelRecs = await modelRecRes.json();const modelContainer = document.getElementById('model-recommendations');if (modelRecs && modelRecs.length > 0) {modelContainer.innerHTML = '<h6 class="mb-2">Recommended Models:</h6><div class="row g-2">' +modelRecs.slice(0, 4).map(m => '<div class="col-md-3"><div class="card task-card" onclick="selectModel(\'' + m.model_id + '\')"><div class="card-body py-2"><small class="fw-bold">' + m.model_id + '</small><br><small class="text-muted">VRAM: ' + (m.estimated_vram || 'N/A') + '</small></div></div></div>').join('') + '</div>';}}const datasetRecRes = await fetch(API_BASE + '/datasets/recommend/' + selectedTask);if (datasetRecRes.ok) {const datasetRecs = await datasetRecRes.json();const datasetContainer = document.getElementById('dataset-recommendations');if (datasetRecs && datasetRecs.length > 0) {datasetContainer.innerHTML = '<h6 class="mb-2">Recommended Datasets:</h6><div class="row g-2">' +datasetRecs.slice(0, 4).map(d => '<div class="col-md-3"><div class="card task-card" onclick="selectDataset(\'' + d.dataset_id + '\')"><div class="card-body py-2"><small class="fw-bold">' + d.dataset_id + '</small><br><small class="text-muted">' + (d.size || '') + '</small></div></div></div>').join('') + '</div>';}}} catch (error) {6 unmodified linesif (!query) return;const container = document.getElementById('model-results');container.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary"></div></div>';try {const res = await fetch(API_BASE + '/models/search?query=' + encodeURIComponent(query) + '&limit=12');if (!res.ok) throw new Error('Search failed');13 unmodified linescontainer.innerHTML = models.slice(0, 12).map(model => {const id = model.id || model.model_id || model.modelId || 'unknown';const downloads = model.downloads || 0;return '<div class="col-md-3"><div class="card task-card" onclick="selectModel(\'' + id + '\')"><div class="card-body py-2"><small class="fw-bold text-truncate d-block">' + id + '</small><small class="text-muted">' + downloads.toLocaleString() + ' downloads</small></div></div></div>';}).join('');}1 unmodified lineselectedModel = modelId;document.getElementById('selected-model').value = modelId;document.querySelectorAll('#model-results .task-card').forEach(card => card.classList.remove('selected'));if (event.currentTarget) event.currentTarget.classList.add('selected');updateStepIndicator();const container = document.getElementById('model-info');container.style.display = 'block';container.innerHTML = '<div class="card"><div class="card-body">Loading model info...</div></div>';try {const res = await fetch(API_BASE + '/models/info/' + encodeURIComponent(modelId));if (res.ok) {const info = await res.json();container.innerHTML = '<div class="card"><div class="card-body"><h6>' + (info.id || modelId) + '</h6>' +'<div class="row"><div class="col-6"><small class="text-muted">Downloads:</small></div><div class="col-6 text-end"><small>' + (info.downloads?.toLocaleString() || 'N/A') + '</small></div></div>' +'<div class="row"><div class="col-6"><small class="text-muted">Pipeline:</small></div><div class="col-6 text-end"><small>' + (info.pipeline_tag || 'N/A') + '</small></div></div></div></div>';} else {container.innerHTML = '<div class="card"><div class="card-body"><small class="text-muted">Selected: ' + modelId + '</small></div></div>';}7 unmodified linesif (!query) return;const container = document.getElementById('dataset-results');container.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary"></div></div>';try {const res = await fetch(API_BASE + '/datasets/search?query=' + encodeURIComponent(query) + '&limit=12');if (!res.ok) throw new Error('Search failed');13 unmodified linescontainer.innerHTML = datasets.slice(0, 12).map(ds => {const id = ds.id || ds.dataset_id || ds.datasetId || 'unknown';const downloads = ds.downloads || 0;return '<div class="col-md-3"><div class="card task-card" onclick="selectDataset(\'' + id + '\')"><div class="card-body py-2"><small class="fw-bold text-truncate d-block">' + id + '</small><small class="text-muted">' + downloads.toLocaleString() + ' downloads</small></div></div></div>';}).join('');}1 unmodified lineselectedDataset = datasetId;document.getElementById('selected-dataset').value = datasetId;document.querySelectorAll('#dataset-results .task-card').forEach(card => card.classList.remove('selected'));if (event.currentTarget) event.currentTarget.classList.add('selected');// Load dataset preview and configurationawait loadDatasetConfig(datasetId);updateStepIndicator();}2 unmodified linesconst container = document.getElementById('dataset-config-container');document.getElementById('form-step-4').style.display = 'block';container.innerHTML = '<div class="text-center"><div class="spinner-border text-primary"></div> Loading dataset structure...</div>';try {const res = await fetch(API_BASE + '/training/dataset/preview/' + encodeURIComponent(datasetId));if (!res.ok) throw new Error('Failed to load dataset');datasetInfo = await res.json();datasetColumns = datasetInfo.columns || [];datasetSplits = datasetInfo.splits || [];renderDatasetConfig();updateColumnVariableTags();} catch (error) {3 unmodified linesfunction renderDatasetConfig() {const container = document.getElementById('dataset-config-container');let html = '<div class="row">';// Splits Section1 unmodified linehtml += '<div class="mb-3"><label class="form-label fw-bold">Training Split</label><div>';datasetSplits.forEach(split => {const isSelected = split === 'train' || split === datasetSplits[0];html += '<span class="split-chip ' + (isSelected ? 'selected' : 'available') + '" onclick="selectSplit(\'train\', \'text" class="form-control" id="val-split-select">';datasetSplits.forEach(split => {html += '<option value="' + split + '">' + split + '</option>';});html += '</select></div>';html += '</div></div></div>';// Column Mapping Sectionhtml += '<div class="col-md-4"><div class="card h-100"><div class="card-header py-2"><i class="bi bi-columns me-2"></i>Map Columns</div><div class="card-body">';16 unmodified lineshtml += '<select class="form-select form-select-sm" id="col-' + role.key + '" onchange="updateColumnMapping(\'' + role.key + '\', this.value)">';html += '<option value="">-- None --</option>';datasetColumns.forEach(col => {const selected = suggested === col.name || col.name.toLowerCase().includes(role.key) ? 'selected' : '';html += '<option value="' + col.name + '" ' + selected + '>' + col.name + '</option>';});html += '</select></div>';});1 unmodified linehtml += '</div></div></div>';// Preview Sectionhtml += '<div class="col-md-4"><div class="card h-100"><div class="card-header py-2"><i class="bi bi-eye me-2"></i>Data Preview</div><div class="card-body" style="max-height: 300px; overflow-y: auto;">';html += '<table class="table table-sm preview-table"><thead><tr>';datasetColumns.slice(0, 5).forEach(col => {html += '<th>' + col.name + '</th>';});html += '</tr></thead><tbody>';(datasetInfo.sample_data || []).slice(0, 5).forEach(row => {html += '<tr>';datasetColumns.slice(0, 5).forEach(col => {let val = row[col.name] || '';if (typeof val === 'object') val = JSON.stringify(val);html += '<td title="' + escapeHtml(val) + '">' + escapeHtml(val.substring(0, 30)) + (val.length > 30 ? '...' : '') + '</td>';});html += '</tr>';});html += '</tbody></table></div></div></div>';html += '</div>';container.innerHTML = html;// Initialize column mapping from suggestions6 unmodified lines});}function escapeHtml(text) {const div = document.createElement('div');div.textContent = text;return div.innerHTML;}8 unmodified linesupdateStepIndicator();}function selectSplit(type, splitName) {// Update UIconst chips = document.querySelectorAll('.split-chip');chips.forEach(chip => chip.classList.remove('selected'));event.target.classList.add('selected');}function updateColumnVariableTags() {// Update variable tags in prompt template sectionsconst sections = ['system', 'context', 'user', 'reasoning', 'assistant'];sections.forEach(section => {const container = document.getElementById(section + '-columns');if (!container) return;let html = '';Object.values(columnMapping).forEach(colName => {html += '<span class="variable-tag" onclick="insertVariable(\'' + section + '\', \'{' + colName + '}\')">{' + colName + '}</span> ';});datasetColumns.forEach(col => {if (!Object.values(columnMapping).includes(col.name)) {html += '<span class="variable-tag" style="background: #999" onclick="insertVariable(\'' + section + '\', \'{' + col.name + '}\')">{' + col.name + '}</span> ';}});container.innerHTML = html || '<small class="text-muted">No columns mapped</small>';});}function insertVariable(section, variable) {const textarea = document.getElementById(section + '-template');const start = textarea.selectionStart;const end = textarea.selectionEnd;const text = textarea.value;5 unmodified linesfunction togglePromptSection(section) {const body = document.getElementById(section + '-body');body.classList.toggle('show');}function selectPromptPreset(preset) {document.querySelectorAll('[data-preset]').forEach(el => el.classList.remove('selected'));document.querySelector('[data-preset="' + preset + '"]').classList.add('selected');// Apply preset configurationconst presets = {none: {system: { enabled: false, template: '', prefix: '', suffix: '' },43 unmodified linesuser: { enabled: true, template: '{question}', prefix: 'Question: ', suffix: '\n\n' },reasoning: { enabled: true, template: '{reasoning}', prefix: 'Reasoning:\n', suffix: '\n\n' },assistant: { enabled: true, template: '{answer}', prefix: 'Answer: ', suffix: '' }}};1 unmodified lineif (config) {['system', 'context', 'user', 'reasoning', 'assistant'].forEach(section => {const secConfig = config[section];document.getElementById(section + '-enabled').checked = secConfig.enabled;document.getElementById(section + '-template').value = secConfig.template;document.getElementById(section + '-prefix').value = secConfig.prefix;document.getElementById(section + '-suffix').value = secConfig.suffix;});}updatePromptPreview();}function updatePromptPreview() {const preview = document.getElementById('template-preview');let html = '';const sections = ['system', 'context', 'user', 'reasoning', 'assistant'];const labels = {system: 'System',context: 'Context',user: 'User',reasoning: 'Reasoning',assistant: 'Assistant'};sections.forEach(section => {const enabled = document.getElementById(section + '-enabled')?.checked;if (!enabled) return;const prefix = document.getElementById(section + '-prefix')?.value || '';const template = document.getElementById(section + '-template')?.value || '';const suffix = document.getElementById(section + '-suffix')?.value || '';if (template || prefix || suffix) {html += '<span class="' + section + '">' + escapeHtml(prefix) + escapeHtml(template) + escapeHtml(suffix) + '</span>\n';}});preview.innerHTML = html || '<span class="text-muted">Configure your prompt template above...</span>';}// Training form submissiondocument.getElementById('training-form').addEventListener('submit', async (e) => {e.preventDefault();if (!selectedTask || !selectedModel || !selectedDataset) {alert('Please complete all required steps');return;}1 unmodified lineconst promptTemplate = {instruction_format: document.querySelector('[data-preset].selected')?.dataset.preset || 'none',system: {enabled: document.getElementById('system-enabled').checked,template: document.getElementById('system-template').value,prefix: document.getElementById('system-prefix').value,suffix: document.getElementById('system-suffix').value},context: {enabled: document.getElementById('context-enabled').checked,template: document.getElementById('context-template').value,prefix: document.getElementById('context-prefix').value,suffix: document.getElementById('context-suffix').value},user: {enabled: document.getElementById('user-enabled').checked,template: document.getElementById('user-template').value,prefix: document.getElementById('user-prefix').value,suffix: document.getElementById('user-suffix').value},reasoning: {enabled: document.getElementById('reasoning-enabled').checked,template: document.getElementById('reasoning-template').value,prefix: document.getElementById('reasoning-prefix').value,suffix: document.getElementById('reasoning-suffix').value},assistant: {enabled: document.getElementById('assistant-enabled').checked,template: document.getElementById('assistant-template').value,prefix: document.getElementById('assistant-prefix').value,suffix: document.getElementById('assistant-suffix').value}};// Get target modulesconst targetModules = [];['q_proj', 'v_proj', 'k_proj', 'o_proj', 'gate_proj', 'up_proj', 'down_proj'].forEach(mod => {if (document.getElementById('mod-' + mod)?.checked) {targetModules.push(mod);}});const formData = {13 unmodified linesbatch_size: parseInt(document.getElementById('batch_size').value),learning_rate: parseFloat(document.getElementById('learning_rate').value),warmup_steps: parseInt(document.getElementById('warmup_steps').value),weight_decay: parseFloat(document.getElementById('weight_decay').value),gradient_accumulation_steps: parseInt(document.getElementById('gradient_accumulation').value),lr_scheduler_type: document.getElementById('lr_scheduler').value,save_steps: parseInt(document.getElementById('save_steps').value),eval_steps: parseInt(document.getElementById('eval_steps').value),max_grad_norm: parseFloat(document.getElementById('max_grad_norm').value),gradient_checkpointing: document.getElementById('gradient_checkpointing').checked,load_best_model_at_end: document.getElementById('load_best_model').checked},peft_config: document.getElementById('use_peft').checked ? {enabled: true,28 unmodified lines});function updateRangeValue(input) {document.getElementById(input.id + '-value').textContent = input.value;}function formatBytes(bytes) {23 unmodified linesfunction renderJobsList(jobs) {const container = document.getElementById('jobs-list');if (jobs.length === 0) {container.innerHTML = '<div class="text-center text-muted py-4"><i class="bi bi-inbox fs-1 d-block mb-2"></i>No jobs yet</div>';return;}container.innerHTML = jobs.map(job => '<div class="card mb-2 model-card" onclick="showJobDetail(\'' + job.job_id + '\')"><div class="card-body"><div class="row align-items-center"><div class="col-md-3"><strong>' + job.model_name + '</strong></div><div class="col-md-3"><span class="job-status status-' + job.status + '">' + job.status + '</span></div><div class="col-md-3"><div class="progress"><div class="progress-bar" style="width: ' + job.progress + '%">' + job.progress.toFixed(0) + '%</div></div></div><div class="col-md-3 text-end"><small class="text-muted">' + formatDate(job.created_at) + '</small></div></div></div></div>').join('');}async function loadPopularModels() {34 unmodified lines}container.innerHTML = models.map(m => {const id = m.id || m.model_id || 'unknown';return '<div class="col-md-3"><div class="card model-card"><div class="card-body"><h6>' + id + '</h6><small class="text-muted">' + (m.downloads || 0).toLocaleString() + ' downloads</small></div></div></div>';}).join('');}35 unmodified lines}container.innerHTML = datasets.map(d => {const id = d.id || d.dataset_id || 'unknown';return '<div class="col-md-3"><div class="card model-card"><div class="card-body"><h6>' + id + '</h6><small class="text-muted">' + (d.downloads || 0).toLocaleString() + ' downloads</small></div></div></div>';}).join('');}function saveSettings() {localStorage.setItem('hf_token', document.getElementById('hf-token').value);localStorage.setItem('wandb_key', document.getElementById('wandb-key').value);alert('Settings saved!');}197 unmodified lines19819920020120220320420520620720820921021121221314 unmodified lines2282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053068 unmodified lines3153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453466 unmodified lines353354355356357358359245 unmodified lines6056066076086096106116126135 unmodified lines6196206216226236246256266276286291 unmodified line6316326336346356366371 unmodified line6396406416426436446451 unmodified line6476486496506516526531 unmodified line6556566576586596606611 unmodified line6636646656666676686691 unmodified line6716726736746756766771 unmodified line6796806816826836846854 unmodified lines690691692693694695696228 unmodified lines9259269279289299309312 unmodified lines934935936937938939940261 unmodified lines1202120312041205120612079 unmodified lines1217121812191220122112225 unmodified lines12281229123012311232123312341235123612371238123912401241124229 unmodified lines1272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713286 unmodified lines13351336133713381339134013 unmodified lines1354135513561357135813591360136113621 unmodified line136413651366136713681369137013711372137313741375137613771378137913801381138213837 unmodified lines13911392139313941395139613 unmodified lines1410141114121413141414151416141714181 unmodified line14201421142214231424142514262 unmodified lines1429143014311432143314341435143614371438143914403 unmodified lines1444144514461447144814491 unmodified line14511452145314541455145614571458145914601461146214631464146516 unmodified lines1482148314841485148614871488148914901 unmodified line149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915206 unmodified lines1527152815291530153115321533153415351536153715381539154015418 unmodified lines15501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915805 unmodified lines1586158715881589159015911592159315941595159615971598159943 unmodified lines16431644164516461647164816491650165116521653165416551 unmodified line165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001 unmodified line17021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174313 unmodified lines1757175817591760176117621763176417651766176717681769177028 unmodified lines1799180018011802180318041805180623 unmodified lines1830183118321833183418351836183718381839184018411842184318441845184618471848184934 unmodified lines1884188518861887188818891890189135 unmodified lines1927192819291930193119321933193419351936193719381939194019411942197 unmodified linesborder-radius: 8px;margin-top: 10px;}.step-indicator {display: flex;justify-content: center;margin-bottom: 30px;flex-wrap: wrap;}.step-indicator .step {display: flex;align-items: center;margin: 5px;}.step-indicator .step-number {width: 40px;14 unmodified linesbackground: #4caf50;color: white;}.step-indicator .step-connector {width: 30px;height: 2px;background: #e0e0e0;margin: 0 5px;}.step-indicator .step-connector.completed {background: #4caf50;}.split-chip {display: inline-block;padding: 6px 14px;border-radius: 20px;font-size: 0.85rem;margin: 3px;cursor: pointer;border: 2px solid transparent;transition: all 0.2s;}.split-chip.available { background: #e8f5e9; color: #2e7d32; }.split-chip.selected { border-color: #667eea; background: #667eea; color: white; }.split-chip:hover { border-color: #667eea; }.variable-tag {background: #667eea;color: white;padding: 3px 10px;border-radius: 4px;font-family: monospace;font-size: 0.8rem;cursor: pointer;margin: 2px;display: inline-block;}.variable-tag:hover {background: #764ba2;}.template-preview {background: #1e1e1e;color: #d4d4d4;font-family: 'Fira Code', monospace;font-size: 0.85rem;padding: 15px;border-radius: 8px;white-space: pre-wrap;max-height: 300px;overflow-y: auto;}.template-preview .system { color: #569cd6; }.template-preview .user { color: #4ec9b0; }.template-preview .assistant { color: #ce9178; }.template-preview .context { color: #dcdcaa; }.template-preview .reasoning { color: #c586c0; }.prompt-section {border: 1px solid #dee2e6;border-radius: 8px;margin-bottom: 10px;overflow: hidden;}.prompt-section-header {background: #f8f9fa;padding: 10px 15px;cursor: pointer;display: flex;justify-content: space-between;align-items: center;}.prompt-section-body {padding: 15px;display: none;}.prompt-section-body.show {display: block;}</style></head><body>8 unmodified lines<div class="collapse navbar-collapse" id="navbarNav"><ul class="navbar-nav ms-auto"><li class="nav-item"><a class="nav-link active" href="#" onclick="showSection('dashboard'); return false;"><i class="bi bi-speedometer2 me-1"></i>Dashboard</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('new-training'); return false;"><i class="bi bi-plus-circle me-1"></i>New Training</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('jobs'); return false;"><i class="bi bi-list-task me-1"></i>Jobs</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('models'); return false;"><i class="bi bi-box me-1"></i>Models</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('datasets'); return false;"><i class="bi bi-database me-1"></i>Datasets</a></li><li class="nav-item"><a class="nav-link" href="#" onclick="showSection('settings'); return false;"><i class="bi bi-gear me-1"></i>Settings</a></li>6 unmodified lines<div class="container text-center"><h1><i class="bi bi-rocket-takeoff me-3"></i>Train Any Model</h1><p class="lead mb-4">Fine-tune models from HuggingFace Hub with full control over data formatting</p><button class="btn btn-light btn-lg" onclick="showSection('new-training'); return false;"><i class="bi bi-plus-circle me-2"></i>Start New Training</button></div>245 unmodified lines<div id="dataset-recommendations" class="mt-3"></div></div><!-- Step 4: Dataset Configuration --><div class="mb-4" id="form-step-4" style="display: none;"><h5 class="mb-3"><i class="bi bi-4-circle me-2"></i>Configure Dataset</h5><div id="dataset-config-container"><div class="text-center text-muted py-4"><i class="bi bi-database fs-1 d-block mb-2"></i>5 unmodified lines<!-- Step 5: Prompt Template Configuration --><div class="mb-4" id="form-step-5" style="display: none;"><h5 class="mb-3"><i class="bi bi-5-circle me-2"></i>Configure Prompt Template</h5><div id="prompt-config-container"><div class="mb-4"><label class="form-label fw-bold">Choose a Template Preset</label><div class="row g-2"><div class="col-md-3 col-6"><div class="card task-card" onclick="selectPromptPreset('none')" data-preset="none"><div class="card-body py-2 text-center"><small class="fw-bold">None</small><br>1 unmodified line</div></div></div><div class="col-md-3 col-6"><div class="card task-card" onclick="selectPromptPreset('alpaca')" data-preset="alpaca"><div class="card-body py-2 text-center"><small class="fw-bold">Alpaca</small><br>1 unmodified line</div></div></div><div class="col-md-3 col-6"><div class="card task-card" onclick="selectPromptPreset('chatml')" data-preset="chatml"><div class="card-body py-2 text-center"><small class="fw-bold">ChatML</small><br>1 unmodified line</div></div></div><div class="col-md-3 col-6"><div class="card task-card" onclick="selectPromptPreset('llama3')" data-preset="llama3"><div class="card-body py-2 text-center"><small class="fw-bold">Llama 3</small><br>1 unmodified line</div></div></div><div class="col-md-3 col-6"><div class="card task-card" onclick="selectPromptPreset('mistral')" data-preset="mistral"><div class="card-body py-2 text-center"><small class="fw-bold">Mistral</small><br>1 unmodified line</div></div></div><div class="col-md-3 col-6"><div class="card task-card" onclick="selectPromptPreset('reasoning')" data-preset="reasoning"><div class="card-body py-2 text-center"><small class="fw-bold">Reasoning</small><br>1 unmodified line</div></div></div><div class="col-md-3 col-6"><div class="card task-card" onclick="selectPromptPreset('vicuna')" data-preset="vicuna"><div class="card-body py-2 text-center"><small class="fw-bold">Vicuna</small><br>1 unmodified line</div></div></div><div class="col-md-3 col-6"><div class="card task-card" onclick="selectPromptPreset('phi3')" data-preset="phi3"><div class="card-body py-2 text-center"><small class="fw-bold">Phi-3</small><br>4 unmodified lines</div></div><!-- Custom Template Sections --><div class="accordion" id="prompt-accordion"><!-- System Section --><div class="prompt-section">228 unmodified lines<div class="accordion-body"><div class="form-check form-switch mb-3"><input class="form-check-input" type="checkbox" id="use_peft" name="use_peft" checked><label class="form-check-label" for="use_peft">Enable PEFT/LoRA (Recommended)</label></div><div id="peft-options"><div class="row g-3">2 unmodified lines<select class="form-select" id="peft_method" name="peft_method"><option value="lora">LoRA</option><option value="adalora">AdaLoRA</option><option value="ia3">IA3</option><option value="prefix_tuning">Prefix Tuning</option></select></div>261 unmodified lineslet datasetSplits = [];let datasetInfo = null;let columnMapping = {};function showSection(sectionId) {document.querySelectorAll('.section').forEach(s => s.style.display = 'none');9 unmodified linesfor (let i = 1; i <= 6; i++) {const stepEl = document.getElementById('step-' + i);stepEl.classList.remove('active', 'completed');if (i === 1 && selectedTask) stepEl.classList.add('completed');else if (i === 1) stepEl.classList.add('active');else if (i === 2 && selectedModel) stepEl.classList.add('completed');5 unmodified lineselse if (i === 5 && selectedTask) stepEl.classList.add('active');else if (i === 6) stepEl.classList.add('active');}for (let i = 1; i <= 5; i++) {const connector = document.getElementById('connector-' + i + '-' + (i+1));const step = document.getElementById('step-' + i);if (connector && step) {if (step.classList.contains('completed')) {connector.classList.add('completed');} else {connector.classList.remove('completed');}}}}29 unmodified linesfunction renderRecentJobs(jobs) {const container = document.getElementById('recent-jobs-list');if (!jobs || jobs.length === 0) {container.innerHTML = '<div class="text-center text-muted py-4"><i class="bi bi-inbox fs-1 d-block mb-2"></i>No jobs yet</div>';return;}container.innerHTML = jobs.map(job =>'<div class="card mb-2 model-card" onclick="showJobDetail(\'' + job.job_id + '\')">' +'<div class="card-body py-2"><div class="row align-items-center">' +'<div class="col-md-4"><strong>' + (job.model_name || job.name || 'Unknown') + '</strong><br>' +'<small class="text-muted">' + (job.dataset_name || '') + '</small></div>' +'<div class="col-md-3"><span class="job-status status-' + job.status + '">' + job.status + '</span></div>' +'<div class="col-md-3"><div class="progress" style="height: 20px;">' +'<div class="progress-bar" style="width: ' + (job.progress || 0) + '%">' + (job.progress || 0).toFixed(0) + '%</div></div></div>' +'<div class="col-md-2 text-end"><small class="text-muted">' + formatDate(job.created_at) + '</small></div>' +'</div></div></div>').join('');}function selectTask(task) {selectedTask = task;document.querySelectorAll('.task-card').forEach(card => card.classList.remove('selected'));const card = document.querySelector('.task-card[data-task="' + task + '"]');if (card) card.classList.add('selected');document.getElementById('selected-task').value = task;updateStepIndicator();loadRecommendations();document.getElementById('form-step-5').style.display = 'block';}async function loadRecommendations() {if (!selectedTask) return;try {const modelRecRes = await fetch(API_BASE + '/models/recommend/' + selectedTask);if (modelRecRes.ok) {const modelRecs = await modelRecRes.json();const container = document.getElementById('model-recommendations');if (modelRecs && modelRecs.length > 0) {container.innerHTML = '<h6 class="mb-2">Recommended Models:</h6><div class="row g-2">' +modelRecs.slice(0, 4).map(m => '<div class="col-md-3"><div class="card task-card" onclick="selectModel(\'' + (m.model_id || m.id) + '\')">' +'<div class="card-body py-2"><small class="fw-bold">' + (m.model_id || m.id) + '</small><br>' +'<small class="text-muted">' + (m.estimated_vram || 'N/A') + '</small></div></div></div>').join('') + '</div>';}}const datasetRecRes = await fetch(API_BASE + '/datasets/recommend/' + selectedTask);if (datasetRecRes.ok) {const datasetRecs = await datasetRecRes.json();const container = document.getElementById('dataset-recommendations');if (datasetRecs && datasetRecs.length > 0) {container.innerHTML = '<h6 class="mb-2">Recommended Datasets:</h6><div class="row g-2">' +datasetRecs.slice(0, 4).map(d => '<div class="col-md-3"><div class="card task-card" onclick="selectDataset(\'' + (d.dataset_id || d.id) + '\')">' +'<div class="card-body py-2"><small class="fw-bold">' + (d.dataset_id || d.id) + '</small><br>' +'<small class="text-muted">' + (d.size || '') + '</small></div></div></div>').join('') + '</div>';}}} catch (error) {6 unmodified linesif (!query) return;const container = document.getElementById('model-results');container.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary"></div></div>';try {const res = await fetch(API_BASE + '/models/search?query=' + encodeURIComponent(query) + '&limit=12');if (!res.ok) throw new Error('Search failed');13 unmodified linescontainer.innerHTML = models.slice(0, 12).map(model => {const id = model.id || model.model_id || model.modelId || 'unknown';const downloads = model.downloads || 0;return '<div class="col-md-3"><div class="card task-card" onclick="selectModel(\'' + id + '\')">' +'<div class="card-body py-2"><small class="fw-bold text-truncate d-block">' + id + '</small>' +'<small class="text-muted">' + downloads.toLocaleString() + ' downloads</small></div></div></div>';}).join('');}1 unmodified lineselectedModel = modelId;document.getElementById('selected-model').value = modelId;document.querySelectorAll('#model-results .task-card').forEach(card => card.classList.remove('selected'));if (event && event.currentTarget) event.currentTarget.classList.add('selected');updateStepIndicator();const container = document.getElementById('model-info');container.style.display = 'block';container.innerHTML = '<div class="card"><div class="card-body">Loading model info...</div></div>';try {const res = await fetch(API_BASE + '/models/info/' + encodeURIComponent(modelId));if (res.ok) {const info = await res.json();container.innerHTML = '<div class="card"><div class="card-body"><h6>' + (info.id || modelId) + '</h6>' +'<div class="row"><div class="col-6"><small class="text-muted">Downloads:</small></div>' +'<div class="col-6 text-end"><small>' + (info.downloads?.toLocaleString() || 'N/A') + '</small></div></div>' +'<div class="row"><div class="col-6"><small class="text-muted">Pipeline:</small></div>' +'<div class="col-6 text-end"><small>' + (info.pipeline_tag || 'N/A') + '</small></div></div></div></div>';} else {container.innerHTML = '<div class="card"><div class="card-body"><small class="text-muted">Selected: ' + modelId + '</small></div></div>';}7 unmodified linesif (!query) return;const container = document.getElementById('dataset-results');container.innerHTML = '<div class="col-12 text-center"><div class="spinner-border text-primary"></div></div>';try {const res = await fetch(API_BASE + '/datasets/search?query=' + encodeURIComponent(query) + '&limit=12');if (!res.ok) throw new Error('Search failed');13 unmodified linescontainer.innerHTML = datasets.slice(0, 12).map(ds => {const id = ds.id || ds.dataset_id || ds.datasetId || 'unknown';const downloads = ds.downloads || 0;return '<div class="col-md-3"><div class="card task-card" onclick="selectDataset(\'' + id + '\')">' +'<div class="card-body py-2"><small class="fw-bold text-truncate d-block">' + id + '</small>' +'<small class="text-muted">' + downloads.toLocaleString() + ' downloads</small></div></div></div>';}).join('');}1 unmodified lineselectedDataset = datasetId;document.getElementById('selected-dataset').value = datasetId;document.querySelectorAll('#dataset-results .task-card').forEach(card => card.classList.remove('selected'));if (event && event.currentTarget) event.currentTarget.classList.add('selected');await loadDatasetConfig(datasetId);updateStepIndicator();}2 unmodified linesconst container = document.getElementById('dataset-config-container');document.getElementById('form-step-4').style.display = 'block';container.innerHTML = '<div class="text-center"><div class="spinner-border text-primary"></div> Loading dataset structure...</div>';try {const res = await fetch(API_BASE + '/training/dataset/preview/' + encodeURIComponent(datasetId));if (!res.ok) throw new Error('Failed to load dataset');datasetInfo = await res.json();datasetColumns = datasetInfo.columns || [];datasetSplits = datasetInfo.splits || [];renderDatasetConfig();updateColumnVariableTags();} catch (error) {3 unmodified linesfunction renderDatasetConfig() {const container = document.getElementById('dataset-config-container');let html = '<div class="row">';// Splits Section1 unmodified linehtml += '<div class="mb-3"><label class="form-label fw-bold">Training Split</label><div>';datasetSplits.forEach(split => {const isSelected = split === 'train' || split === datasetSplits[0];html += '<span class="split-chip ' + (isSelected ? 'selected' : 'available') + '" onclick="selectTrainSplit(\'' + split + '\')">' + split + '</span> ';});html += '</div></div>';html += '<div class="mb-3"><label class="form-label fw-bold">Validation Split</label>';html += '<select class="form-select" id="val-split-select">';datasetSplits.forEach(split => {html += '<option value="' + split + '">' + split + '</option>';});html += '</select></div></div></div></div>';// Column Mapping Sectionhtml += '<div class="col-md-4"><div class="card h-100"><div class="card-header py-2"><i class="bi bi-columns me-2"></i>Map Columns</div><div class="card-body">';16 unmodified lineshtml += '<select class="form-select form-select-sm" id="col-' + role.key + '" onchange="updateColumnMapping(\'' + role.key + '\', this.value)">';html += '<option value="">-- None --</option>';datasetColumns.forEach(col => {const colName = col.name || col;const selected = suggested === colName || colName.toLowerCase().includes(role.key) ? 'selected' : '';html += '<option value="' + colName + '" ' + selected + '>' + colName + '</option>';});html += '</select></div>';});1 unmodified linehtml += '</div></div></div>';// Preview Sectionhtml += '<div class="col-md-4"><div class="card h-100"><div class="card-header py-2"><i class="bi bi-eye me-2"></i>Data Preview</div>';html += '<div class="card-body" style="max-height: 300px; overflow-y: auto;">';html += '<table class="table table-sm table-bordered"><thead><tr>';datasetColumns.slice(0, 5).forEach(col => {const colName = col.name || col;html += '<th>' + colName + '</th>';});html += '</tr></thead><tbody>';const sampleData = datasetInfo.sample_data || [];sampleData.slice(0, 5).forEach(row => {html += '<tr>';datasetColumns.slice(0, 5).forEach(col => {const colName = col.name || col;let val = row[colName] || '';if (typeof val === 'object') val = JSON.stringify(val);if (val.length > 30) val = val.substring(0, 30) + '...';html += '<td>' + escapeHtml(val) + '</td>';});html += '</tr>';});html += '</tbody></table></div></div></div></div>';container.innerHTML = html;// Initialize column mapping from suggestions6 unmodified lines});}function selectTrainSplit(splitName) {document.querySelectorAll('.split-chip').forEach(chip => chip.classList.remove('selected'));if (event && event.target) event.target.classList.add('selected');}function escapeHtml(text) {if (text === null || text === undefined) return '';const div = document.createElement('div');div.textContent = String(text);return div.innerHTML;}8 unmodified linesupdateStepIndicator();}function updateColumnVariableTags() {const sections = ['system', 'context', 'user', 'reasoning', 'assistant'];sections.forEach(section => {const container = document.getElementById(section + '-columns');if (!container) return;let html = '';const mappedCols = Object.values(columnMapping);mappedCols.forEach(colName => {html += '<span class="variable-tag" onclick="insertVariable(\'' + section + '\', \'{' + colName + '}\')">{' + colName + '}</span> ';});if (datasetColumns) {datasetColumns.forEach(col => {const colName = col.name || col;if (!mappedCols.includes(colName)) {html += '<span class="variable-tag" style="background: #999" onclick="insertVariable(\'' + section + '\', \'{' + colName + '}\')">{' + colName + '}</span> ';}});}container.innerHTML = html || '<small class="text-muted">No columns mapped</small>';});}function insertVariable(section, variable) {const textarea = document.getElementById(section + '-template');if (!textarea) return;const start = textarea.selectionStart;const end = textarea.selectionEnd;const text = textarea.value;5 unmodified linesfunction togglePromptSection(section) {const body = document.getElementById(section + '-body');if (body) body.classList.toggle('show');}function selectPromptPreset(preset) {document.querySelectorAll('[data-preset]').forEach(el => el.classList.remove('selected'));const el = document.querySelector('[data-preset="' + preset + '"]');if (el) el.classList.add('selected');const presets = {none: {system: { enabled: false, template: '', prefix: '', suffix: '' },43 unmodified linesuser: { enabled: true, template: '{question}', prefix: 'Question: ', suffix: '\n\n' },reasoning: { enabled: true, template: '{reasoning}', prefix: 'Reasoning:\n', suffix: '\n\n' },assistant: { enabled: true, template: '{answer}', prefix: 'Answer: ', suffix: '' }},phi3: {system: { enabled: true, template: '{system_message}', prefix: '<|system|>\n', suffix: '<|end|>\n' },context: { enabled: false, template: '', prefix: '', suffix: '' },user: { enabled: true, template: '{user_message}', prefix: '<|user|>\n', suffix: '<|end|>\n' },reasoning: { enabled: false, template: '', prefix: '', suffix: '' },assistant: { enabled: true, template: '{assistant_message}', prefix: '<|assistant|>\n', suffix: '<|end|>' }}};1 unmodified lineif (config) {['system', 'context', 'user', 'reasoning', 'assistant'].forEach(section => {const secConfig = config[section];const enabledEl = document.getElementById(section + '-enabled');const templateEl = document.getElementById(section + '-template');const prefixEl = document.getElementById(section + '-prefix');const suffixEl = document.getElementById(section + '-suffix');if (enabledEl) enabledEl.checked = secConfig.enabled;if (templateEl) templateEl.value = secConfig.template;if (prefixEl) prefixEl.value = secConfig.prefix;if (suffixEl) suffixEl.value = secConfig.suffix;});}updatePromptPreview();}function updatePromptPreview() {const preview = document.getElementById('template-preview');let html = '';const sections = ['system', 'context', 'user', 'reasoning', 'assistant'];sections.forEach(section => {const enabledEl = document.getElementById(section + '-enabled');if (!enabledEl || !enabledEl.checked) return;const prefixEl = document.getElementById(section + '-prefix');const templateEl = document.getElementById(section + '-template');const suffixEl = document.getElementById(section + '-suffix');const prefix = prefixEl ? prefixEl.value : '';const template = templateEl ? templateEl.value : '';const suffix = suffixEl ? suffixEl.value : '';if (template || prefix || suffix) {html += '<span class="' + section + '">' + escapeHtml(prefix) + escapeHtml(template) + escapeHtml(suffix) + '</span>\n';}});preview.innerHTML = html || '<span class="text-muted">Configure your prompt template above...</span>';}// Training form submissiondocument.getElementById('training-form').addEventListener('submit', async (e) => {e.preventDefault();if (!selectedTask || !selectedModel || !selectedDataset) {alert('Please complete all required steps: select a task, model, and dataset');return;}1 unmodified lineconst promptTemplate = {instruction_format: document.querySelector('[data-preset].selected')?.dataset.preset || 'none',system: {enabled: document.getElementById('system-enabled')?.checked || false,template: document.getElementById('system-template')?.value || '',prefix: document.getElementById('system-prefix')?.value || '',suffix: document.getElementById('system-suffix')?.value || ''},context: {enabled: document.getElementById('context-enabled')?.checked || false,template: document.getElementById('context-template')?.value || '',prefix: document.getElementById('context-prefix')?.value || '',suffix: document.getElementById('context-suffix')?.value || ''},user: {enabled: document.getElementById('user-enabled')?.checked || false,template: document.getElementById('user-template')?.value || '',prefix: document.getElementById('user-prefix')?.value || '',suffix: document.getElementById('user-suffix')?.value || ''},reasoning: {enabled: document.getElementById('reasoning-enabled')?.checked || false,template: document.getElementById('reasoning-template')?.value || '',prefix: document.getElementById('reasoning-prefix')?.value || '',suffix: document.getElementById('reasoning-suffix')?.value || ''},assistant: {enabled: document.getElementById('assistant-enabled')?.checked || false,template: document.getElementById('assistant-template')?.value || '',prefix: document.getElementById('assistant-prefix')?.value || '',suffix: document.getElementById('assistant-suffix')?.value || ''}};// Get target modulesconst targetModules = [];['q_proj', 'v_proj', 'k_proj', 'o_proj', 'gate_proj', 'up_proj', 'down_proj'].forEach(mod => {const el = document.getElementById('mod-' + mod);if (el && el.checked) targetModules.push(mod);});const formData = {13 unmodified linesbatch_size: parseInt(document.getElementById('batch_size').value),learning_rate: parseFloat(document.getElementById('learning_rate').value),warmup_steps: parseInt(document.getElementById('warmup_steps').value),weight_decay: parseFloat(document.getElementById('weight_decay')?.value || 0.01),gradient_accumulation_steps: parseInt(document.getElementById('gradient_accumulation')?.value || 1),lr_scheduler_type: document.getElementById('lr_scheduler')?.value || 'cosine',save_steps: parseInt(document.getElementById('save_steps')?.value || 500),eval_steps: parseInt(document.getElementById('eval_steps')?.value || 500),max_grad_norm: parseFloat(document.getElementById('max_grad_norm')?.value || 1.0),gradient_checkpointing: document.getElementById('gradient_checkpointing')?.checked || false,load_best_model_at_end: document.getElementById('load_best_model')?.checked || true},peft_config: document.getElementById('use_peft').checked ? {enabled: true,28 unmodified lines});function updateRangeValue(input) {const el = document.getElementById(input.id + '-value');if (el) el.textContent = input.value;}function formatBytes(bytes) {23 unmodified linesfunction renderJobsList(jobs) {const container = document.getElementById('jobs-list');if (!jobs || jobs.length === 0) {container.innerHTML = '<div class="text-center text-muted py-4"><i class="bi bi-inbox fs-1 d-block mb-2"></i>No jobs yet</div>';return;}container.innerHTML = jobs.map(job =>'<div class="card mb-2 model-card" onclick="showJobDetail(\'' + job.job_id + '\')">' +'<div class="card-body"><div class="row align-items-center">' +'<div class="col-md-3"><strong>' + (job.name || 'Unknown') + '</strong></div>' +'<div class="col-md-3"><span class="job-status status-' + job.status + '">' + job.status + '</span></div>' +'<div class="col-md-3"><div class="progress"><div class="progress-bar" style="width: ' + (job.progress || 0) + '%">' +(job.progress || 0).toFixed(0) + '%</div></div></div>' +'<div class="col-md-3 text-end"><small class="text-muted">' + formatDate(job.created_at) + '</small></div>' +'</div></div></div>').join('');}async function loadPopularModels() {34 unmodified lines}container.innerHTML = models.map(m => {const id = m.id || m.model_id || 'unknown';return '<div class="col-md-3"><div class="card model-card"><div class="card-body"><h6>' + id + '</h6>' +'<small class="text-muted">' + (m.downloads || 0).toLocaleString() + ' downloads</small></div></div></div>';}).join('');}35 unmodified lines}container.innerHTML = datasets.map(d => {const id = d.id || d.dataset_id || 'unknown';return '<div class="col-md-3"><div class="card model-card"><div class="card-body"><h6>' + id + '</h6>' +'<small class="text-muted">' + (d.downloads || 0).toLocaleString() + ' downloads</small></div></div></div>';}).join('');}function saveSettings() {const hfToken = document.getElementById('hf-token').value;const wandbKey = document.getElementById('wandb-key').value;localStorage.setItem('hf_token', hfToken);localStorage.setItem('wandb_key', wandbKey);alert('Settings saved!');}
app/templates/dashboard.html+247-291