remove the power cord, and the battery. let the G5 sit for an hour or so. Battery back in. press the reset button, and do an Open Firmware reset
restart with Apple-Option-O-F
at the prompt, type reset-nvram, and press enter
type set-defaults, and press enter
type reset-all, and press enter.
Hold Option-Apple-P-R during the reboot, until you hear the startup chime 3 times. release the keys, and let it boot normally. reset your time and date if you need to.
If that doesn't control the fans again, then may need service.
Do the fans kick on immediately, or only after the system begins to load?
You may have software problems, and not a problem with the hardware at all. In that case, download and reinstall the current combined updater for your version of OS X.- 10.3.9, or 10.4.8 - whatever you currently have.
If THAT doesn't help, you may need to locate a copy of the Apple Service Diagnostics ver 2.5.8(NOT hardware test), if you know someone.