Compare commits

..

10 Commits

5 changed files with 23 additions and 10 deletions
+4 -4
View File
@@ -21,16 +21,16 @@ jobs:
tag_name: v${{ steps.version.outputs.version }}
target_commitish: ${{ github.head_ref }}
code-review:
name: Code Review
name: 'Code Review'
runs-on: ubuntu
needs: [version]
steps:
- name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@v${{ needs.version.outputs.version }}
with:
# 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
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: https://openrouter.ai/api/v1
OPENAI_API_KEY: ${{ secrets.HF_API_KEY }}
OPENAI_BASE_URL: https://router.huggingface.co/novita/v1
OPENAI_MODEL: deepseek-ai/DeepSeek-R1
permissions:
contents: write
pull-requests: write
+2 -2
View File
@@ -262,8 +262,8 @@ jobs:
- name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
with:
OLLAMA_BASE_URL: ${{ secrets.OLLAMA_BASE_URL }}
OLLAMA_MODEL: ${{ secrets.OLLAMA_MODEL }}
OLLAMA_BASE_URL: ${{ vars.OLLAMA_BASE_URL }}
OLLAMA_MODEL: ${{ vars.OLLAMA_MODEL }}
permissions:
contents: write
pull-requests: write
+1
View File
@@ -29,6 +29,7 @@ inputs:
OPENAI_BASE_URL:
description: 'OpenAI-compatible Base URL'
required: false
default: 'https://openrouter.ai/api/v1'
OPENAI_MODEL:
description: 'OpenAI-compatible Model Name'
required: false
+4 -2
View File
@@ -1,15 +1,17 @@
import axios from 'axios';
import https from 'https';
import { GITEA_TOKEN, GITEA_SERVER_URL, GITEA_REPOSITORY, PR_NUMBER } from './config.js';
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
const headers = () => ({ Authorization: `token ${GITEA_TOKEN}`, 'Content-Type': 'application/json' });
const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`;
export async function getPRDiff() {
const resp = await axios.get(api(`/repos/${GITEA_REPOSITORY}/pulls/${PR_NUMBER}.diff`), { headers: headers(), timeout: 60000 });
const resp = await axios.get(api(`/repos/${GITEA_REPOSITORY}/pulls/${PR_NUMBER}.diff`), { headers: headers(), timeout: 60000, httpsAgent });
return resp.data;
}
export async function postComment(body) {
const resp = await axios.post(api(`/repos/${GITEA_REPOSITORY}/issues/${PR_NUMBER}/comments`), { body }, { headers: headers(), timeout: 30000 });
const resp = await axios.post(api(`/repos/${GITEA_REPOSITORY}/issues/${PR_NUMBER}/comments`), { body }, { headers: headers(), timeout: 30000, httpsAgent });
return resp.data;
}
+12 -2
View File
@@ -1,6 +1,9 @@
import axios from 'axios';
import https from 'https';
import { getLLMConfig } from './config.js';
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
export async function chat(systemPrompt, userContent) {
const { provider, apiKey, baseURL, model } = getLLMConfig();
if (!provider) throw new Error('未設定任何 LLM API Key');
@@ -13,10 +16,17 @@ export async function chat(systemPrompt, userContent) {
};
if (provider === 'claude') headers['anthropic-version'] = '2023-06-01';
// 部分模型(如 DeepSeek-R1)不支援 system role,改合併到 user message
const NO_SYSTEM_ROLE_MODELS = ['deepseek-ai/deepseek-r1', 'deepseek-r1'];
const isNoSystemRole = NO_SYSTEM_ROLE_MODELS.some(m => model.toLowerCase().includes(m.toLowerCase()));
const messages = isNoSystemRole
? [{ role: 'user', content: `${systemPrompt}\n\n${userContent}` }]
: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userContent }];
const resp = await axios.post(
`${baseURL.replace(/\/$/, '')}/chat/completions`,
{ model, messages: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userContent }], temperature: 0.2 },
{ headers, timeout: 120000 }
{ model, messages, temperature: 0.2 },
{ headers, timeout: 120000, httpsAgent }
);
return resp.data.choices[0].message.content;
}