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)
This commit is contained in:
Ivan Pereira
2026-07-16 15:59:30 +01:00
parent 9f5c87c1c4
commit f94c08072e
3 changed files with 23 additions and 5 deletions
+7 -5
View File
@@ -284,12 +284,14 @@ export async function searchPerplexity(
answer: answer || "No answer text returned by Perplexity.", answer: answer || "No answer text returned by Perplexity.",
sources, sources,
}; };
// Prefer user_selected_model: display_model may report "turbo" even when the // The stream's model fields are inconsistent: either user_selected_model or
// requested model was honored (see issue #7). // 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 = const reportedModel =
snapshot.user_selected_model && snapshot.user_selected_model !== "turbo" [snapshot.user_selected_model, snapshot.display_model].find(
? snapshot.user_selected_model (model) => model && model !== "turbo",
: snapshot.display_model; ) ?? params.model;
if (reportedModel !== undefined) result.displayModel = reportedModel; if (reportedModel !== undefined) result.displayModel = reportedModel;
if (snapshot.uuid !== undefined) result.uuid = snapshot.uuid; if (snapshot.uuid !== undefined) result.uuid = snapshot.uuid;
+1
View File
@@ -35,4 +35,5 @@ export const KNOWN_MODELS: ModelOption[] = [
{ value: "grok4", label: "Grok 4 Thinking" }, { value: "grok4", label: "Grok 4 Thinking" },
{ value: "nv_nemotron_3_super", label: "Nemotron 3 Super" }, { value: "nv_nemotron_3_super", label: "Nemotron 3 Super" },
{ value: "kimik25thinking", label: "Kimi K2.5 Thinking" }, { value: "kimik25thinking", label: "Kimi K2.5 Thinking" },
{ value: "glm_5_2", label: "GLM-5.2" },
]; ];
+15
View File
@@ -309,6 +309,21 @@ describe("searchPerplexity", () => {
const fallback = await searchPerplexity({ query: "q", model: "pplx_pro_upgraded" }, "jwt"); const fallback = await searchPerplexity({ query: "q", model: "pplx_pro_upgraded" }, "jwt");
expect(fallback.displayModel).toBe("pplx_pro_upgraded"); 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 () => { test("returns EMPTY error when response has no answer and no sources", async () => {