fix(huanke): normalize base url to avoid v1/v1beta path
This commit is contained in:
parent
c4da49e126
commit
e010c9b643
@ -7,6 +7,20 @@ interface HuankeGeminiConfig {
|
||||
baseURL: string;
|
||||
}
|
||||
|
||||
function normalizeHuankeBaseURL(baseURL: string): string {
|
||||
let normalized = (baseURL || "").trim().replace(/\/+$/, "");
|
||||
|
||||
normalized = normalized.replace(/\/v1beta\/models\/.*$/i, "");
|
||||
normalized = normalized.replace(/\/v1beta$/i, "");
|
||||
normalized = normalized.replace(/\/v1$/i, "");
|
||||
|
||||
if (!normalized) {
|
||||
return "https://api.huandutech.com";
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function redactSecrets(text: string, secrets: string[] = []) {
|
||||
let output = text;
|
||||
for (const secret of secrets) {
|
||||
@ -386,9 +400,10 @@ async function sendHuankeGeminiRequest(
|
||||
imageSize?: string;
|
||||
}
|
||||
): Promise<HuankeGeminiResponse> {
|
||||
const normalizedBaseURL = normalizeHuankeBaseURL(baseURL);
|
||||
// 构建 Gemini 原生格式的端点
|
||||
// 例如: https://api.example.com/v1beta/models/gemini-3-pro-image-preview-4k:generateContent
|
||||
const url = `${baseURL}/v1beta/models/${modelId}:generateContent?key=${apiKey}`;
|
||||
const url = `${normalizedBaseURL}/v1beta/models/${modelId}:generateContent?key=${apiKey}`;
|
||||
|
||||
console.log("[Huanke Gemini] Sending request to:", redactSecrets(url, [apiKey]));
|
||||
console.log("[Huanke Gemini] Using model:", modelId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user