Files

1 line
1.8 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "0lin0-c/wecom-scrm", "files": {"tests/test.py": {"55d6af83dcad99fc658055b79e5aecc46aeb2d7a": {"t": 1785768181.8204165, "n": 1309, "h": "ae33ec1b30309319", "c": "import requests\nimport json\n\n# app = FastAPI()\n\nOPENAI_API_KEY = \"sk-sp-iP9d7tGzkcMhgjkDVhhZ7XIhhZuTfZEGORVw0TlltsALWQq7\"\n\n# 建议尝试这个更完整的地址\nTARGET_URL = \"https://api.lkeap.cloud.tencent.com/coding/v3/chat/completions\"\nMODEL_NAME = \"glm-5\"\n\ndef test_api():\n payload = {\n \"model\": MODEL_NAME,\n \"messages\": [\n {\"role\": \"user\", \"content\": \"你好,请回复‘收到’\"}\n ],\n \"stream\": False\n }\n \n headers = {\n \"Authorization\": f\"Bearer {OPENAI_API_KEY}\",\n \"Content-Type\": \"application/json\"\n }\n\n print(f\"--- 正在发起测试 ---\")\n print(f\"目标地址: {TARGET_URL}\")\n \n try:\n response = requests.post(TARGET_URL, headers=headers, json=payload, timeout=10)\n \n print(f\"状态码: {response.status_code}\")\n print(f\"原始返回内容: {response.text}\")\n \n if response.status_code == 200:\n print(\"✅ 恭喜!接口调用成功。\")\n print(f\"模型回复: {response.json()['choices'][0]['message']['content']}\")\n elif response.status_code == 404:\n print(\"❌ 依然返回 404:请确认 URL。如果加上 /chat/completions 还报错,请登录腾讯云控制台确认该模型对应的 API Endpoint。\")\n elif response.status_code == 401:\n print(\"❌ 返回 401:API Key 无效或已过期。\")\n \n except Exception as e:\n print(f\"❌ 请求发生异常: {e}\")\n\nif __name__ == \"__main__\":\n test_api()"}}}}