更新bug
This commit is contained in:
+38
-25
@@ -1,29 +1,42 @@
|
||||
"""快速测试 AI API 连接是否可用"""
|
||||
import sys, os
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
"""手工测试 AI API 连接;自动测试导入本模块时不会发起请求。"""
|
||||
|
||||
from ai_config import AI_API_BASE, AI_API_KEY, AI_MODEL
|
||||
from ai_chat import call_ai_text
|
||||
import unittest
|
||||
|
||||
print(f"API 地址: {AI_API_BASE}")
|
||||
print(f"模型名称: {AI_MODEL}")
|
||||
print(f"API Key: {AI_API_KEY[:4]}****")
|
||||
|
||||
# 打印实际请求 URL(方便排查路径问题)
|
||||
from ai_chat import _completions_url
|
||||
print(f"请求 URL: {_completions_url()}")
|
||||
print("-" * 40)
|
||||
print("正在发送测试消息...")
|
||||
|
||||
try:
|
||||
reply = call_ai_text("你好")
|
||||
print(f"\n[+] AI 回复: {reply}")
|
||||
print("\n测试通过!AI 模型可以正常使用。")
|
||||
except Exception as e:
|
||||
print(f"\n[-] 测试失败: {e}")
|
||||
# 打印服务器返回的详细信息
|
||||
if hasattr(e, 'response') and e.response is not None:
|
||||
print(f"状态码: {e.response.status_code}")
|
||||
print(f"响应体: {e.response.text[:500]}")
|
||||
def main() -> None:
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user