UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

80 lines (79 loc) • 3.17 kB
import { n as normalizeGooglePreviewModelId } from "../../provider-model-id-normalize-DpMwcMeB.mjs"; import { h as readProviderJsonResponse, r as assertOkOrThrowProviderError } from "../../provider-http-errors-Dtgw3x-5.mjs"; import { d as postJsonRequest } from "../../shared-CfcMLHIP.mjs"; import "../../provider-http-LcawLneq.mjs"; import "../../model-id-DTVzKSqj.mjs"; import { o as GOOGLE_MEDIA_UNDERSTANDING_DEFAULT_MODELS, u as createGoogleMediaUnderstandingProviderMetadata } from "../../generation-provider-metadata-C-Rz3J9V.mjs"; import { t as resolveGoogleGenerativeAiHttpRequestConfig } from "../../http-request-kajy42Nf.mjs"; //#region extensions/google/media-understanding-provider.ts const DEFAULT_GOOGLE_AUDIO_PROMPT = "Transcribe the audio."; const DEFAULT_GOOGLE_VIDEO_PROMPT = "Describe the video."; async function generateGeminiInlineDataText(e) { const t = e.fetchFn ?? fetch; const n = e.model?.trim(); const r = n ? normalizeGooglePreviewModelId(n) : e.defaultModel; const { baseUrl: i, allowPrivateNetwork: a, headers: o, dispatcherPolicy: s } = resolveGoogleGenerativeAiHttpRequestConfig({ apiKey: e.apiKey, baseUrl: e.baseUrl, headers: e.headers, request: e.request, capability: e.defaultMime.startsWith("audio/") ? "audio" : "video", transport: "media-understanding" }); const c = `${i}/models/${r}:generateContent`; const l = { contents: [{ role: "user", parts: [{ text: e.prompt?.trim() || e.defaultPrompt }, { inline_data: { mime_type: e.mime ?? e.defaultMime, data: e.buffer.toString("base64") } }] }] }; const { response: u, release: d } = await postJsonRequest({ url: c, headers: o, body: l, timeoutMs: e.timeoutMs, ...e.signal ? { signal: e.signal } : {}, fetchFn: t, allowPrivateNetwork: a, dispatcherPolicy: s }); try { await assertOkOrThrowProviderError(u, e.httpErrorLabel, { requestHeaders: o }); const t = ((await readProviderJsonResponse(u, e.httpErrorLabel, { requestHeaders: o })).candidates?.[0]?.content?.parts ?? []).map((e) => e?.text?.trim()).filter(Boolean).join("\n"); if (!t) throw new Error(e.missingTextError); return { text: t, model: r }; } finally { await d(); } } async function transcribeGeminiAudio(e) { return await generateGeminiInlineDataText({ ...e, defaultModel: GOOGLE_MEDIA_UNDERSTANDING_DEFAULT_MODELS.audio, defaultPrompt: DEFAULT_GOOGLE_AUDIO_PROMPT, defaultMime: "audio/wav", httpErrorLabel: "Audio transcription failed", missingTextError: "Audio transcription response missing text" }); } async function describeGeminiVideo(e) { return await generateGeminiInlineDataText({ ...e, defaultModel: GOOGLE_MEDIA_UNDERSTANDING_DEFAULT_MODELS.video, defaultPrompt: DEFAULT_GOOGLE_VIDEO_PROMPT, defaultMime: "video/mp4", httpErrorLabel: "Video description failed", missingTextError: "Video description response missing text" }); } const googleMediaUnderstandingProvider = { ...createGoogleMediaUnderstandingProviderMetadata(), transcribeAudio: transcribeGeminiAudio, describeVideo: describeGeminiVideo }; //#endregion export { describeGeminiVideo, googleMediaUnderstandingProvider, transcribeGeminiAudio };