Their purpose in Bakhmut is to draw Russians to attrit. They are somewhere between 7:1 and 10:1 in their favour on losses. That's why they are holding on to Bakhmut. As long as the Russians keep committing forces to the fight, it's worthwhile to stay. I know that sounds crazy and very macabre, but this is sadly how wars are fought.Ukrainian forces need to leave Bakhmut. There insistance to fight at all costs is going to result in either high casualties or a significant number of POWs. Either would be a significant strategic mistake, though I'd argue it already is one given there are no safe routes out of the city.
The Russians have lost so many forces in and around Bakhmut that they are almost certainly opening up gaps elsewhere that will allow for a Ukrainian offensive. Kharkiv 2.0.