Probably a lot of external and internal factors combined. But the most important would be the smell, eye sight and taste.
Smell can be, I would say 60-70%. When some particles arrive to the smell receptors, htne on the cellular level the receptor gives a "report" to other parts of the bady, especially brain etc. E.g. some seabirds, like storm petrels, recognize the odor of a compound emitted by krill, their main fare.
Almost all birds have great eyes, so this is a great long-distance food check.
But to be honest the taste is also a big issue and I think that all birds go through a phase when they eat everything and after learning what tastes good and bad (with combination of how it look like before they eat it and how it smelled, the infomrmation is stored in the brain.
Even though the birds have problems with complicated thought processes in their brain, I think that they are more than capable of storing and reusing this "good-bad-food" information from their brain.
There could be other factors like e.g. some birds are allergic to some food (yes, animals can be allergic too, even though their immune system is much stronger then ours) and the body will store in the brain to not eat that in the future.