"""
测试 NVIDIA API 连接
"""
from openai import OpenAI

client = OpenAI(
    base_url="https://integrate.api.nvidia.com/v1",
    api_key="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"
)

try:
    print("开始测试 API 调用...")
    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,
        timeout=120
    )

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

    print("回答内容:")
    print(completion.choices[0].message.content)
    print("\n" + "="*50)
    print("API 调用成功！")

except Exception as e:
    print(f"API 调用失败: {type(e).__name__}: {e}")
