mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 19:40:22 +00:00
refactor: unify Google Generative AI normalization
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import { isRecord } from "../../utils.js";
|
||||
import { normalizeSecretInput } from "../../utils/normalize-secret-input.js";
|
||||
import { resolveGoogleGenerativeAiApiOrigin } from "../google-generative-ai.js";
|
||||
|
||||
type PdfInput = {
|
||||
base64: string;
|
||||
@@ -137,9 +138,7 @@ export async function geminiAnalyzePdf(params: {
|
||||
}
|
||||
parts.push({ text: params.prompt });
|
||||
|
||||
const baseUrl = (params.baseUrl ?? "https://generativelanguage.googleapis.com")
|
||||
.replace(/\/+$/, "")
|
||||
.replace(/\/v1beta$/, "");
|
||||
const baseUrl = resolveGoogleGenerativeAiApiOrigin(params.baseUrl);
|
||||
const url = `${baseUrl}/v1beta/models/${encodeURIComponent(params.modelId)}:generateContent?key=${encodeURIComponent(apiKey)}`;
|
||||
|
||||
const res = await fetch(url, {
|
||||
|
||||
@@ -748,6 +748,26 @@ describe("native PDF provider API calls", () => {
|
||||
expect(url).toContain("/v1beta/models/");
|
||||
expect(url).not.toContain("/v1beta/v1beta");
|
||||
});
|
||||
|
||||
it("geminiAnalyzePdf normalizes bare Google API hosts to a single /v1beta root", async () => {
|
||||
const { geminiAnalyzePdf } = await import("./pdf-native-providers.js");
|
||||
const fetchMock = mockFetchResponse({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
candidates: [{ content: { parts: [{ text: "ok" }] } }],
|
||||
}),
|
||||
});
|
||||
|
||||
await geminiAnalyzePdf(
|
||||
makeGeminiAnalyzeParams({
|
||||
baseUrl: "https://generativelanguage.googleapis.com",
|
||||
}),
|
||||
);
|
||||
|
||||
const [url] = fetchMock.mock.calls[0];
|
||||
expect(url).toContain("https://generativelanguage.googleapis.com/v1beta/models/");
|
||||
expect(url).not.toContain("/v1beta/v1beta");
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user