You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
943 B
28 lines
943 B
import requests
|
|
import json
|
|
|
|
OPENAI_API_KEY = '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'
|
|
|
|
url = "https://api.openai.com/v1/chat/completions"
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
|
}
|
|
data = {
|
|
"model": "gpt-3.5-turbo",
|
|
"messages": [
|
|
{"role": "user", "content": "请帮我改写这句话:在城市发展进程当中,逐渐呈现出一些综合性的大型建筑群。"},
|
|
{"role": "assistant", "content": "随着城市的发展,综合性大型建筑群正在逐渐出现。"},
|
|
{"role": "user", "content": "这句话我不满意,再改一下帮我"}
|
|
],
|
|
"temperature": 0.7
|
|
}
|
|
|
|
response = requests.post(url,
|
|
headers=headers,
|
|
data=json.dumps(data),
|
|
timeout=1000)
|
|
|
|
res = response.json()
|
|
print(res)
|
|
print(res["choices"][0]["message"]["content"])
|