天天看點

python調用chatgpt的API

(357條消息) ChatGPT API調用python和腳本實作_AI架構師易筋的部落格-CSDN部落格

(357條消息) NLP | 打造一個‘OpenAI智能’機器人,隻需要五分鐘_夏天|여름이다的部落格-CSDN部落格

(357條消息) ChatGPT官方API可以搶先體驗了_Coding的葉子的部落格-CSDN部落格

這個是我參考的部落格

1.在你有openai賬号的的前提下(沒有也有很多辦法注冊和在某寶購買),去到這個網站去注冊api-key:

,在https://beta.openai.com/account/api-keys申請你的api keys

代碼:

import openai
openai.api_key = "sk-xxxxxxxxxxxxxxxxxxx"#這裡是你的api-key
def askChatGPT(question):
    prompt = question
    model_engine = "text-davinci-003"

    completions = openai.Completion.create(
        engine=model_engine,
        prompt=prompt,
        max_tokens=1024,
        n=1,
        stop=None,
        temperature=0.5,
    )

    message = completions.choices[0].text
    print(message)
askChatGPT("what is love")
           
python調用chatgpt的API