Compare commits

...

14 Commits

Author SHA1 Message Date
jiantw83 4a67dec32a feat: 階段三 - AI 語意去重,失敗時降級保留所有問題 2026-05-11 09:40:38 +00:00
jiantw83 5c5660a34b feat: update OpenAI base URL to use OpenRouter API 2026-05-11 09:37:53 +00:00
jiantw83 6ecb018ef4 feat: update OpenAI base URL to use OpenRouter API 2026-05-11 09:37:01 +00:00
jiantw83 02529a4ec9 feat: update OpenAI API key in README.md 2026-05-11 09:34:43 +00:00
jiantw83 624a71836c feat: update AI Code Review step to use OpenAI API key and base URL 2026-05-11 09:31:01 +00:00
jiantw83 fb1254aa32 feat: refactor AI Code Review step to use OLLAMA_BASE_URL and OLLAMA_MODEL
Co-authored-by: Copilot <copilot@github.com>
2026-05-11 09:10:20 +00:00
jiantw83 6eae6eb0ce feat: add OPENAI_MODEL parameter to AI Code Review step 2026-05-11 09:07:21 +00:00
jiantw83 ed1f2bea15 feat: update AI Code Review step to use DeepSeek API and correct API key
Co-authored-by: Copilot <copilot@github.com>
2026-05-11 09:03:03 +00:00
jiantw83 9a11d25c00 revert: 移除 DeepSeek-R1 特別處理 2026-05-11 08:58:59 +00:00
jiantw83 64b904dd07 fix: 支援不接受 system role 的模型(DeepSeek-R1) 2026-05-11 08:56:48 +00:00
jiantw83 73c11129ab feat: update AI Code Review step to use new OpenAI base URL and model 2026-05-11 08:55:53 +00:00
jiantw83 7ba2af3384 feat: update OPENAI_MODEL to use DeepSeek-R1-Distill-Qwen-32B for improved performance 2026-05-11 08:54:13 +00:00
jiantw83 aca76f23af feat: add OPENAI_MODEL parameter to AI Code Review step 2026-05-11 08:53:03 +00:00
jiantw83 bdf8d8a797 feat: update AI Code Review step to use OpenAI API key and base URL 2026-05-11 08:47:34 +00:00
4 changed files with 45 additions and 6 deletions
+2 -2
View File
@@ -28,8 +28,8 @@ jobs:
- name: AI Code Review - name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@v${{ needs.version.outputs.version }} uses: https://gitea.jsc.idv.tw/jiantw83/code-review@v${{ needs.version.outputs.version }}
with: with:
OLLAMA_BASE_URL: ${{ vars.OLLAMA_BASE_URL }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OLLAMA_MODEL: ${{ vars.OLLAMA_MODEL }} OPENAI_BASE_URL: https://openrouter.ai/api/v1
permissions: permissions:
contents: write contents: write
pull-requests: write pull-requests: write
+3 -1
View File
@@ -41,8 +41,10 @@ jobs:
- name: AI Code Review - name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }} uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
with: with:
# Github (h3285@evertrust.com.tw)
# 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
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: https://api.openai.com/v1 OPENAI_BASE_URL: https://openrouter.ai/api/v1
permissions: permissions:
contents: write contents: write
pull-requests: write pull-requests: write
+32
View File
@@ -61,3 +61,35 @@ export function mergeFindings(oldFindings, newFindings) {
export function sortByLevel(findings) { export function sortByLevel(findings) {
return [...findings].sort((a, b) => LEVELS.indexOf(a.level) - LEVELS.indexOf(b.level)); return [...findings].sort((a, b) => LEVELS.indexOf(a.level) - LEVELS.indexOf(b.level));
} }
/**
* 呼叫 LLM 進行語意去重,回傳去重後的 findings
* 失敗時降級回傳原始 findings
*/
export async function deduplicateWithAI(findings) {
if (findings.length === 0) return findings;
const systemPrompt = `你是一位程式碼審查問題去重專家。
給你一份問題清單(JSON 陣列),請移除語意重複的問題(即使描述文字不同,但指的是同一個問題)。
保留等級較高的版本,優先保留 critical > warning > info。
只回傳去重後的 JSON 陣列,不要有其他文字。`;
const userContent = `以下是問題清單,請去除語意重複的項目:\n\n${JSON.stringify(findings, null, 2)}`;
try {
const result = await chatJSON(systemPrompt, userContent);
if (Array.isArray(result) && result.length > 0) {
console.log(` AI 去重: ${findings.length} -> ${result.length}`);
return result;
}
throw new Error('AI 回傳空陣列');
} catch (e) {
const status = e.response?.status;
if (status === 402 || status === 429) {
console.log(` ⚠️ AI 去重失敗(${status} 額度/限流),降級:保留所有問題`);
} else {
console.log(` ⚠️ AI 去重失敗(${e.message}),降級:保留所有問題`);
}
return findings;
}
}
+8 -3
View File
@@ -1,7 +1,7 @@
import { GITEA_REPOSITORY, PR_NUMBER, PR_HEAD_BRANCH, PR_BASE_BRANCH, getLLMConfig } from './config.js'; import { GITEA_REPOSITORY, PR_NUMBER, PR_HEAD_BRANCH, PR_BASE_BRANCH, getLLMConfig } from './config.js';
import { loadRoles, getRoleIntro } from './roles.js'; import { loadRoles, getRoleIntro } from './roles.js';
import { getPRDiff, postComment } from './gitea.js'; import { getPRDiff, postComment } from './gitea.js';
import { analyzeWithRole, loadOldFindings, mergeFindings, sortByLevel } from './findings.js'; import { analyzeWithRole, loadOldFindings, mergeFindings, sortByLevel, deduplicateWithAI } from './findings.js';
const WORKSPACE = process.env.GITHUB_WORKSPACE || '/workspace'; const WORKSPACE = process.env.GITHUB_WORKSPACE || '/workspace';
@@ -66,8 +66,13 @@ async function main() {
console.log('\n🔀 Step3: Findings 合併'); console.log('\n🔀 Step3: Findings 合併');
const oldFindings = loadOldFindings(WORKSPACE); const oldFindings = loadOldFindings(WORKSPACE);
const mergedFindings = mergeFindings(oldFindings, newFindings); const mergedFindings = mergeFindings(oldFindings, newFindings);
const sorted = sortByLevel(mergedFindings); console.log(` Step3 merged findings total=${mergedFindings.length}`);
console.log(` Step3 merged findings total=${sorted.length} (critical=${sorted.filter(f=>f.level==='critical').length} warning=${sorted.filter(f=>f.level==='warning').length} info=${sorted.filter(f=>f.level==='info').length})`);
// Step3b: AI 語意去重
console.log('\n🤖 Step3b: AI 語意去重');
const deduped = await deduplicateWithAI(mergedFindings);
const sorted = sortByLevel(deduped);
console.log(` Step3b dedup findings total=${sorted.length} (critical=${sorted.filter(f=>f.level==='critical').length} warning=${sorted.filter(f=>f.level==='warning').length} info=${sorted.filter(f=>f.level==='info').length})`);
console.log('\n📝 Step4: Findings 寫入與 Comment 發布(待實作)'); console.log('\n📝 Step4: Findings 寫入與 Comment 發布(待實作)');
console.log(' [stub] 寫入 findings.json,發布 comment...'); console.log(' [stub] 寫入 findings.json,發布 comment...');