#feature: AI analysis update
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Jobs;
|
||||
use App\Enums\AnalysisMode;
|
||||
use App\Models\LogAnalysisReport;
|
||||
use App\Services\AiService;
|
||||
use App\Services\CodeAnalysisService;
|
||||
use App\Services\CodeContextService;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\DingTalkService;
|
||||
@@ -38,6 +39,7 @@ class LogAnalysisJob implements ShouldQueue
|
||||
SlsService $slsService,
|
||||
AiService $aiService,
|
||||
CodeContextService $codeContextService,
|
||||
CodeAnalysisService $codeAnalysisService,
|
||||
ConfigService $configService,
|
||||
DingTalkService $dingTalkService
|
||||
): void {
|
||||
@@ -85,28 +87,30 @@ class LogAnalysisJob implements ShouldQueue
|
||||
$appLogsCollection = $appLogsCollection->take($maxLogsPerApp);
|
||||
}
|
||||
|
||||
// 获取代码上下文(如果需要)
|
||||
$codeContext = null;
|
||||
if ($this->mode === AnalysisMode::LogsWithCode) {
|
||||
$repoPath = $codeContextService->getRepoPath($appName);
|
||||
if ($repoPath) {
|
||||
$codeContext = $codeContextService->extractRelevantCode($repoPath, $appLogsCollection);
|
||||
}
|
||||
}
|
||||
|
||||
// 准备日志内容
|
||||
$logsContent = $this->formatLogsForAnalysis($appLogsCollection);
|
||||
|
||||
// AI 分析
|
||||
// AI 分析(不再携带代码上下文)
|
||||
try {
|
||||
$results[$appName] = $aiService->analyzeLogs($logsContent, $codeContext);
|
||||
$results[$appName] = $aiService->analyzeLogs($logsContent, null);
|
||||
$results[$appName]['log_count'] = $appLogsCollection->count();
|
||||
$results[$appName]['has_code_context'] = $codeContext !== null;
|
||||
|
||||
// 如果是 logs+code 模式,且 impact 为 high/medium,触发代码分析
|
||||
if ($this->mode === AnalysisMode::LogsWithCode) {
|
||||
$impact = $results[$appName]['impact'] ?? 'unknown';
|
||||
if (in_array($impact, ['high', 'medium'])) {
|
||||
$codeAnalysisResult = $codeAnalysisService->analyze(
|
||||
$appName,
|
||||
$logsContent,
|
||||
$results[$appName]['summary'] ?? null
|
||||
);
|
||||
$results[$appName]['code_analysis'] = $codeAnalysisResult;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$results[$appName] = [
|
||||
'error' => $e->getMessage(),
|
||||
'log_count' => $appLogsCollection->count(),
|
||||
'has_code_context' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user