Generation of microwave fields in cavities with laser-excited nonlinear media: competition between the second- and third-order optical nonlinearities