mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 22:20:22 +00:00
fix: preserve generic DashScope streaming usage (#52395) (thanks @IVY-AI-gif)
This commit is contained in:
@@ -863,6 +863,33 @@ describe("openai transport stream", () => {
|
||||
expect(params.stream_options).toMatchObject({ include_usage: true });
|
||||
});
|
||||
|
||||
it("enables streaming usage compat for generic providers on native DashScope endpoints", () => {
|
||||
const params = buildOpenAICompletionsParams(
|
||||
{
|
||||
id: "glm-5",
|
||||
name: "GLM-5",
|
||||
api: "openai-completions",
|
||||
provider: "generic",
|
||||
baseUrl: "https://coding.dashscope.aliyuncs.com/v1",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 200000,
|
||||
maxTokens: 8192,
|
||||
} satisfies Model<"openai-completions">,
|
||||
{
|
||||
systemPrompt: "system",
|
||||
messages: [],
|
||||
tools: [],
|
||||
} as never,
|
||||
undefined,
|
||||
) as {
|
||||
stream_options?: { include_usage?: boolean };
|
||||
};
|
||||
|
||||
expect(params.stream_options).toMatchObject({ include_usage: true });
|
||||
});
|
||||
|
||||
it("disables developer-role-only compat defaults for configured custom proxy completions providers", () => {
|
||||
const params = buildOpenAICompletionsParams(
|
||||
{
|
||||
|
||||
@@ -572,6 +572,19 @@ describe("provider attribution", () => {
|
||||
supportsNativeStreamingUsageCompat: true,
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveProviderRequestCapabilities({
|
||||
provider: "generic",
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://coding.dashscope.aliyuncs.com/v1",
|
||||
capability: "llm",
|
||||
transport: "stream",
|
||||
}),
|
||||
).toMatchObject({
|
||||
endpointClass: "modelstudio-native",
|
||||
supportsNativeStreamingUsageCompat: true,
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveProviderRequestCapabilities({
|
||||
provider: "ollama",
|
||||
@@ -753,6 +766,28 @@ describe("provider attribution", () => {
|
||||
supportsNativeStreamingUsageCompat: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "generic provider on native DashScope completions",
|
||||
input: {
|
||||
provider: "generic",
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://coding-intl.dashscope.aliyuncs.com/v1",
|
||||
capability: "llm" as const,
|
||||
transport: "stream" as const,
|
||||
},
|
||||
expected: {
|
||||
knownProviderFamily: "generic",
|
||||
endpointClass: "modelstudio-native",
|
||||
isKnownNativeEndpoint: true,
|
||||
allowsOpenAIServiceTier: false,
|
||||
supportsOpenAIReasoningCompatPayload: false,
|
||||
allowsResponsesStore: false,
|
||||
supportsResponsesStoreField: false,
|
||||
shouldStripResponsesPromptCache: false,
|
||||
allowsAnthropicServiceTier: false,
|
||||
supportsNativeStreamingUsageCompat: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "native Google Gemini api",
|
||||
input: {
|
||||
|
||||
@@ -604,9 +604,10 @@ export function resolveProviderRequestCapabilities(
|
||||
policy.usesKnownNativeOpenAIEndpoint,
|
||||
shouldStripResponsesPromptCache:
|
||||
api !== undefined && OPENAI_RESPONSES_APIS.has(api) && policy.usesExplicitProxyLikeEndpoint,
|
||||
// Native endpoint class is the real signal here. Users can point a generic
|
||||
// provider key at Moonshot or DashScope and still need streaming usage.
|
||||
supportsNativeStreamingUsageCompat:
|
||||
(provider === "moonshot" && endpointClass === "moonshot-native") ||
|
||||
(provider === "modelstudio" && endpointClass === "modelstudio-native"),
|
||||
endpointClass === "moonshot-native" || endpointClass === "modelstudio-native",
|
||||
compatibilityFamily,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user