岁月静好

深邃,更古,憧憬,永恒
个人资料
  • 博客访问:
正文

每日学习卡: 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)
评论
目前还没有任何评论
登录后才可评论.