feat(llm): 引入基于完成度的 AI 提交指导与限流

- 新增 llm_guidance 策略层,根据源码、判题结果与通过率评估完成度分级
- llm-review.php 改为服务端缓冲上游输出,仅下发白名单分类的固定模板
- 新增 llm_review 与 llm_review_rate_limit 表,实现结果缓存与账户/提交两级限流
- ceinfo 模板渲染编译器标出的源码行号/列号,reinfo 仅向高完成度提交展示结构化 diff
- download.php 按完成度授权测试点下载,封堵白卷提交套取隐藏用例
- judge_client 在 ACM 非比赛场景下记录已通过测试点数,前端可显示进度
- 附 llm_guidance_policy_test 单测覆盖空白卷、注释卷、隐藏 SPJ、OJ_FULL_DIFF 等关键路径
This commit is contained in:
2026-07-23 10:47:50 +08:00
parent 5a27c07bba
commit 12bea84d8b
12 changed files with 1721 additions and 768 deletions
+59 -5
View File
@@ -1,15 +1,22 @@
<?php
////////////////////////////Common head
require_once( './include/db_info.inc.php' );
require_once( './include/llm_guidance.inc.php' );
if((!isset($OJ_DOWNLOAD))||!$OJ_DOWNLOAD){
$view_errors="Download Disabled!";
require("template/".$OJ_TEMPLATE."/error.php");
exit(0);
}
$sid=intval($_GET['sid']);
$name=basename($_GET['name'],".out");
$sql="select problem_id,contest_id,user_id from solution where solution_id=?";
$sid=isset($_GET['sid']) ? intval($_GET['sid']) : 0;
$requested_name=isset($_GET['name']) ? $_GET['name'] : '';
$name=llm_guidance_testcase_base($requested_name);
if($sid<=0 || $name===null){
$view_errors="无效的测试点下载请求。";
require("template/".$OJ_TEMPLATE."/error.php");
exit(0);
}
$sql="select problem_id,contest_id,user_id,result,pass_rate from solution where solution_id=?";
$data=pdo_query($sql,$sid);
//var_dump($sql);
if(count($data)>0){
@@ -17,13 +24,55 @@ if(count($data)>0){
$pid=$row[0];
$cid=$row[1];
$uid=$row[2];
if(!(isset($_SESSION[$OJ_NAME.'_'.'user_id']) && $uid == $_SESSION[$OJ_NAME.'_'.'user_id']
|| isset($_SESSION[$OJ_NAME.'_'.'administrator'])
$result_code=intval($row[3]);
$pass_rate=floatval($row[4]);
$is_admin=isset($_SESSION[$OJ_NAME.'_'.'administrator']);
if(!(isset($_SESSION[$OJ_NAME.'_'.'user_id']) && strval($uid) === strval($_SESSION[$OJ_NAME.'_'.'user_id'])
|| $is_admin
)){
$view_errors="not your submission";
require("template/".$OJ_TEMPLATE."/error.php");
exit(0);
}
if(!$is_admin){
$diff_disabled=isset($OJ_SHOW_DIFF) && !$OJ_SHOW_DIFF;
$spj_rows=pdo_query("select spj from problem where problem_id=?",$pid);
$hidden_spj=!empty($spj_rows)
&& $spj_rows!==-1
&& intval($spj_rows[0][0])===2
&& !empty($OJ_HIDE_RIGHT_ANSWER);
$source_rows=pdo_query("select source from source_code_user where solution_id=?",$sid);
$student_source=(!empty($source_rows) && $source_rows!==-1) ? $source_rows[0][0] : "";
$guidance=llm_guidance_assess($student_source,$result_code,$pass_rate);
$runtime_info="";
$allowed_testcases=array();
if($result_code===5 || $result_code===6){
$runtime_rows=pdo_query("select error from runtimeinfo where solution_id=?",$sid);
$runtime_info=(!empty($runtime_rows) && $runtime_rows!==-1) ? $runtime_rows[0][0] : "";
$guidance=llm_guidance_refine_with_output_attempt(
$guidance,
$result_code,
llm_guidance_output_attempt($runtime_info)
);
$allowed_testcases=llm_guidance_diff_testcase_names($runtime_info);
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
$allowed_testcases=array_slice($allowed_testcases,0,1);
}
}
$authorized_testcase=in_array($name,$allowed_testcases,true);
$unsafe_full_diff=llm_guidance_has_full_diff_sections($runtime_info);
if($diff_disabled
|| $hidden_spj
|| $unsafe_full_diff
|| ($result_code!==5 && $result_code!==6)
|| !$guidance['show_output_diff']
|| !$authorized_testcase){
$view_errors="当前提交或测试点未获授权,暂不提供隐藏测试数据下载。";
require("template/".$OJ_TEMPLATE."/error.php");
exit(0);
}
}
if(isset($OJ_NOIP_KEYWORD)&&$OJ_NOIP_KEYWORD){
$now = date('Y-m-d H:i', time());
$sql = "select 1 from `contest` where contest_id=? and `start_time` < ? and `end_time` > ? and `title` like ?";
@@ -38,6 +87,11 @@ if(count($data)>0){
}
$infile="$OJ_DATA/$pid/$name.in";
$outfile="$OJ_DATA/$pid/$name.out";
if(!is_file($infile) || !is_file($outfile)){
$view_errors="测试点文件不存在。";
require("template/".$OJ_TEMPLATE."/error.php");
exit(0);
}
$zipname = tempnam(__dir__.'/upload', '');
$zip = new ZipArchive();