diff --git a/agent/prompt.py b/agent/prompt.py index 4fa1547..e16921b 100644 --- a/agent/prompt.py +++ b/agent/prompt.py @@ -99,12 +99,12 @@ exam_prompt = """ - single:单选题,answer 长度为 1 - multiple:多选题,answer 长度 ≥ 2 - question:题干内容 -- options:选项数组,固定 4 项,格式为 ["A. xxx", "B. xxx", "C. xxx", "D. xxx"] +- options:选项数组,固定 4 项,格式为 ["选项A内容", "选项B内容", "选项C内容", "选项D内容"] - answer:正确答案编号数组,如 ["A"] 或 ["A", "C"] - select:用户选择,永远为空数组 [] 【约束】 -1. 仅返回 JSON 数组,不要任何说明、注释或 Markdown。 +1. 仅返回纯 JSON,禁止输出 Markdown、代码块、注释或任何说明文字。必须返回一个 JSON 数组,不得以对象包裹。JSON 必须是合法格式,可被程序直接解析。 2. 单选题的 answer 只能包含一个选项。 3. 多选题的 answer 至少包含两个选项。 4. 选项必须具有区分度,不能有明显错误或重复。 @@ -115,12 +115,12 @@ exam_prompt = """ { "id": 1, "type": "single", - "question": "下列关于光的传播说法正确的是?", + "question": "题目内容", "options": [ - "A. 光在同种均匀介质中沿直线传播", - "B. 光在真空中的传播速度为 3×10⁸ m/s", - "C. 光在不同介质中传播速度相同", - "D. 光不能在真空中传播" + "选项A内容", + "选项B内容", + "选项C内容", + "选项D内容" ], "answer": ["A"], "select": [] @@ -128,12 +128,12 @@ exam_prompt = """ { "id": 2, "type": "multiple", - "question": "下列哪些属于可再生能源?", + "question": "题目内容", "options": [ - "A. 太阳能", - "B. 煤炭", - "C. 风能", - "D. 天然气" + "选项A内容", + "选项B内容", + "选项C内容", + "选项D内容" ], "answer": ["A", "C"], "select": [] diff --git a/models/library.py b/models/library.py index ec8f181..f162b46 100644 --- a/models/library.py +++ b/models/library.py @@ -33,6 +33,13 @@ class PracticeRecord(AuditBase): ) +class ExamRecord(AuditBase): + subject = Column(String(45), nullable=False) + total_count = Column(Integer, nullable=False) + correct_count = Column(Integer, nullable=False) + wrong_count = Column(Integer, nullable=False) + + class Mistake(AuditBase): subject = Column(String(45), nullable=False) module = Column(String(45), nullable=False) diff --git a/routers/__init__.py b/routers/__init__.py index 90500ab..68e3c1d 100644 --- a/routers/__init__.py +++ b/routers/__init__.py @@ -1,11 +1,13 @@ from .agent import router as agent_router from .library import router as library_router from .practice import router as practice_router +from .exam import router as exam_router from .mistake import router as mistake_router routers = [ agent_router, library_router, practice_router, + exam_router, mistake_router, ] diff --git a/routers/exam.py b/routers/exam.py new file mode 100644 index 0000000..d391b78 --- /dev/null +++ b/routers/exam.py @@ -0,0 +1,13 @@ +from fastapi import APIRouter, Depends +from sqlalchemy.ext.asyncio import AsyncSession + +from database import get_db +from schemas.exam import ExamRecordRequest +from service import exam_service + +router = APIRouter(prefix="/exam", tags=["Exam"]) + + +@router.post("/record", response_model=bool) +async def add_record(data: ExamRecordRequest, db: AsyncSession = Depends(get_db), ): + return await exam_service.add_record(db, data) diff --git a/schemas/exam.py b/schemas/exam.py new file mode 100644 index 0000000..a9bc3f3 --- /dev/null +++ b/schemas/exam.py @@ -0,0 +1,16 @@ +from pydantic import BaseModel + + +class ExamRecordRequest(BaseModel): + subject: str + totalCount: int + correctCount: int + wrongCount: int + + +class ExamRecordResponse(ExamRecordRequest): + id: int + createTime: str + + class Config: + from_attributes = True diff --git a/service/exam_service.py b/service/exam_service.py new file mode 100644 index 0000000..058dcf1 --- /dev/null +++ b/service/exam_service.py @@ -0,0 +1,18 @@ +from sqlalchemy.ext.asyncio import AsyncSession + +from models.library import ExamRecord +from schemas.exam import ExamRecordRequest + + +async def add_record(db: AsyncSession, data: ExamRecordRequest) -> bool: + record = ExamRecord( + subject=data.subject, + total_count=data.totalCount, + correct_count=data.correctCount, + wrong_count=data.wrongCount, + ) + + db.add(record) + await db.commit() + + return True