mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-06 14:51:08 +00:00
fix(providers): keep native modelstudio streaming usage compat
This commit is contained in:
@@ -4,6 +4,7 @@ type OpenAICompletionsCompatDefaultsInput = {
|
||||
provider?: string;
|
||||
endpointClass: ProviderEndpointClass;
|
||||
knownProviderFamily: string;
|
||||
supportsNativeStreamingUsageCompat?: boolean;
|
||||
usesExplicitProxyLikeEndpoint?: boolean;
|
||||
};
|
||||
|
||||
@@ -22,7 +23,12 @@ function isDefaultRouteProvider(provider: string | undefined, ...ids: string[])
|
||||
export function resolveOpenAICompletionsCompatDefaults(
|
||||
input: OpenAICompletionsCompatDefaultsInput,
|
||||
): OpenAICompletionsCompatDefaults {
|
||||
const { endpointClass, knownProviderFamily, usesExplicitProxyLikeEndpoint = false } = input;
|
||||
const {
|
||||
endpointClass,
|
||||
knownProviderFamily,
|
||||
supportsNativeStreamingUsageCompat = false,
|
||||
usesExplicitProxyLikeEndpoint = false,
|
||||
} = input;
|
||||
const isDefaultRoute = endpointClass === "default";
|
||||
const usesConfiguredNonOpenAIEndpoint =
|
||||
endpointClass !== "default" && endpointClass !== "openai-public";
|
||||
@@ -54,7 +60,8 @@ export function resolveOpenAICompletionsCompatDefaults(
|
||||
knownProviderFamily !== "mistral" &&
|
||||
endpointClass !== "xai-native" &&
|
||||
!usesExplicitProxyLikeEndpoint,
|
||||
supportsUsageInStreaming: !isNonStandard && !usesConfiguredNonOpenAIEndpoint,
|
||||
supportsUsageInStreaming:
|
||||
!isNonStandard && (!usesConfiguredNonOpenAIEndpoint || supportsNativeStreamingUsageCompat),
|
||||
supportsStrictMode: !isZai && !usesConfiguredNonOpenAIEndpoint,
|
||||
};
|
||||
}
|
||||
@@ -62,7 +69,10 @@ export function resolveOpenAICompletionsCompatDefaults(
|
||||
export function resolveOpenAICompletionsCompatDefaultsFromCapabilities(
|
||||
input: Pick<
|
||||
ProviderRequestCapabilities,
|
||||
"endpointClass" | "knownProviderFamily" | "usesExplicitProxyLikeEndpoint"
|
||||
| "endpointClass"
|
||||
| "knownProviderFamily"
|
||||
| "supportsNativeStreamingUsageCompat"
|
||||
| "usesExplicitProxyLikeEndpoint"
|
||||
> & {
|
||||
provider?: string;
|
||||
},
|
||||
|
||||
@@ -356,13 +356,13 @@ describe("openai transport stream", () => {
|
||||
expect(params.messages?.[0]).toMatchObject({ role: "system" });
|
||||
});
|
||||
|
||||
it("uses system role for ModelStudio-hosted completions providers", () => {
|
||||
it("uses system role and streaming usage compat for native ModelStudio completions providers", () => {
|
||||
const params = buildOpenAICompletionsParams(
|
||||
{
|
||||
id: "qwen3.6-plus",
|
||||
name: "Qwen 3.6 Plus",
|
||||
api: "openai-completions",
|
||||
provider: "custom-qwen",
|
||||
provider: "modelstudio",
|
||||
baseUrl: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
@@ -376,9 +376,13 @@ describe("openai transport stream", () => {
|
||||
tools: [],
|
||||
} as never,
|
||||
undefined,
|
||||
) as { messages?: Array<{ role?: string }> };
|
||||
) as {
|
||||
messages?: Array<{ role?: string }>;
|
||||
stream_options?: { include_usage?: boolean };
|
||||
};
|
||||
|
||||
expect(params.messages?.[0]).toMatchObject({ role: "system" });
|
||||
expect(params.stream_options).toMatchObject({ include_usage: true });
|
||||
});
|
||||
|
||||
it("disables developer-role-only compat defaults for configured custom proxy completions providers", () => {
|
||||
|
||||
Reference in New Issue
Block a user