import asyncio from pydantic import BaseModel, Field class QuestionTypeItem(BaseModel): questionType: str = "" name: str = "" count: int = 0 questionCount: int = 0 scorePerQuestion: int = 0 romanNumeral: str = "" class BuildPromptRequest(BaseModel): mode: str = "" client: str = "" projectType: str = "" examTitle: str = "" totalScore: int = 0 questionTypes: list[QuestionTypeItem] = Field(default_factory=list) pptContent: str = "" data = BuildPromptRequest(**{ "mode": "ai", "client": "pc", "projectType": "bridge", "examTitle": "桥梁工程施工技术考核", "totalScore": 100, "questionTypes": [ { "name": "单选题", "romanNumeral": "一", "questionCount": 20, "scorePerQuestion": 2 }, { "name": "判断题", "romanNumeral": "二", "questionCount": 10, "scorePerQuestion": 3 } ], "pptContent": "" }) question_desc = [] total_count = 0 for item in data.questionTypes: count = item.count or item.questionCount or 0 score = item.scorePerQuestion or 0 qtype = item.questionType or item.name or "未命名题型" total_count += count question_desc.append(f"{qtype}{count}道,每道{score}分") question_text = ";".join(question_desc) if question_desc else "题型未提供" question_schema_lines = [] for item in data.questionTypes: count = item.count or item.questionCount or 0 score = item.scorePerQuestion or 0 qtype = item.questionType or item.name or "未命名题型" if count <= 0: continue question_schema_lines.append(f"- {qtype}: {count}道,每道{score}分") question_schema = "\n".join( question_schema_lines) if question_schema_lines else "- 未提供有效题型" ppt_content = (data.pptContent or "").strip() basis_requirement = "" if ppt_content: basis_requirement = ( "出题依据内容是本次试卷的核心来源,所有题目必须围绕该内容中的知识点、术语、流程、规范要求和场景展开。\n" "如果出题依据内容中出现了章节、条款、培训主题或专业术语,题目必须优先考查这些内容,不能偏离到无关知识。\n" "单选题、多选题、判断题和简答题的题干、选项、答案解析都要与出题依据内容直接相关,不能泛泛而谈。\n" "请结合出题依据内容、工程类型和题型要求,生成有具体内容、具体选项、具体答案、具体解析的试卷。\n" ) else: basis_requirement = ( "请结合工程类型、考试标题和题型要求,运用路桥隧轨施工安全等专业知识,生成有具体内容、具体选项、具体答案、具体解析的高质量试卷。\n" "所有题目必须与考试标题紧密相关,不能泛泛而谈。\n" ) prompt = ( "请根据以下要求直接生成一份完整试卷,并严格返回纯 JSON,不要输出 markdown 代码块、解释说明或额外文字。\n" f"生成模式:{data.mode or '未指定'}\n" f"客户端:{data.client or '未指定'}\n" f"项目类型:{data.projectType or '未指定'}\n" f"考试标题:{data.examTitle or '未命名考试'}\n" f"总分:{data.totalScore or 0}\n" f"总题量:{total_count}\n" f"题型要求:{question_text}\n" f"出题依据内容:{ppt_content or '无'}\n" f"{basis_requirement}" "禁止输出“选项A”“题目1”“桥梁工程相关单选题1”“题目内容”“解析内容”这类占位内容,所有题目必须是可直接展示和作答的真实内容。\n" "下面的 JSON 结构示例只用于说明字段格式,示例中的字符串不能原样照抄到最终结果中,最终返回的每个字符串都必须替换成结合出题依据生成的具体内容。\n" "JSON 输出结构必须符合以下格式:\n" "{\n" ' "title": "试卷标题",\n' ' "totalScore": 100,\n' ' "totalQuestions": 10,\n' ' "singleChoice": {"scorePerQuestion": 2, "totalScore": 20, "count": 10, "questions": [{"text": "<单选题题干>", "options": [{"key": "A", "text": "<选项A具体内容>"}, {"key": "B", "text": "<选项B具体内容>"}, {"key": "C", "text": "<选项C具体内容>"}, {"key": "D", "text": "<选项D具体内容>"}], "answer": "A", "analysis": "<解析内容>"}]},\n' ' "judge": {"scorePerQuestion": 2, "totalScore": 0, "count": 0, "questions": [{"text": "<判断题题干>", "answer": "正确", "analysis": "<解析内容>"}]},\n' ' "multiple": {"scorePerQuestion": 3, "totalScore": 0, "count": 0, "questions": [{"text": "<多选题题干>", "options": [{"key": "A", "text": "<选项A具体内容>"}, {"key": "B", "text": "<选项B具体内容>"}, {"key": "C", "text": "<选项C具体内容>"}, {"key": "D", "text": "<选项D具体内容>"}], "answers": ["A", "C"], "analysis": "<解析内容>"}]},\n' ' "short": {"scorePerQuestion": 10, "totalScore": 0, "count": 0, "questions": [{"text": "<简答题题干>", "outline": {"keyFactors": "<答题要点>", "measures": "<参考措施>"}}]}\n' "}\n" "请按下面的题型配置生成对应数量的题目,没有的题型 count 返回 0、questions 返回空数组:\n" f"{question_schema}" ) print(prompt)