feat: v1.2.0 - 图片去重与管理、微信机器人优化、搜索设置可配置
主要功能: - 图片上传时 OCR 内容去重(3个上传端点统一使用公共函数 _check_ocr_duplicate) - 图片管理 Tab:展示所有图片、手动删除、一键去重 - 搜索结果详情弹窗增加删除按钮(带确认弹窗) - 图片管理卡片点击查看详情(复用 showOcrDetailModal) - 搜索限制和 LLM 批量判断数量可通过网站设置 - MiniMax API 调用添加 reasoning_split=True - 企业微信机器人:WebSocket 长连接、图片搜索、配置化搜索数量 - 版本号升级至 1.2.0
This commit is contained in:
32
app/schemas/__init__.py
Normal file
32
app/schemas/__init__.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Pydantic Schemas 包
|
||||
用于 API 请求/响应的数据校验与序列化
|
||||
"""
|
||||
|
||||
from app.schemas.page import (
|
||||
PageCreate,
|
||||
PageResponse,
|
||||
PageListResponse,
|
||||
)
|
||||
from app.schemas.search import (
|
||||
SearchRequest,
|
||||
SearchResponse,
|
||||
SearchResult,
|
||||
)
|
||||
from app.schemas.ocr import (
|
||||
OCRResultSchema,
|
||||
OCRBlockSchema,
|
||||
ImageUploadResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"PageCreate",
|
||||
"PageResponse",
|
||||
"PageListResponse",
|
||||
"SearchRequest",
|
||||
"SearchResponse",
|
||||
"SearchResult",
|
||||
"OCRResultSchema",
|
||||
"OCRBlockSchema",
|
||||
"ImageUploadResponse",
|
||||
]
|
||||
47
app/schemas/ocr.py
Normal file
47
app/schemas/ocr.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
OCR 相关的 Pydantic Schema
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class OCRBlockSchema(BaseModel):
|
||||
"""OCR 识别的文本块"""
|
||||
text: str = Field(..., description="文本块内容")
|
||||
bbox: Optional[list[float]] = Field(None, description="边界框 [x1, y1, x2, y2]")
|
||||
confidence: float = Field(..., description="置信度 (0-1)")
|
||||
|
||||
|
||||
class OCRResultSchema(BaseModel):
|
||||
"""OCR 识别结果"""
|
||||
text: str = Field(..., description="识别全文")
|
||||
blocks: list[OCRBlockSchema] = Field(default_factory=list, description="文本块列表")
|
||||
confidence: float = Field(..., description="平均置信度 (0-1)")
|
||||
provider: str = Field(..., description="使用的 OCR 提供商")
|
||||
|
||||
|
||||
class ImageUploadResponse(BaseModel):
|
||||
"""图片上传响应"""
|
||||
id: int
|
||||
file_path: str
|
||||
status: str
|
||||
created_at: datetime
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class ImageOCRResponse(BaseModel):
|
||||
"""图片 OCR 结果响应"""
|
||||
id: int
|
||||
file_path: str
|
||||
ocr_text: Optional[str] = None
|
||||
confidence: Optional[float] = None
|
||||
provider: Optional[str] = None
|
||||
status: str
|
||||
error_message: Optional[str] = None
|
||||
created_at: datetime
|
||||
model_config = {"from_attributes": True}
|
||||
63
app/schemas/page.py
Normal file
63
app/schemas/page.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
知识页面相关的 Pydantic Schema
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class PageCreate(BaseModel):
|
||||
"""创建知识页面请求"""
|
||||
title: str = Field(..., max_length=500, description="页面标题")
|
||||
content: str = Field(..., description="页面正文内容")
|
||||
source_file: Optional[str] = Field(None, max_length=500, description="来源文件名")
|
||||
course_name: Optional[str] = Field(None, max_length=200, description="课程名称")
|
||||
teacher_name: Optional[str] = Field(None, max_length=100, description="讲师名称")
|
||||
live_date: Optional[str] = Field(None, max_length=20, description="直播日期 (YYYY-MM-DD)")
|
||||
page_number: Optional[int] = Field(None, description="原始页码")
|
||||
metadata_json: Optional[str] = Field(None, description="额外元数据 (JSON)")
|
||||
|
||||
|
||||
class PageUpdate(BaseModel):
|
||||
"""更新知识页面请求(所有字段可选)"""
|
||||
title: Optional[str] = Field(None, max_length=500, description="页面标题")
|
||||
content: Optional[str] = Field(None, description="页面正文内容")
|
||||
course_name: Optional[str] = Field(None, max_length=200, description="课程名称")
|
||||
teacher_name: Optional[str] = Field(None, max_length=100, description="讲师名称")
|
||||
live_date: Optional[str] = Field(None, max_length=20, description="直播日期")
|
||||
page_number: Optional[int] = Field(None, description="原始页码")
|
||||
metadata_json: Optional[str] = Field(None, description="额外元数据")
|
||||
|
||||
|
||||
class PageResponse(BaseModel):
|
||||
"""知识页面响应"""
|
||||
id: int
|
||||
title: str
|
||||
content: str
|
||||
source_file: Optional[str] = None
|
||||
course_name: Optional[str] = None
|
||||
teacher_name: Optional[str] = None
|
||||
live_date: Optional[str] = None
|
||||
page_number: Optional[int] = None
|
||||
metadata_json: Optional[str] = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class PageListResponse(BaseModel):
|
||||
"""知识页面列表响应(带分页)"""
|
||||
total: int = Field(..., description="总记录数")
|
||||
page: int = Field(..., description="当前页码")
|
||||
page_size: int = Field(..., description="每页数量")
|
||||
items: list[PageResponse] = Field(default_factory=list, description="页面列表")
|
||||
|
||||
|
||||
class PageDetailResponse(PageResponse):
|
||||
"""知识页面详情响应(包含分块信息)"""
|
||||
chunks: list[dict[str, Any]] = Field(default_factory=list, description="关联的分块列表")
|
||||
42
app/schemas/search.py
Normal file
42
app/schemas/search.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
语义搜索相关的 Pydantic Schema
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class SearchRequest(BaseModel):
|
||||
"""语义搜索请求"""
|
||||
query: str = Field(..., min_length=1, max_length=1000, description="搜索查询文本")
|
||||
top_k: int = Field(default=10, ge=1, le=100, description="返回结果数量")
|
||||
course_name: Optional[str] = Field(None, description="按课程名称过滤")
|
||||
teacher_name: Optional[str] = Field(None, description="按讲师名称过滤")
|
||||
live_date_from: Optional[str] = Field(None, description="直播日期起始 (YYYY-MM-DD)")
|
||||
live_date_to: Optional[str] = Field(None, description="直播日期结束 (YYYY-MM-DD)")
|
||||
threshold: float = Field(default=0.5, ge=0.0, le=1.0, description="相似度阈值")
|
||||
use_fulltext: bool = Field(default=True, description="是否同时使用全文搜索混合排序")
|
||||
|
||||
|
||||
class SearchResult(BaseModel):
|
||||
"""单条搜索结果"""
|
||||
chunk_id: int = Field(..., description="分块 ID")
|
||||
page_id: int = Field(..., description="知识页面 ID")
|
||||
page_title: str = Field(..., description="页面标题")
|
||||
content: str = Field(..., description="分块文本内容")
|
||||
score: float = Field(..., description="相似度分数")
|
||||
course_name: Optional[str] = None
|
||||
teacher_name: Optional[str] = None
|
||||
live_date: Optional[str] = None
|
||||
highlight: Optional[str] = Field(None, description="高亮摘要")
|
||||
|
||||
|
||||
class SearchResponse(BaseModel):
|
||||
"""搜索结果响应"""
|
||||
query: str = Field(..., description="原始查询文本")
|
||||
total: int = Field(..., description="结果总数")
|
||||
results: list[SearchResult] = Field(default_factory=list, description="搜索结果列表")
|
||||
elapsed_ms: float = Field(..., description="搜索耗时(毫秒)")
|
||||
Reference in New Issue
Block a user