43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""手工测试 AI API 连接;自动测试导入本模块时不会发起请求。"""
|
|
|
|
import unittest
|
|
|
|
|
|
def main() -> None:
|
|
import os
|
|
import sys
|
|
import traceback
|
|
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
|
|
from ai_config import AI_API_BASE, AI_API_KEY, AI_MODEL
|
|
from ai_chat import _completions_url, call_ai_text
|
|
|
|
print(f"API 地址: {AI_API_BASE}")
|
|
print(f"模型名称: {AI_MODEL}")
|
|
print(f"API Key: {'已配置' if AI_API_KEY else '未配置'}(不会显示密钥)")
|
|
print(f"请求 URL: {_completions_url()}")
|
|
print("-" * 40)
|
|
print("正在发送测试消息...")
|
|
|
|
try:
|
|
reply = call_ai_text("你好")
|
|
print(f"\n[+] AI 回复: {reply}")
|
|
print("\n测试通过!AI 模型可以正常使用。")
|
|
except Exception as exc:
|
|
print(f"\n[-] 测试失败: {exc}")
|
|
response = getattr(exc, "response", None)
|
|
if response is not None:
|
|
print(f"状态码: {response.status_code}")
|
|
print(f"响应体: {response.text[:500]}")
|
|
traceback.print_exc()
|
|
|
|
|
|
class ManualAIIsolationTest(unittest.TestCase):
|
|
def test_manual_entrypoint_is_import_safe(self) -> None:
|
|
self.assertTrue(callable(main))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|