fix: validate openrouter stt temperature · openclaw/openclaw@f5c7d77
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -153,6 +153,34 @@ describe("openrouter media understanding provider", () => {
|
153 | 153 | }); |
154 | 154 | }); |
155 | 155 | |
| 156 | +it("drops malformed temperature query options", async () => { |
| 157 | +for (const temperature of [Number.NaN, Number.POSITIVE_INFINITY]) { |
| 158 | +const release = vi.fn(async () => {}); |
| 159 | +postJsonRequestMock.mockResolvedValueOnce({ |
| 160 | +response: new Response(JSON.stringify({ text: "ok" }), { status: 200 }), |
| 161 | + release, |
| 162 | +}); |
| 163 | + |
| 164 | +await transcribeOpenRouterAudio({ |
| 165 | +buffer: Buffer.from("audio"), |
| 166 | +fileName: "voice.webm", |
| 167 | +apiKey: "sk-openrouter", |
| 168 | +timeoutMs: 5_000, |
| 169 | +query: { temperature }, |
| 170 | +fetchFn: fetch, |
| 171 | +}); |
| 172 | + |
| 173 | +expect(firstPostJsonRequest().body).toEqual({ |
| 174 | +model: "openai/whisper-large-v3-turbo", |
| 175 | +input_audio: { |
| 176 | +data: Buffer.from("audio").toString("base64"), |
| 177 | +format: "webm", |
| 178 | +}, |
| 179 | +}); |
| 180 | +postJsonRequestMock.mockClear(); |
| 181 | +} |
| 182 | +}); |
| 183 | + |
156 | 184 | it("falls back to filename extension when mime is missing", async () => { |
157 | 185 | const release = vi.fn(async () => {}); |
158 | 186 | postJsonRequestMock.mockResolvedValue({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import {
|
12 | 12 | requireTranscriptionText, |
13 | 13 | resolveProviderHttpRequestConfig, |
14 | 14 | } from "openclaw/plugin-sdk/provider-http"; |
| 15 | +import { asFiniteNumber } from "openclaw/plugin-sdk/string-coerce-runtime"; |
15 | 16 | import { OPENROUTER_BASE_URL } from "./provider-catalog.js"; |
16 | 17 | |
17 | 18 | const DEFAULT_OPENROUTER_AUDIO_TRANSCRIPTION_MODEL = "openai/whisper-large-v3-turbo"; |
@@ -123,6 +124,7 @@ export async function transcribeOpenRouterAudio(
|
123 | 124 | capability: "audio", |
124 | 125 | transport: "media-understanding", |
125 | 126 | }); |
| 127 | +const temperature = asFiniteNumber(params.query?.temperature); |
126 | 128 | |
127 | 129 | const { response, release } = await postJsonRequest({ |
128 | 130 | url: `${baseUrl}/audio/transcriptions`, |
@@ -134,9 +136,7 @@ export async function transcribeOpenRouterAudio(
|
134 | 136 | format, |
135 | 137 | }, |
136 | 138 | ...(params.language?.trim() ? { language: params.language.trim() } : {}), |
137 | | - ...(typeof params.query?.temperature === "number" |
138 | | - ? { temperature: params.query.temperature } |
139 | | - : {}), |
| 139 | + ...(temperature !== undefined ? { temperature } : {}), |
140 | 140 | }, |
141 | 141 | timeoutMs: params.timeoutMs, |
142 | 142 | fetchFn, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。