importrequests
# 定义本地部署的 DeepSeek API 地址
DEESEEK_API_URL ="http://localhost:11434/api/generate"
defcall_deepseek_for_logs(input_text): """
调用 DeepSeek 推理服务进行日志分析。
"""
# 请求数据
payload = {
"model":"deepseek-r1:1.5b",
"prompt":f"从以下日志中查找与 '{input_text}' 相关的错误,并提供解决方案:\n\n{open('application.log','r').read()}"
}
headers = {"Content-Type":"application/json"}
try:
# 调用 DeepSeek API
response = requests.post(DEESEEK_API_URL, json=payload, headers=headers)
response.raise_for_status() # 如果 HTTP 请求失败,抛出异常
result = response.json()
returnresult.get("response","")
exceptrequests.exceptions.RequestExceptionase:
print(f"调用 DeepSeek API 失败:{e}")
returnNone