环境变量修改

This commit is contained in:
2026-01-13 09:38:11 +00:00
parent 41179b9c83
commit f588d1e46d
5 changed files with 59 additions and 19 deletions

View File

@@ -149,26 +149,42 @@ async def delete_task(task_id: int, db: Session = Depends(get_db)):
@api.post('/tasks/{task_id}/polish')
async def polish_task_description(task_id: int, db: Session = Depends(get_db)):
"""AI润色任务描述"""
task = db.query(Task).filter(Task.id == task_id).first()
if not task:
raise HTTPException(status_code=404, detail='任务不存在')
try:
task = db.query(Task).filter(Task.id == task_id).first()
if not task:
raise HTTPException(status_code=404, detail='任务不存在')
if not ai_service.is_available():
raise HTTPException(status_code=500, detail='AI服务不可用请检查API密钥配置')
if not ai_service.is_available():
raise HTTPException(status_code=400, detail='AI服务不可用请检查API密钥配置')
if not task.description:
raise HTTPException(status_code=400, detail='任务描述为空,无法润色')
if not task.description:
raise HTTPException(status_code=400, detail='任务描述为空,无法润色')
polished_description = ai_service.polish_description(task.description)
task.polished_description = polished_description
task.updated_at = datetime.utcnow()
polished_description = ai_service.polish_description(task.description)
db.commit()
# 如果AI服务返回的内容与原内容相同可能是AI调用失败
if polished_description == task.description:
raise HTTPException(status_code=500, detail='AI润色服务调用失败请检查配置和网络连接')
return {
'original': task.description,
'polished': polished_description
}
task.polished_description = polished_description
task.updated_at = datetime.utcnow()
db.commit()
return {
'original': task.description,
'polished': polished_description
}
except HTTPException:
# 重新抛出HTTP异常
raise
except Exception as e:
# 捕获其他异常并返回详细错误信息
import traceback
error_detail = f'AI润色失败: {str(e)}'
print(f"Polish task error: {error_detail}")
print(traceback.format_exc())
raise HTTPException(status_code=500, detail=error_detail)
# 计时器API
@api.post('/timer/start')