'commit'
This commit is contained in:
@@ -3,7 +3,7 @@ import json
|
||||
|
||||
# API配置
|
||||
API_URL = "https://goapi.gptnb.ai/v1/chat/completions"
|
||||
API_KEY = "sk-amQHwiEzPIZIB2KuF5A10dC23a0e4b02B48a7a2b6aFa0662" # 从文件末尾提取的API密钥
|
||||
API_KEY = "sk-amQHwiEzPIZIB2KuF5A10dC23a0e4b02B48a7a2b6aFa0662"
|
||||
|
||||
# 请求头
|
||||
headers = {
|
||||
@@ -25,8 +25,16 @@ try:
|
||||
|
||||
# 解析响应
|
||||
result = response.json()
|
||||
print("API响应:")
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
|
||||
# 提取并打印返回的文本内容
|
||||
try:
|
||||
# 从响应中获取文本内容
|
||||
text_content = result['choices'][0]['message']['content']
|
||||
print("\n提取的文本内容:")
|
||||
print(text_content)
|
||||
except (KeyError, IndexError) as e:
|
||||
print(f"\n提取文本内容时出错: {e}")
|
||||
print("响应结构可能与预期不符。")
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"请求发生错误: {e}")
|
Reference in New Issue
Block a user