歲月靜好

凡所有相,皆是虛妄,若見諸相非相,則見如來
正文

每日學習卡: ChatGPT api

(2023-05-17 05:34:12) 下一個

Once you have your website set up, you can use the OpenAI API to interact with GPT-4. You'll need to create a POST request to the appropriate endpoint. In Python, this might look something like:

import openai

openai.api_key = 'your-api-key'

response = openai.ChatCompletion.create(
  model="gpt-4.0-turbo",
  messages=[
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Who won the world series in 2020?"},
  ]
)

print(response['choices'][0]['message']['content'])

Replace 'your-api-key' with your actual API key. The messages array in the create method represents the conversation. The "system" role is used to set the behavior of the assistant, and the "user" role represents the user's input.

You can then display this response on your website using your preferred web development language.

https://www.nocode.mba/ai-app-course?refer=twitter&twclid=2-68m1riodvmnqrsdb0x3elwevf

 

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.