Mosquity bits or dunks. If that product isn't in your region, something with "Bti" or 'bacillus thrugeniss (israelis supspecies)" -- i definitely spelled that wrong, but it'll be recognizable. It's a bacteria that will kill most larva in soil/solid substrate. It's a bacteria that;s been used on the world's food crops for a century? i.e. it is safe to use.
larva often comes from the store when you buy a substrate. so using this stuff pre-emptively is a smart thing to do. If you see no hint of gnats after a few weeks you can stop. I leave a dunk in my resesrvoir for the entire grow.
mid-problem, it'll takes 3-4 weeks to get it under control by itself - basaically an entire lifecycle of time and a bit longer. In the meantime you can also use sticky traps and if not in flower, a pesticide-spray becomes an option, too. The adults don't damage anything, so they are annoying but not what is hurting your plant. The larva is chomping on the roots. Killing adults reduces reproduction, which is good, though. Either way, it'll take 3 weeks or more.