Repository navigation
fix(translator): normalize developer role to system #4625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
|
|
||
| import { filterToOpenAIFormat } from "../../open-sse/translator/helpers/openaiHelper.ts"; | ||
|
|
||
| // Ported from upstream decolua/9router#1011 — many OpenAI-compatible providers | ||
| // reject the `developer` role (introduced by OpenAI Responses API). Normalize to | ||
| // `system` so passthrough requests keep working downstream. | ||
| test("filterToOpenAIFormat normalizes developer role to system", () => { | ||
| const body = { | ||
| messages: [ | ||
| { role: "developer", content: "You are helpful" }, | ||
| { role: "user", content: "Hi" }, | ||
| ], | ||
| }; | ||
|
|
||
| const out = filterToOpenAIFormat(body); | ||
|
|
||
| assert.equal(out.messages[0].role, "system"); | ||
| assert.equal(out.messages[0].content, "You are helpful"); | ||
| assert.equal(out.messages[1].role, "user"); | ||
| }); | ||
|
|
||
| test("filterToOpenAIFormat normalizes developer role with array content", () => { | ||
| const body = { | ||
| messages: [ | ||
| { | ||
| role: "developer", | ||
| content: [{ type: "text", text: "Be concise" }], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const out = filterToOpenAIFormat(body); | ||
|
|
||
| assert.equal(out.messages[0].role, "system"); | ||
| assert.deepEqual(out.messages[0].content, [{ type: "text", text: "Be concise" }]); | ||
| }); | ||
|
Comment on lines
+1
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The repository uses Vitest as its primary test runner (as indicated by import { test, expect } from "vitest";
import { filterToOpenAIFormat } from "../../open-sse/translator/helpers/openaiHelper.ts";
// Ported from upstream decolua/9router#1011 — many OpenAI-compatible providers
// reject the developer role (introduced by OpenAI Responses API). Normalize to
// system so passthrough requests keep working downstream.
test("filterToOpenAIFormat normalizes developer role to system", () => {
const body = {
messages: [
{ role: "developer", content: "You are helpful" },
{ role: "user", content: "Hi" },
],
};
const out = filterToOpenAIFormat(body);
expect(out.messages[0].role).toBe("system");
expect(out.messages[0].content).toBe("You are helpful");
expect(out.messages[1].role).toBe("user");
});
test("filterToOpenAIFormat normalizes developer role with array content", () => {
const body = {
messages: [
{
role: "developer",
content: [{ type: "text", text: "Be concise" }],
},
],
};
const out = filterToOpenAIFormat(body);
expect(out.messages[0].role).toBe("system");
expect(out.messages[0].content).toEqual([{ type: "text", text: "Be concise" }]);
});References
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent potential runtime crashes if
msgis null, undefined, or not an object (e.g., if a client sends a malformed payload), we should add a defensive check at the beginning of the map function before accessing any properties likemsg.role.References