'commit'
This commit is contained in:
32
dsLightRag/Test/TestGoogleGemini.py
Normal file
32
dsLightRag/Test/TestGoogleGemini.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
# API配置
|
||||
API_URL = "https://goapi.gptnb.ai/v1/chat/completions"
|
||||
API_KEY = "sk-amQHwiEzPIZIB2KuF5A10dC23a0e4b02B48a7a2b6aFa0662" # 从文件末尾提取的API密钥
|
||||
|
||||
# 请求头
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {API_KEY}"
|
||||
}
|
||||
|
||||
# 请求体
|
||||
payload = {
|
||||
"model": "gemini-2.5-pro",
|
||||
"messages": [{"role": "user", "content": "你是谁?"}],
|
||||
"temperature": 0.7
|
||||
}
|
||||
|
||||
try:
|
||||
# 发送POST请求
|
||||
response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
|
||||
response.raise_for_status() # 检查请求是否成功
|
||||
|
||||
# 解析响应
|
||||
result = response.json()
|
||||
print("API响应:")
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"请求发生错误: {e}")
|
Reference in New Issue
Block a user