First and foremost, you are allowed to leave an apprenticeship at any moment. It’s the same as if you were in a regular job; your contract will stipulate how much notice you must give your employer if you wish to leave.
However, it is critical to realise that you will not get a certificate if you leave your apprenticeship before it is finished despite possibly completing considerable work. This is something you should consider before making your decision.