02DESIGN & BUILD
The project in practice.
Comparison of machine learning models and LLMs, followed by two integrations in the Next.js starter. An LLM connection through OpenRouter and a linear model trained in Python and exposed through FastAPI. The adviser approves the category before it is saved in PostgreSQL.
- Next.js
- React · JavaScript
- Python
- FastAPI
- scikit-learn
- TF-IDF
- Logistic regression
- OpenRouter
- PostgreSQL
01The need
02The solution
03Everyday use
Project scope.
Model training and evaluation, server-side LLM integration, a Python inference service and a validation flow in the existing Next.js interface.
- Train a linear model
- Text vectorisation with TF-IDF, followed by scikit-learn logistic regression with class weighting. The model is selected using validation macro F1 and evaluated on a separate test set.
- Move from a notebook to the application
- The pipeline is exported with its version and metadata, then loaded when FastAPI starts. Next.js sends text to the Python service. The predicted category, from 18 options, remains a suggestion until confirmation in PostgreSQL.
- Compare with an LLM approach
- Another version connects OpenRouter through an OpenAI-compatible API, with examples in the prompt, a structured response and category validation. The choice between ML and an LLM depends on quality, latency and cost.