uni-api / test /curl.py
yym68686's picture
Support setting whether to poll for each API key separately.
b54a508
raw
history blame
1.07 kB
import json
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from main import load_config
provider_name = "linuxdoi"
model = "claude-3-5-sonnet"
config, api_keys_db, api_list = load_config()
providers = config["providers"]
provider_config = None
for provider in providers:
if provider["provider"] == provider_name:
provider_config = provider
break
if provider_config == None:
print("Provider not found")
sys.exit(1)
model_name = provider_config["model"][model]
# 定义请求的内容
request_content = {
"model": model_name,
"messages": [
{"role": "user", "content": {"text": "What is the meaning of life?"}}
],
"stream": True
}
# 将请求内容转换为JSON字符串
request_json = json.dumps(request_content)
# 定义curl命令
curl_command = f"""
curl {provider_config["base_url"]} \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer {provider_config['api']}" \\
-d '{request_json}'
"""
# 打印生成的curl命令
print(curl_command)