
4 changed files with 71 additions and 16 deletions
@ -0,0 +1,39 @@ |
|||
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) |
Loading…
Reference in new issue