mirror of
https://github.com/sune-org/us.proxy.sune.chat.git
synced 2026-04-07 02:02:13 +00:00
Feat: Add :online web search support for OpenAI
This commit is contained in:
13
providers.js
13
providers.js
@@ -105,8 +105,11 @@ export async function streamOpenRouter({ apiKey, body, signal, onDelta, isRunnin
|
|||||||
|
|
||||||
export async function streamOpenAI({ apiKey, body, signal, onDelta, isRunning }) {
|
export async function streamOpenAI({ apiKey, body, signal, onDelta, isRunning }) {
|
||||||
const client = new OpenAI({ apiKey })
|
const client = new OpenAI({ apiKey })
|
||||||
|
const online = (body.model ?? '').endsWith(':online')
|
||||||
|
const model = online ? body.model.slice(0, -7) : body.model
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
model: body.model,
|
model,
|
||||||
input: buildInputForResponses(body.messages || []),
|
input: buildInputForResponses(body.messages || []),
|
||||||
temperature: body.temperature,
|
temperature: body.temperature,
|
||||||
stream: true,
|
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.reasoning?.effort) params.reasoning = { effort: body.reasoning.effort }
|
||||||
if (body.verbosity) params.text = { verbosity: body.verbosity }
|
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)
|
const stream = await client.responses.stream(params)
|
||||||
try {
|
try {
|
||||||
for await (const event of stream) {
|
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)
|
buf = buf.slice(buf.lastIndexOf('\n') + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user