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.
39 lines
1002 B
39 lines
1002 B
![]()
2 years ago
|
import requests
|
||
|
import json
|
||
|
import time
|
||
|
|
||
|
prompt = "请帮我根据题目为“{}”生成一个论文目录"
|
||
|
def requests_chatgpt(api_key,title):
|
||
|
|
||
|
OPENAI_API_KEY = api_key
|
||
|
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": prompt.format(title)},
|
||
|
],
|
||
|
"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"])
|
||
|
|
||
|
|
||
|
start = time.time()
|
||
|
|
||
|
for i in range(10):
|
||
|
requests_chatgpt("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","大型商业建筑人员疏散设计研究")
|
||
|
|
||
|
end = time.time()
|
||
|
|
||
|
print(end-start)
|