From 78ae7a53206edf1d8872ffe12cacf1c595cc23e1 Mon Sep 17 00:00:00 2001 From: liuhaibin0528 Date: Fri, 8 May 2026 23:56:26 +0800 Subject: [PATCH] fix(memos-local-plugin): handle full endpoint paths in openai_compatible probe When the user provides an endpoint that already includes the full path (e.g. https://open.bigmodel.cn/api/paas/v4/chat/completions for Zhipu AI / GLM models), the probe would previously append another /v1/chat/completions segment, resulting in a malformed URL. This fix checks if the endpoint already ends with the target path (/chat/completions or /embeddings) before appending, making the probe compatible with endpoints that specify the full URL. Affects both probeChat and probeEmbedding for openai_compatible provider. --- apps/memos-local-plugin/server/routes/models.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/memos-local-plugin/server/routes/models.ts b/apps/memos-local-plugin/server/routes/models.ts index ff82b5636..757aaed1d 100644 --- a/apps/memos-local-plugin/server/routes/models.ts +++ b/apps/memos-local-plugin/server/routes/models.ts @@ -163,9 +163,11 @@ async function probeEmbedding(req: TestRequest): Promise { case "openai_compatible": { if (!endpoint) throw new Error("endpoint is required for openai_compatible"); const base = endpoint.replace(/\/+$/, ""); - const url = base.endsWith("/v1") - ? `${base}/embeddings` - : `${base}/v1/embeddings`; + const url = base.endsWith("/embeddings") + ? base + : base.endsWith("/v1") + ? `${base}/embeddings` + : `${base}/v1/embeddings`; const r = await fetchJson(url, { method: "POST", headers: { ...authHeader(apiKey), "Content-Type": "application/json" }, @@ -263,9 +265,11 @@ async function probeChat(req: TestRequest): Promise { case "openai_compatible": { if (!endpoint) throw new Error("endpoint is required for openai_compatible"); const base = endpoint.replace(/\/+$/, ""); - const url = base.endsWith("/v1") - ? `${base}/chat/completions` - : `${base}/v1/chat/completions`; + const url = base.endsWith("/chat/completions") + ? base + : base.endsWith("/v1") + ? `${base}/chat/completions` + : `${base}/v1/chat/completions`; const r = await fetchJson(url, { method: "POST", headers: { ...authHeader(apiKey), "Content-Type": "application/json" },