GigaChat: broaden leaked prelude stripping
This commit is contained in:
parent
62faef905a
commit
af83a32c9e
@ -22,11 +22,15 @@ function createSseStream(lines: string[]): Readable {
|
||||
}
|
||||
|
||||
describe("GigaChat leaked function-call prelude cleanup", () => {
|
||||
it("drops leaked assistant text preludes when a function call is present", async () => {
|
||||
it.each([
|
||||
"assistant function callrecipient{",
|
||||
"assistant function callweather{",
|
||||
"assistant function call recipient {",
|
||||
])("drops leaked assistant text prelude %p when a function call is present", async (prelude) => {
|
||||
request.mockResolvedValueOnce({
|
||||
status: 200,
|
||||
data: createSseStream([
|
||||
'data: {"choices":[{"delta":{"content":"assistant function callrecipient{","role":"assistant"},"index":0}]}',
|
||||
`data: {"choices":[{"delta":{"content":"${prelude}","role":"assistant"},"index":0}]}`,
|
||||
'data: {"choices":[{"delta":{"content":"","role":"assistant","function_call":{"name":"message","arguments":"{\\"action\\":\\"send\\",\\"message\\":\\"hello\\"}"}},"index":0}]}',
|
||||
"data: [DONE]",
|
||||
]),
|
||||
|
||||
@ -40,7 +40,7 @@ export type GigachatStreamOptions = {
|
||||
};
|
||||
|
||||
function stripLeakedFunctionCallPrelude(text: string): string {
|
||||
return text.replace(/^\s*assistant\s+function\s+call(?:recipient)?\{\s*/i, "");
|
||||
return text.replace(/^\s*assistant\s+function\s+call(?:\s*([A-Za-z0-9_.:/-]+))?\s*\{\s*/i, "");
|
||||
}
|
||||
|
||||
// ── Function name sanitization ──────────────────────────────────────────────
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user