That's only a half measure if AI companies ruthlessly consume anything they can get. Microsoft might ignore repo visibility, they can still consume it. OpenAI may have a backdoor by nature of its apps/harnesses running on dev machines that do have copies of your project.
I guess you're safe with a privately self hosted project that you only share with people who don't have any AI and won't reshare it.
Then again, if you even distribute only binaries then in theory the AI could copy those and reverse engineer them, or just mutate the binaries.