We show how low-energy electronic models derived from the first-principles electronic structure calculations can help to rationalize the magnetic properties of two lacunar spinel compounds GaM4S8 with light (M=V) and heavy (M=Mo) transition-metal elements, which are responsible for different spin-orbit interaction strength. In the model, each magnetic lattice point was associated with the M4S4 molecule, and the model itself was formulated in the basis of molecular Wannier functions constructed for three magnetic t2 bands. The effects of rhombohedral distortion, spin-orbit interaction, band filling, and the screening of Coulomb interactions in the t2 bands are discussed in details. The electronic model is further treated in the superexchange approximation, which allows us to derive an effective spin model for the energy and electric polarization ($P$) depending on the relative orientation of spins in the bonds, and study the properties of this model by means of classical Monte Carlo simulations with the emphasis on the possible formation of the skyrmionic phase. While isotropic exchange interactions clearly dominate in GaV4S8, all types of interactions -- isotropic, antisymmetric, and symmetric anisotropic -- are comparable in the case of GaMo4S8. Particularly, large uniaxial exchange anisotropy has a profound effect on the properties of GaMo4S8. On the one hand, it raises the Curie temperature by opening a gap in the spectrum of magnon excitations. On the other hand, it strongly affects the skyrmionic phase by playing the role of a molecular field, which facilitates the formation of skyrmions, but makes them relatively insensitive to the external magnetic field in the large part of the phase diagram. We predict reversal of the magnetic dependence of $P$ in the case of GaMo4S8 caused by the reversal of direction of the rhombohedral distortion.