Initial: integrated 2025 LawGraph (graphrag_pipeline) + 2026 kg_project
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
测试硅基流动API配置
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from src.utils.llm_client import LLMClient, LLMProvider
|
||||
from src.utils.config import load_config
|
||||
|
||||
|
||||
def test_siliconflow():
|
||||
"""测试硅基流动API"""
|
||||
print("=" * 60)
|
||||
print("测试硅基流动API配置")
|
||||
print("=" * 60)
|
||||
|
||||
# 加载配置
|
||||
config = load_config()
|
||||
|
||||
# 检查API密钥
|
||||
if not config.SILICONFLOW_API_KEY:
|
||||
print("❌ 错误: SILICONFLOW_API_KEY 未配置")
|
||||
print("请在 .env 文件中设置 SILICONFLOW_API_KEY")
|
||||
return False
|
||||
|
||||
print(f"✅ API密钥已配置: {config.SILICONFLOW_API_KEY[:20]}...")
|
||||
print(f"✅ API Base URL: {config.SILICONFLOW_API_BASE}")
|
||||
|
||||
# 创建客户端(使用一个常见的模型,用户需要根据实际可用模型调整)
|
||||
print("\n尝试创建客户端...")
|
||||
try:
|
||||
# 注意:这里使用的模型名称需要根据硅基流动平台实际可用模型调整
|
||||
# 常用的模型包括:Qwen/Qwen2.5-72B-Instruct, meta-llama/Llama-3.1-70B-Instruct 等
|
||||
client = LLMClient(
|
||||
provider=LLMProvider.SILICONFLOW,
|
||||
model="Qwen/Qwen2.5-72B-Instruct", # 请根据实际情况修改模型名称
|
||||
config=config
|
||||
)
|
||||
print("✅ 客户端创建成功")
|
||||
except Exception as e:
|
||||
print(f"❌ 客户端创建失败: {e}")
|
||||
return False
|
||||
|
||||
# 测试简单对话
|
||||
print("\n测试API调用...")
|
||||
messages = [
|
||||
{"role": "user", "content": "请用一句话介绍知识图谱。"}
|
||||
]
|
||||
|
||||
try:
|
||||
response = client.chat(messages)
|
||||
print(f"✅ API调用成功")
|
||||
print(f"\n响应内容:\n{response}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ API调用失败: {e}")
|
||||
print("\n提示:")
|
||||
print("1. 请检查API密钥是否正确")
|
||||
print("2. 请检查网络连接")
|
||||
print("3. 请确认模型名称是否在硅基流动平台可用")
|
||||
print("4. 可以访问 https://siliconflow.cn/ 查看可用模型列表")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_siliconflow()
|
||||
if success:
|
||||
print("\n" + "=" * 60)
|
||||
print("✅ 硅基流动API配置测试通过!")
|
||||
print("=" * 60)
|
||||
else:
|
||||
print("\n" + "=" * 60)
|
||||
print("❌ 硅基流动API配置测试失败,请检查配置")
|
||||
print("=" * 60)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user