DEV Community

Xylar
Xylar

Posted on

How I Quickly Detect AI-Generated Content With Python

Ever spent hours trying to figure out if a piece of content was written by a human or AI?

I did. Reviewing articles, essays, or even social media posts manually is tedious, and honestly… I needed a faster way.

Luckily, I found two free tools for quick checks:

Both work well in the browser, but as a programmer, I started thinking: can I automate AI detection using code?


Using Python + OpenAI to Detect AI Content

Even though MyDetector and DeChecker don’t have APIs, we can use OpenAI GPT models to check if content is AI-generated.

Here’s a simple example using Python:

import openai

# Make sure you set your OPENAI_API_KEY in your environment
openai.api_key = "YOUR_OPENAI_API_KEY"

text_to_check = """
Once upon a time, in a world dominated by AI content...
"""

prompt = f"""
Determine if the following text was likely written by AI or a human.
Answer with only "AI-generated" or "Human-written", and explain briefly.

Text:
{text_to_check}
"""

response = openai.ChatCompletion.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are an expert AI content detector."},
        {"role": "user", "content": prompt}
    ],
    temperature=0
)

result = response['choices'][0]['message']['content']
print(result)
Enter fullscreen mode Exit fullscreen mode

This approach lets you automate detection, even without an official API from MyDetector or DeChecker. You can also batch-check multiple texts, integrate with your workflows, or combine it with other AI detection tools.


Why Automate AI Detection?

  • Speed: Process dozens or hundreds of texts in seconds.
  • Scalability: Useful for content teams, educators, or researchers.
  • Flexibility: You can tweak prompts, use different GPT models, or combine with other tools.

Takeaways

  • Manual detection is slow and tedious.
  • Free browser tools like MyDetector and DeChecker are handy.
  • With a little Python + OpenAI API, you can automate AI content detection and integrate it into your workflow.

Try it out and see how quickly you can detect AI-generated text!

Top comments (0)