From f94c08072ead8400d2471fbd7ad3aec0738d9011 Mon Sep 17 00:00:00 2001 From: Ivan Pereira <183991+ivanrvpereira@users.noreply.github.com> Date: Thu, 16 Jul 2026 15:56:46 +0100 Subject: [PATCH] feat(models): add GLM-5.2 and harden reported-model fallback Perplexity's model fields are inconsistent per model: Claude Sonnet 5 reports the real slug in user_selected_model with display_model "turbo", while GLM-5.2 reports the inverse. Pick whichever field is present and not "turbo", and fall back to the requested model when both are missing or "turbo". Also add glm_5_2 to KNOWN_MODELS. Refs #7 (follow-up comment) --- src/search/client.ts | 12 +++++++----- src/search/models.ts | 1 + test/search/client.test.ts | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/search/client.ts b/src/search/client.ts index 5dd7705..503a67f 100644 --- a/src/search/client.ts +++ b/src/search/client.ts @@ -284,12 +284,14 @@ export async function searchPerplexity( answer: answer || "No answer text returned by Perplexity.", sources, }; - // Prefer user_selected_model: display_model may report "turbo" even when the - // requested model was honored (see issue #7). + // The stream's model fields are inconsistent: either user_selected_model or + // display_model may report "turbo" even when the requested model was honored + // (see issue #7). Prefer whichever is present and not "turbo"; if both are + // missing or "turbo", fall back to the requested model. const reportedModel = - snapshot.user_selected_model && snapshot.user_selected_model !== "turbo" - ? snapshot.user_selected_model - : snapshot.display_model; + [snapshot.user_selected_model, snapshot.display_model].find( + (model) => model && model !== "turbo", + ) ?? params.model; if (reportedModel !== undefined) result.displayModel = reportedModel; if (snapshot.uuid !== undefined) result.uuid = snapshot.uuid; diff --git a/src/search/models.ts b/src/search/models.ts index 6cc5f51..013a2ef 100644 --- a/src/search/models.ts +++ b/src/search/models.ts @@ -35,4 +35,5 @@ export const KNOWN_MODELS: ModelOption[] = [ { value: "grok4", label: "Grok 4 Thinking" }, { value: "nv_nemotron_3_super", label: "Nemotron 3 Super" }, { value: "kimik25thinking", label: "Kimi K2.5 Thinking" }, + { value: "glm_5_2", label: "GLM-5.2" }, ]; diff --git a/test/search/client.test.ts b/test/search/client.test.ts index fc5e6a2..6c539da 100644 --- a/test/search/client.test.ts +++ b/test/search/client.test.ts @@ -309,6 +309,21 @@ describe("searchPerplexity", () => { const fallback = await searchPerplexity({ query: "q", model: "pplx_pro_upgraded" }, "jwt"); expect(fallback.displayModel).toBe("pplx_pro_upgraded"); + + globalThis.fetch = (async () => + createSseResponse([ + { + status: "COMPLETED", + final: true, + text: "answer", + display_model: "turbo", + user_selected_model: "turbo", + sources_list: [{ title: "S", url: "https://example.com" }], + }, + ])) as unknown as typeof fetch; + + const requested = await searchPerplexity({ query: "q", model: "glm_5_2" }, "jwt"); + expect(requested.displayModel).toBe("glm_5_2"); }); test("returns EMPTY error when response has no answer and no sources", async () => {