import os
from openai import OpenAI

# 设置 API key 为环境变量
os.environ["NVIDIA_API_KEY"] = "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"

client = OpenAI(
  base_url="https://integrate.api.nvidia.com/v1",
  api_key=os.environ["NVIDIA_API_KEY"]
)

print("正在测试 API 连接...")
print("发送消息: 天气")
print("-" * 50)

completion = client.chat.completions.create(
  model="deepseek-ai/deepseek-r1",
  messages=[{"role": "user", "content": "天气"}],
  temperature=0.6,
  top_p=0.7,
  max_tokens=4096,
  stream=False
)

reasoning = getattr(completion.choices[0].message, "reasoning_content", None)
if reasoning:
    print("推理过程:")
    print(reasoning)
    print("-" * 50)

print("回答:")
print(completion.choices[0].message.content)
