【Python】その文章がCHATGPTで作られたか判別するプログラム



1. **必要なライブラリのインストール**
 

pip install openai


2. **Pythonスクリプトの作成**

  import openai

   # OpenAI APIキーを設定
   openai.api_key = 'YOUR_OPENAI_API_KEY'

   def detect_generated_text(text):
       response = openai.Completion.create(
           engine="text-davinci-003",
           prompt=f"Is the following text generated by ChatGPT? {text}",
           max_tokens=60
       )
       return response.choices[0].text.strip()

   text_to_check = "ここに判別したい文章を入力します。"
   result = detect_generated_text(text_to_check)
   print(result)



3. **スクリプトの実行**
 

python script.py

この記事が気に入ったらサポートをしてみませんか?