Set friendly name for auto loaded chat models during first run

The chat model friendly name field was introduced in a8c47a70f. But
we weren't setting the friendly name for ollama models, which get
automatically loaded on first run.

This broke setting chat model options, server admin settings and
creating new chat pages (at least) as they display the chat model's
friendly name.

This change ensures the friendly name for auto loaded chat models is
set to resolve these issues. We also add a null ref check to web app
model selector as an additional safeguard to prevent new chat page
crash due to missing friendly name going forward.

Resolves #1208
This commit is contained in:
Debanjum
2025-07-15 14:12:37 -07:00
parent 0a06f5b41a
commit 76ed97d066
2 changed files with 3 additions and 1 deletions

View File

@@ -92,7 +92,7 @@ export function ModelSelector({ ...props }: ModelSelectorProps) {
disabled={props.disabled ?? false}
>
<p className="truncate">
{selectedModel ? selectedModel.name.substring(0, 20) : "Select a model..."}
{selectedModel ? selectedModel.name?.substring(0, 20) : "Select a model..."}
</p>
<CaretUpDown className="opacity-50" />
</Button>

View File

@@ -235,6 +235,7 @@ def initialization(interactive: bool = True):
chat_model_options = {
"name": chat_model,
"friendly_name": chat_model,
"model_type": model_type,
"max_prompt_size": default_max_tokens,
"vision_enabled": vision_enabled,
@@ -275,6 +276,7 @@ def initialization(interactive: bool = True):
if not existing_models.filter(name=model_name).exists():
ChatModel.objects.create(
name=model_name,
friendly_name=model_name,
model_type=ChatModel.ModelType.OPENAI,
max_prompt_size=model_to_prompt_size.get(model_name),
vision_enabled=model_name in default_openai_chat_models,