System Settings > General > Software Update <click>. If your Mac is not compatible with Sonoma, then there will be an entry for Ventura 13.6.7.
If there is an upgrade offered for Sonoma 14.5, scroll down and you will see Another Update is available, and that link will offer Ventura 13.6.7. When you select that for installation, it will not install Sonoma (if offered). After you have installed Ventura 13.6.7, wait a couple of hours and repeat the software update process. There may be another update available which will be Safari 17.5.