feat: 新增 LLM AI 错误点评功能,支持通过 OpenAI 兼容 API 对提交代码进行智能分析

This commit is contained in:
2026-05-29 16:04:42 +08:00
parent 606e0855f9
commit b95ede457e
3 changed files with 296 additions and 0 deletions

View File

@@ -177,5 +177,80 @@
<?php } ?>
<?php if(isset($OJ_LLM_ENABLED) && $OJ_LLM_ENABLED){ ?>
<div style="margin-top: 20px; margin-bottom: 14px; ">
<div class="ui styled fluid accordion" id="llm-review-accordion">
<div class="title" style="font-size: 1.1em; font-weight: bold; ">
<i class="dropdown icon"></i> 🤖 AI 点评
</div>
<div class="content">
<div id="llm-review-area">
<button class="ui labeled icon blue button" id="llm-review-btn" onclick="fetchLLMReview()">
<i class="magic icon"></i> 获取 AI 点评
</button>
<div id="llm-review-loading" style="display:none; margin-top: 15px; ">
<div class="ui active centered inline text loader">AI 正在分析你的代码,请稍候...</div>
</div>
<div id="llm-review-result" style="display:none; margin-top: 15px; ">
<div class="ui existing segment" id="llm-review-content"></div>
</div>
<div id="llm-review-error" style="display:none; margin-top: 15px; ">
<div class="ui negative message">
<p id="llm-review-error-msg"></p>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#llm-review-accordion').accordion();
});
function fetchLLMReview(){
var btn = $('#llm-review-btn');
btn.prop('disabled', true).addClass('loading');
$('#llm-review-loading').show();
$('#llm-review-error').hide();
$('#llm-review-result').hide();
$.ajax({
type: 'GET',
url: 'llm-review.php?sid=<?php echo intval($id); ?>',
dataType: 'json',
timeout: 60000,
success: function(data){
btn.removeClass('loading');
$('#llm-review-loading').hide();
if(data.error){
$('#llm-review-error-msg').text(data.error);
$('#llm-review-error').show();
btn.prop('disabled', false);
} else if(data.review){
$('#llm-review-result').show();
var container = document.getElementById('llm-review-content');
// 先以纯文本放入,再用 Vditor 渲染为 Markdown HTML
container.textContent = data.review;
if(typeof HustOJVditor !== 'undefined' && HustOJVditor.renderMarkdownBlocks){
HustOJVditor.renderMarkdownBlocks('#llm-review-content', {
useTextContent: true
});
}
btn.hide();
}
},
error: function(xhr, status){
btn.removeClass('loading').prop('disabled', false);
$('#llm-review-loading').hide();
var msg = '请求失败';
if(status === 'timeout') msg = '请求超时,请稍后重试';
$('#llm-review-error-msg').text(msg);
$('#llm-review-error').show();
}
});
}
</script>
<?php } ?>
<?php include("template/$OJ_TEMPLATE/footer.php");?>