import asyncio
import aiohttp
API_KEY = 'Your ApiKey'
BASE_URL = "https://api.iqqz.com/v1/"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
async def create_completion(session):
try:
async with session.post(
url=f"{BASE_URL}chat/completions",
json={
"model": "gpt-4o",
"max_tokens":4000,
"temperature": 0.5,
# "top_p": 0.5,
"messages": [{"role": "user", "content": "你是谁"}],
},
headers=headers
) as response:
if response.status == 200:
result = await response.json()
# 打印结果
# 请自行处理请求结果的存储。
print(result['choices'][0]['message']['content'])
else:
print(f"请求失败,状态码: {response.status}")
except Exception as e:
print(f"请求发生异常: {e}")
async def main():
max_limits = 2000 # 设置一个合理的并发请求数,请不要超过5000,可以开多个脚本同时跑,效率更高!
async with aiohttp.ClientSession() as session:
while True:
tasks = [create_completion(session) for _ in range(max_limits)]
await asyncio.gather(*tasks)
await asyncio.sleep(1) # 控制请求间隔
if __name__ == "__main__":
asyncio.run(main())