MindMap/others_deletable/ai-content-analyzer/test_json_openai.py

43 lines
1.2 KiB
Python
Raw 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.

from json_openai import llm_format_text, EXTRACT_OUNTLINE_SYSTEM_PROMPT
# 测试配置
model = "glm-4.5"
base_url = "https://open.bigmodel.cn/api/paas/v4/"
api_key = "ce39bdd4fcf34ec0aec75072bc9ff988.hAp7HZTVUwy7vImn"
# 测试内容
test_content = """
# 人工智能的发展历程
## 早期发展
人工智能的概念最早可以追溯到1950年代。图灵测试的提出标志着AI研究的开始。
### 图灵测试
图灵测试是判断机器是否具有智能的重要标准。
## 现代发展
近年来深度学习技术的突破推动了AI的快速发展。
### 深度学习
深度学习通过神经网络模拟人脑的工作方式。
"""
# 构建消息
messages = [
{"role": "system", "content": EXTRACT_OUNTLINE_SYSTEM_PROMPT},
{"role": "user", "content": f"请分析以下文章内容:\n\n{test_content}"}
]
print("开始调用API...")
try:
result = llm_format_text(model, base_url, api_key, messages, 2000)
print("API调用结果:")
print(result)
except Exception as e:
print(f"调用失败: {e}")
print("可能的原因:")
print("1. API密钥无效或过期")
print("2. 网络连接问题")
print("3. API服务不可用")
print("4. 模型名称不正确")