环境变量修改
This commit is contained in:
11
backend/.env
11
backend/.env
@@ -1,4 +1,13 @@
|
|||||||
# OpenAI API配置(可选,用于AI润色功能)
|
# AI服务配置(用于AI润色功能)
|
||||||
|
# 支持多个AI服务商:OpenAI、Anthropic、Google、自定义端点等
|
||||||
|
AI_MODEL=gpt-3.5-turbo
|
||||||
|
AI_API_KEY=your_api_key_here
|
||||||
|
# AI_API_BASE=https://your-custom-endpoint.com/v1 # 可选:自定义API端点
|
||||||
|
# AI_CUSTOM_PROVIDER=openai # 可选:自定义端点的API格式
|
||||||
|
AI_TEMPERATURE=0.7
|
||||||
|
AI_MAX_TOKENS=500
|
||||||
|
|
||||||
|
# 兼容旧配置
|
||||||
OPENAI_API_KEY=your_openai_api_key_here
|
OPENAI_API_KEY=your_openai_api_key_here
|
||||||
|
|
||||||
# 数据库配置
|
# 数据库配置
|
||||||
|
|||||||
@@ -118,3 +118,6 @@ class AIService:
|
|||||||
|
|
||||||
# 创建全局AI服务实例
|
# 创建全局AI服务实例
|
||||||
ai_service = AIService()
|
ai_service = AIService()
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
|
ai_service.polish_description("你好,我是奶龙,我打开附件打开房间啊看回归程序。")
|
||||||
@@ -149,26 +149,42 @@ async def delete_task(task_id: int, db: Session = Depends(get_db)):
|
|||||||
@api.post('/tasks/{task_id}/polish')
|
@api.post('/tasks/{task_id}/polish')
|
||||||
async def polish_task_description(task_id: int, db: Session = Depends(get_db)):
|
async def polish_task_description(task_id: int, db: Session = Depends(get_db)):
|
||||||
"""AI润色任务描述"""
|
"""AI润色任务描述"""
|
||||||
task = db.query(Task).filter(Task.id == task_id).first()
|
try:
|
||||||
if not task:
|
task = db.query(Task).filter(Task.id == task_id).first()
|
||||||
raise HTTPException(status_code=404, detail='任务不存在')
|
if not task:
|
||||||
|
raise HTTPException(status_code=404, detail='任务不存在')
|
||||||
|
|
||||||
if not ai_service.is_available():
|
if not ai_service.is_available():
|
||||||
raise HTTPException(status_code=500, detail='AI服务不可用,请检查API密钥配置')
|
raise HTTPException(status_code=400, detail='AI服务不可用,请检查API密钥配置')
|
||||||
|
|
||||||
if not task.description:
|
if not task.description:
|
||||||
raise HTTPException(status_code=400, detail='任务描述为空,无法润色')
|
raise HTTPException(status_code=400, detail='任务描述为空,无法润色')
|
||||||
|
|
||||||
polished_description = ai_service.polish_description(task.description)
|
polished_description = ai_service.polish_description(task.description)
|
||||||
task.polished_description = polished_description
|
|
||||||
task.updated_at = datetime.utcnow()
|
|
||||||
|
|
||||||
db.commit()
|
# 如果AI服务返回的内容与原内容相同,可能是AI调用失败
|
||||||
|
if polished_description == task.description:
|
||||||
|
raise HTTPException(status_code=500, detail='AI润色服务调用失败,请检查配置和网络连接')
|
||||||
|
|
||||||
return {
|
task.polished_description = polished_description
|
||||||
'original': task.description,
|
task.updated_at = datetime.utcnow()
|
||||||
'polished': polished_description
|
|
||||||
}
|
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
|
||||||
@api.post('/timer/start')
|
@api.post('/timer/start')
|
||||||
|
|||||||
@@ -13,10 +13,13 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
- SECRET_KEY=${SECRET_KEY:-your-secret-key-here}
|
- SECRET_KEY=${SECRET_KEY:-your-secret-key-here}
|
||||||
- OPENAI_API_KEY=${OPENAI_API_KEY:-}
|
|
||||||
# 默认用户配置
|
# 默认用户配置
|
||||||
- DEFAULT_USERNAME=${DEFAULT_USERNAME:-admin}
|
- DEFAULT_USERNAME=${DEFAULT_USERNAME:-admin}
|
||||||
- DEFAULT_PASSWORD=${DEFAULT_PASSWORD:-admin123}
|
- DEFAULT_PASSWORD=${DEFAULT_PASSWORD:-admin123}
|
||||||
|
- AI_API_BASE=${AI_API_BASE}
|
||||||
|
- AI_CUSTOM_PROVIDER=${AI_CUSTOM_PROVIDER}
|
||||||
|
- AI_MODEL=${AI_MODEL}
|
||||||
|
- AI_API_KEY=${AI_API_KEY}
|
||||||
volumes:
|
volumes:
|
||||||
# 持久化数据库 - 挂载到宿主机目录
|
# 持久化数据库 - 挂载到宿主机目录
|
||||||
- worklist-data:/app/data
|
- worklist-data:/app/data
|
||||||
|
|||||||
@@ -20,8 +20,17 @@ class WorkListAPI {
|
|||||||
const response = await fetch(url, config);
|
const response = await fetch(url, config);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json().catch(() => ({}));
|
// 尝试解析错误响应
|
||||||
throw new Error(errorData.error || `HTTP错误: ${response.status}`);
|
let errorMessage = `HTTP错误: ${response.status}`;
|
||||||
|
try {
|
||||||
|
const errorData = await response.json();
|
||||||
|
// 使用后端返回的详细错误信息
|
||||||
|
errorMessage = errorData.detail || errorData.error || errorMessage;
|
||||||
|
} catch (parseError) {
|
||||||
|
// 如果无法解析JSON,使用默认错误消息
|
||||||
|
console.error('无法解析错误响应:', parseError);
|
||||||
|
}
|
||||||
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json();
|
return await response.json();
|
||||||
|
|||||||
Reference in New Issue
Block a user