From 50b83d7342560a15d9a9e4190decf5b42653197c Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 11 Jun 2025 17:04:00 +0700 Subject: [PATCH] fix: could not add custom models (#5241) * fix: could not add custom models * Update web-app/src/lib/completion.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * chore: remove hard coded ID string * fix: revert suggestion change --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- web-app/src/lib/completion.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/web-app/src/lib/completion.ts b/web-app/src/lib/completion.ts index 79813192a..1e8a5ec55 100644 --- a/web-app/src/lib/completion.ts +++ b/web-app/src/lib/completion.ts @@ -130,13 +130,36 @@ export const sendCompletion = async ( // TODO: Retrieve from extension settings baseURL: provider.base_url, }) + if ( + thread.model.id && + !(thread.model.id in Object.values(models).flat()) && + // eslint-disable-next-line @typescript-eslint/no-explicit-any + !tokenJS.extendedModelExist(providerName as any, thread.model?.id) + ) { + try { + tokenJS.extendModelList( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + providerName as any, + thread.model?.id, + // This is to inherit the model capabilities from another built-in model + // Can be anything that support all model capabilities + models.anthropic.models[0] + ) + } catch (error) { + console.error( + `Failed to extend model list for ${providerName} with model ${thread.model.id}:`, + error + ) + } + } // TODO: Add message history const completion = stream ? await tokenJS.chat.completions.create( { stream: true, - provider: providerName, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + provider: providerName as any, model: thread.model?.id, messages, tools: normalizeTools(tools),