mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 12:56:01 -06:00
fix(mistral): retain provider-returned streaming model as responseModel (#128066)
Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
This commit is contained in:
@@ -800,6 +800,27 @@ describe("Mistral provider", () => {
|
||||
cacheWrite: 0,
|
||||
totalTokens: 110,
|
||||
});
|
||||
expect(result.responseId).toBe("response-cache-usage");
|
||||
expect(result.responseModel).toBe("mistral-small-latest");
|
||||
});
|
||||
|
||||
it("omits responseModel when streamed model matches the requested id", async () => {
|
||||
mistralMockState.streamResult = {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield {
|
||||
data: {
|
||||
id: "response-same-model",
|
||||
model: "mistral-large-latest",
|
||||
choices: [{ finishReason: "stop", delta: { content: "ok" } }],
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const result = await runMistralFixture(context, { apiKey: "fixture" });
|
||||
|
||||
expect(result.responseId).toBe("response-same-model");
|
||||
expect(result).not.toHaveProperty("responseModel");
|
||||
});
|
||||
|
||||
it("preserves tool-result boundary whitespace in the request payload", async () => {
|
||||
|
||||
@@ -593,6 +593,11 @@ async function consumeChatStream(
|
||||
// Mistral's streamed CompletionChunk carries an id field. Keep the first non-empty one,
|
||||
// mirroring how OpenAI-style streaming exposes a stable response identifier per stream.
|
||||
output.responseId ||= chunk.id;
|
||||
// Retain the provider-returned model when it differs from the requested id so
|
||||
// routed responses are not misattributed, matching the OpenAI sibling stream.
|
||||
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) {
|
||||
output.responseModel ||= chunk.model;
|
||||
}
|
||||
|
||||
if (chunk.usage) {
|
||||
const promptTokens = chunk.usage.promptTokens || 0;
|
||||
|
||||
Reference in New Issue
Block a user