Phillies avoid sweep, beat Giants 2-1