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
+15
View File
@@ -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 () => {