fix: 优化整个项目内容
This commit is contained in:
@@ -62,7 +62,7 @@ def _migrate_mistake_columns() -> None:
|
||||
|
||||
_migrate_mistake_columns()
|
||||
|
||||
app = FastAPI(title="公考助手 API", version="1.0.0")
|
||||
app = FastAPI(title="学习伙伴 API", version="1.0.0")
|
||||
UPLOAD_DIR = Path(os.getenv("UPLOAD_DIR", "/app/uploads"))
|
||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||
app.mount("/uploads", StaticFiles(directory=str(UPLOAD_DIR)), name="uploads")
|
||||
@@ -273,9 +273,23 @@ def _restore_upload_url_from_zip(url: str | None, zip_ref: zipfile.ZipFile) -> s
|
||||
@app.post("/api/upload")
|
||||
async def upload_file(file: UploadFile = File(...)):
|
||||
suffix = Path(file.filename or "").suffix.lower()
|
||||
allowed = {".pdf", ".doc", ".docx", ".jpg", ".jpeg", ".png", ".webp"}
|
||||
allowed = {".pdf", ".doc", ".docx", ".jpg", ".jpeg", ".png", ".webp", ".heic", ".heif"}
|
||||
mime_to_suffix = {
|
||||
"application/pdf": ".pdf",
|
||||
"application/msword": ".doc",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",
|
||||
"image/jpeg": ".jpg",
|
||||
"image/png": ".png",
|
||||
"image/webp": ".webp",
|
||||
"image/heic": ".heic",
|
||||
"image/heif": ".heif",
|
||||
}
|
||||
if suffix not in allowed:
|
||||
raise HTTPException(status_code=400, detail="不支持的文件类型")
|
||||
guessed = mime_to_suffix.get((file.content_type or "").lower())
|
||||
if guessed:
|
||||
suffix = guessed
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="不支持的文件类型")
|
||||
content = await file.read()
|
||||
if len(content) > 50 * 1024 * 1024:
|
||||
raise HTTPException(status_code=400, detail="文件不能超过 50MB")
|
||||
@@ -452,7 +466,7 @@ def export_mistakes_pdf(
|
||||
left = 48
|
||||
right = 560
|
||||
max_width = right - left
|
||||
pdf.drawString(left, y, "公考助手 - 错题导出")
|
||||
pdf.drawString(left, y, "学习伙伴 - 错题导出")
|
||||
y -= 28
|
||||
for idx, item in enumerate(items, start=1):
|
||||
if y < 90:
|
||||
@@ -497,7 +511,7 @@ def export_mistakes_docx(
|
||||
id_list = [int(x) for x in ids.split(",") if x.strip().isdigit()] if ids else None
|
||||
items = _query_mistakes_for_export(db, category, start_date, end_date, id_list)
|
||||
doc = Document()
|
||||
doc.add_heading("公考助手 - 错题导出", level=1)
|
||||
doc.add_heading("学习伙伴 - 错题导出", level=1)
|
||||
for idx, item in enumerate(items, start=1):
|
||||
blocks = _mistake_export_blocks(item, content_mode)
|
||||
for bi, block in enumerate(blocks):
|
||||
@@ -934,9 +948,11 @@ async def parse_ocr(payload: OcrParseIn):
|
||||
".jpeg": "image/jpeg",
|
||||
".png": "image/png",
|
||||
".webp": "image/webp",
|
||||
".heic": "image/heic",
|
||||
".heif": "image/heif",
|
||||
}.get(suffix)
|
||||
if not mime:
|
||||
raise HTTPException(status_code=400, detail="仅支持 JPG/PNG/WebP OCR")
|
||||
raise HTTPException(status_code=400, detail="仅支持 JPG/PNG/WebP/HEIC OCR")
|
||||
|
||||
b64 = base64.b64encode(target.read_bytes()).decode("utf-8")
|
||||
image_data_url = f"data:{mime};base64,{b64}"
|
||||
@@ -952,7 +968,7 @@ async def parse_ocr(payload: OcrParseIn):
|
||||
ocr_prompt = f"{ocr_prompt}\n补充要求:{payload.prompt}"
|
||||
|
||||
raw_text = await _call_qwen_vision(
|
||||
"你是公考题目OCR与结构化助手。输出必须是 JSON,不要额外解释。",
|
||||
"你是题目 OCR 与结构化助手。输出必须是 JSON,不要额外解释。",
|
||||
ocr_prompt,
|
||||
image_data_url,
|
||||
)
|
||||
@@ -1033,7 +1049,7 @@ async def ai_analyze_mistake(item_id: int, db: Session = Depends(get_db)):
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Mistake not found")
|
||||
content = await _call_qwen(
|
||||
"你是公考备考教练,请输出结构化、可执行的错题分析。",
|
||||
"你是学习教练,请输出结构化、可执行的错题分析。",
|
||||
(
|
||||
f"错题标题: {item.title}\n"
|
||||
f"分类: {item.category}\n"
|
||||
@@ -1059,7 +1075,7 @@ async def ai_study_plan(payload: AiStudyPlanIn, db: Session = Depends(get_db)):
|
||||
mistake_text = ", ".join([f"{m.category}-{m.title}" for m in recent_mistakes]) or "暂无错题数据"
|
||||
|
||||
content = await _call_qwen(
|
||||
"你是公考学习规划师,请给出可执行计划并尽量量化。",
|
||||
"你是学习规划师,请给出可执行计划并尽量量化。",
|
||||
(
|
||||
f"目标: {payload.goal}\n"
|
||||
f"剩余天数: {payload.days_left}\n"
|
||||
|
||||
Reference in New Issue
Block a user