mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:30:42 +00:00
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import type { StreamFn } from "@mariozechner/pi-agent-core";
|
|
import type { ProviderWrapStreamFnContext } from "openclaw/plugin-sdk/plugin-entry";
|
|
import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
|
|
import {
|
|
createPayloadPatchStreamWrapper,
|
|
isOpenAICompatibleThinkingEnabled,
|
|
} from "openclaw/plugin-sdk/provider-stream-shared";
|
|
|
|
type QwenThinkingLevel = ProviderWrapStreamFnContext["thinkingLevel"];
|
|
|
|
function isQwenProviderId(providerId: string): boolean {
|
|
const normalized = normalizeProviderId(providerId);
|
|
return (
|
|
normalized === "qwen" ||
|
|
normalized === "modelstudio" ||
|
|
normalized === "qwencloud" ||
|
|
normalized === "dashscope"
|
|
);
|
|
}
|
|
|
|
export function createQwenThinkingWrapper(
|
|
baseStreamFn: StreamFn | undefined,
|
|
thinkingLevel: QwenThinkingLevel,
|
|
): StreamFn {
|
|
return createPayloadPatchStreamWrapper(
|
|
baseStreamFn,
|
|
({ payload: payloadObj, options }) => {
|
|
const enableThinking = isOpenAICompatibleThinkingEnabled({ thinkingLevel, options });
|
|
payloadObj.enable_thinking = enableThinking;
|
|
delete payloadObj.reasoning_effort;
|
|
delete payloadObj.reasoningEffort;
|
|
delete payloadObj.reasoning;
|
|
},
|
|
{
|
|
shouldPatch: ({ model }) => model.api === "openai-completions" && model.reasoning,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function wrapQwenProviderStream(ctx: ProviderWrapStreamFnContext): StreamFn | undefined {
|
|
if (!isQwenProviderId(ctx.provider) || (ctx.model && ctx.model.api !== "openai-completions")) {
|
|
return undefined;
|
|
}
|
|
return createQwenThinkingWrapper(ctx.streamFn, ctx.thinkingLevel);
|
|
}
|