fix(ai): map Z.AI's sensitive finish reason to content-filter (#66643)

This commit is contained in:
Aiden Cline 2026-11-26 11:42:13 -06:00 • committed by GitHub
parent a956150945
commit ac2263f34c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -952,6 +952,8 @@ const mapFinishReason = Effect.fnUntraced(function* (event: OpenAIChatEvent, rea
case "length":
return "length" as const
case "content_filter":
// Z.AI ends a response its safety review blocked with "sensitive".
case "sensitive":
return "content-filter" as const
case "function_call":
case "tool_calls":

View file

@ -657,6 +657,16 @@ describe("OpenAI-compatible Chat route", () => {
}),
)
it.effect("maps Z.AI's sensitive finish to a content-filter finish", () =>
Effect.gen(function* () {
const filtered = yield* LLMClient.generate(request).pipe(
Effect.provide(fixedResponse(sseEvents(deltaChunk({}, "sensitive")))),
)
expect(filtered.finishReason).toEqual({ normalized: "content-filter", raw: "sensitive" })
}),
)
it.effect("names the content filter that blocked a response", () =>
Effect.gen(function* () {
const finish = (choice: object) =>