Chatgpt api 多轮对话功能实现

不废话,上代码

import requests
import json

url = "https://api.openai.com/v1/completions"

payload = json.dumps({
  "model": "text-davinci-003",
  "prompt": "日照香炉生紫烟,遥看瀑布挂前川,飞流直下三千尺,疑是银河落九天。这首古诗是谁写的?\n这首古诗是李白所写。\n介绍一下作者\n李白(701年-762年),字太白,号青莲居士,唐朝浪漫主义诗人,被后人誉为“诗仙”。\n详细解释一下这首诗\n这首诗描写的是一幅美丽的自然风景,作者用比喻的手法,把日照香炉生紫烟比作银河,把瀑布挂前川比作银河落九天,把飞流直下三千尺比作银河落九天,表达出大自然的壮丽美景。\n 你模仿这个也写一首",
  "max_tokens": 2048,
  "temperature": 0
})
headers = {
  'Authorization': 'Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload, allow_redirects=False)

print(response.text)

 

猜你喜欢

转载自blog.csdn.net/jxyk2007/article/details/129178659