I have a computer teammate and whenever I am at war, my teammate keeps making peace with the other team.
Can I do something to prevent this? It (of course) always happens just when I'm about to breach city defenses.
Unfortunately, no. Like real life, your allies can back out of your plans at the least convenient times.
I do have one suggestion, but its not ideal. To see how likely your ally is to make peace, try seeing how much they would charge you to make peace in the diplomacy menu. If its a lot, they are probably going to continue the war, and if its only a little or nothing, you probably shouldn't rely on their help.