Doesn't actually count as open source. Per the OSD, you cannot restrict the purpose for which people use the software and still be open source.
If you want to release your code as actual open source but legally restrict what AI companies do with it, use a copyleft license like the GPL. They could still use it for training, but the product of such training may itself fall under the GPL being a derivative work, and the AI corps don't want to touch that legal quagmire. (The GPL continues to be Stallman's brilliant legal aikido at work. Stallman is like that one guy from Final Fantasy Tactics Advance who gives you the power to manipulate the laws to work to your advantage.)
Honestly, it may be time to abandon open source as a concept. There are source-available strategies that cause less social harm than open source, including Coraline Ada Ehmke's "ethical source" and the Sentry project's "fair source" (https://fair.io) models that we can draw inspiration from.
If you want to release your code as actual open source but legally restrict what AI companies do with it, use a copyleft license like the GPL. They could still use it for training, but the product of such training may itself fall under the GPL being a derivative work, and the AI corps don't want to touch that legal quagmire. (The GPL continues to be Stallman's brilliant legal aikido at work. Stallman is like that one guy from Final Fantasy Tactics Advance who gives you the power to manipulate the laws to work to your advantage.)
Honestly, it may be time to abandon open source as a concept. There are source-available strategies that cause less social harm than open source, including Coraline Ada Ehmke's "ethical source" and the Sentry project's "fair source" (https://fair.io) models that we can draw inspiration from.