fix(training): use selected chart and include TA-Lib span sources

This commit is contained in:
Marko Djordjevic 2026-02-18 23:21:23 +01:00
parent 3448c6febd
commit 07064fbf40
6 changed files with 89 additions and 22 deletions

View file

@ -6,6 +6,7 @@ const INFERENCE_API_TIMEOUT = parseInt(process.env.INFERENCE_API_TIMEOUT || '100
const TrainingStartRequestSchema = z.object({
model_type: z.string().min(1, 'model_type must be a non-empty string'),
chart_id: z.number().int().positive().optional(),
});
export async function POST(request: NextRequest) {

View file

@ -856,7 +856,7 @@ export default function Home() {
{/* Training Panel */}
<div className="px-3 py-2 border-b border-sidebar-border">
<TrainingPanel />
<TrainingPanel activeChartId={activeChartId} />
</div>
{/* Predictions */}

View file

@ -27,6 +27,10 @@ interface TrainingRun {
error?: string;
}
interface TrainingPanelProps {
activeChartId: number | null;
}
const MODEL_TYPES = [
{ value: 'random_forest', label: 'Random Forest' },
{ value: 'xgboost', label: 'XGBoost' },
@ -58,7 +62,7 @@ function StatusBadge({ status }: { status: string }) {
);
}
export default function TrainingPanel() {
export default function TrainingPanel({ activeChartId }: TrainingPanelProps) {
const [expanded, setExpanded] = useState(false);
const [modelType, setModelType] = useState('random_forest');
const [datasetInfo, setDatasetInfo] = useState<DatasetInfo | null>(null);
@ -172,13 +176,21 @@ export default function TrainingPanel() {
}, [isTraining, activeRunId, fetchRuns, fetchActiveRun]);
const handleStartTraining = async () => {
if (!activeChartId) {
setStatusMessage({
type: 'error',
text: 'Select a chart before starting training',
});
return;
}
setStatusMessage(null);
setIsTraining(true);
try {
const res = await fetch('/api/training/start', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model_type: modelType }),
body: JSON.stringify({ model_type: modelType, chart_id: activeChartId }),
});
if (res.status === 409) {
@ -227,7 +239,7 @@ export default function TrainingPanel() {
}
};
const canTrain = !isTraining;
const canTrain = !isTraining && !!activeChartId;
return (
<div>
@ -308,6 +320,11 @@ export default function TrainingPanel() {
'Start Training'
)}
</button>
{!activeChartId && (
<p className="text-[10px] text-muted-foreground">
Select a chart to enable training.
</p>
)}
{/* Status message */}
{statusMessage && (