mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 23:14:31 +00:00
feat(openai): add websocket warm-up with configurable toggle
This commit is contained in:
@@ -46,6 +46,7 @@ export function resolveExtraParams(params: {
|
||||
type CacheRetention = "none" | "short" | "long";
|
||||
type CacheRetentionStreamOptions = Partial<SimpleStreamOptions> & {
|
||||
cacheRetention?: CacheRetention;
|
||||
openaiWsWarmup?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -124,6 +125,9 @@ function createStreamFnWithExtraParams(
|
||||
const transportSummary = typeof transport === "string" ? transport : typeof transport;
|
||||
log.warn(`ignoring invalid transport param: ${transportSummary}`);
|
||||
}
|
||||
if (typeof extraParams.openaiWsWarmup === "boolean") {
|
||||
streamParams.openaiWsWarmup = extraParams.openaiWsWarmup;
|
||||
}
|
||||
const cacheRetention = resolveCacheRetention(extraParams, provider);
|
||||
if (cacheRetention) {
|
||||
streamParams.cacheRetention = cacheRetention;
|
||||
@@ -321,11 +325,19 @@ function createCodexDefaultTransportWrapper(baseStreamFn: StreamFn | undefined):
|
||||
|
||||
function createOpenAIDefaultTransportWrapper(baseStreamFn: StreamFn | undefined): StreamFn {
|
||||
const underlying = baseStreamFn ?? streamSimple;
|
||||
return (model, context, options) =>
|
||||
underlying(model, context, {
|
||||
return (model, context, options) => {
|
||||
const typedOptions = options as
|
||||
| (SimpleStreamOptions & { openaiWsWarmup?: boolean })
|
||||
| undefined;
|
||||
return underlying(model, context, {
|
||||
...options,
|
||||
transport: options?.transport ?? "auto",
|
||||
// Warm-up is optional in OpenAI docs; enabled by default here for lower
|
||||
// first-turn latency on WebSocket sessions. Set params.openaiWsWarmup=false
|
||||
// to disable per model.
|
||||
openaiWsWarmup: typedOptions?.openaiWsWarmup ?? true,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function isAnthropic1MModel(modelId: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user