[ChatGPT]串接OpenAI ChatGPT API (GPT3.5)

參考網址:

Python
https://vocus.cc/article/6400b9c0fd89780001e8807c

到這裡產生自己的API KEY
https://platform.openai.com/overview

import os
import openai
openai.api_key = f'此處貼上你自己的API KEY'
while True:  
    completion = openai.ChatCompletion.create(
      model="gpt-3.5-turbo",
      messages=[
            {"role": "system", "content": "系統訊息,目前無用"},
            {"role": "assistant", "content": "此處填入機器人訊息"},
            {"role": "user", "content": input("You: ")}
        ]
    )
    print(completion.choices[0].message.content)

 

本篇發表於 程式設計。將永久鏈結加入書籤。