Feat: Add :online web search support for OpenAI

This commit is contained in:
2026-03-20 16:44:06 -07:00
parent 2389c07ea7
commit 425478cee1

View File

@@ -105,8 +105,11 @@ export async function streamOpenRouter({ apiKey, body, signal, onDelta, isRunnin
export async function streamOpenAI({ apiKey, body, signal, onDelta, isRunning }) {
const client = new OpenAI({ apiKey })
const online = (body.model ?? '').endsWith(':online')
const model = online ? body.model.slice(0, -7) : body.model
const params = {
model: body.model,
model,
input: buildInputForResponses(body.messages || []),
temperature: body.temperature,
stream: true,
@@ -116,6 +119,13 @@ export async function streamOpenAI({ apiKey, body, signal, onDelta, isRunning })
if (body.reasoning?.effort) params.reasoning = { effort: body.reasoning.effort }
if (body.verbosity) params.text = { verbosity: body.verbosity }
if (online) {
params.tools = [
...(params.tools || []),
{ type: 'web_search', external_web_access: true },
]
}
const stream = await client.responses.stream(params)
try {
for await (const event of stream) {
@@ -243,4 +253,3 @@ export async function streamGoogle({ apiKey, body, signal, onDelta, isRunning })
buf = buf.slice(buf.lastIndexOf('\n') + 1)
}
}