fix: strip unsupported message metadata for Groq (#11026)

5 — Groq rejeita chat multi-turn quando mensagens de assistant carregam metadata não suportada (model/messageId/sender). stripGroqUnsupportedFields agora remove esses campos, preservando role/content/tool_calls. Fix pequeno e focado, teste novo cobrindo o caso.
This commit is contained in:
lamcn1k9
2026-08-22 00:58:59 +07:00
committed by GitHub
parent 00dfdadf93
commit 8f0d0a0d03
2 changed files with 35 additions and 2 deletions

View File

@@ -56,12 +56,21 @@ export function stripGroqUnsupportedFields<T extends Record<string, unknown>>(bo
delete next.top_logprobs;
if (Array.isArray(next.messages)) {
next.messages = next.messages.map((m) => {
if (m && typeof m === "object" && "name" in m) {
const { name: _name, ...rest } = m as Record<string, unknown>;
if (m && typeof m === "object") {
const {
name: _name,
model: _model,
messageId: _msgId,
sender: _sender,
...rest
} = m as Record<string, unknown>;
return rest;
}
return m;
});
}
return next as T;
}

View File

@@ -53,3 +53,27 @@ test("stripGroqUnsupportedFields is immutable (does not mutate input)", () => {
assert.equal(input.messages[0].name, "bob");
assert.equal(input.logprobs, true);
});
test("stripGroqUnsupportedFields drops unsupported messages[].model and other metadata while keeping role and content", () => {
const out = stripGroqUnsupportedFields({
messages: [
{ role: "user", content: "hello" },
{
role: "assistant",
content: "hello!",
model: "groq/openai/gpt-oss-20b",
messageId: "msg_123",
sender: "assistant",
},
],
});
assert.equal(out.messages.length, 2);
assert.equal(out.messages[0].role, "user");
assert.equal(out.messages[0].content, "hello");
assert.equal(out.messages[1].role, "assistant");
assert.equal(out.messages[1].content, "hello!");
assert.equal("model" in out.messages[1], false);
assert.equal("messageId" in out.messages[1], false);
assert.equal("sender" in out.messages[1], false);
});