fix: 忽略 SSL 憑證驗證(支援自簽憑證的 Ollama/Gitea)

This commit is contained in:
2026-05-11 08:34:04 +00:00
parent 7b5decf46a
commit e183e31ce0
2 changed files with 8 additions and 3 deletions
+4 -2
View File
@@ -1,15 +1,17 @@
import axios from 'axios'; import axios from 'axios';
import https from 'https';
import { GITEA_TOKEN, GITEA_SERVER_URL, GITEA_REPOSITORY, PR_NUMBER } from './config.js'; 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 headers = () => ({ Authorization: `token ${GITEA_TOKEN}`, 'Content-Type': 'application/json' });
const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`; const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`;
export async function getPRDiff() { 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; return resp.data;
} }
export async function postComment(body) { 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; return resp.data;
} }
+4 -1
View File
@@ -1,6 +1,9 @@
import axios from 'axios'; import axios from 'axios';
import https from 'https';
import { getLLMConfig } from './config.js'; import { getLLMConfig } from './config.js';
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
export async function chat(systemPrompt, userContent) { export async function chat(systemPrompt, userContent) {
const { provider, apiKey, baseURL, model } = getLLMConfig(); const { provider, apiKey, baseURL, model } = getLLMConfig();
if (!provider) throw new Error('未設定任何 LLM API Key'); if (!provider) throw new Error('未設定任何 LLM API Key');
@@ -16,7 +19,7 @@ export async function chat(systemPrompt, userContent) {
const resp = await axios.post( const resp = await axios.post(
`${baseURL.replace(/\/$/, '')}/chat/completions`, `${baseURL.replace(/\/$/, '')}/chat/completions`,
{ model, messages: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userContent }], temperature: 0.2 }, { model, messages: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userContent }], temperature: 0.2 },
{ headers, timeout: 120000 } { headers, timeout: 120000, httpsAgent }
); );
return resp.data.choices[0].message.content; return resp.data.choices[0].message.content;
} }