Improve LLM model iteration and metadata handling

Added __iter__ to LlmModelMeta for dynamic model iteration and updated metadata retrieval to handle missing registry entries gracefully. Fixed BlockSchema cached_jsonschema initialization and improved discriminator mapping refresh logic. Updated NodeInputs to display beautified string if label is missing.
This commit is contained in:
Bentlybro
2026-01-22 10:00:06 +00:00
parent 226d2ef4a0
commit fbef81c0c9
4 changed files with 18 additions and 4 deletions

View File

@@ -114,6 +114,15 @@ class LlmModelMeta(type):
return cls(slug)
def __iter__(cls):
"""Iterate over all models from the registry.
Yields LlmModel instances for each model in the dynamic registry.
Used by __get_pydantic_json_schema__ to build model metadata.
"""
for model in llm_registry.iter_dynamic_models():
yield cls(model.slug)
class LlmModel(str, metaclass=LlmModelMeta):
"""
@@ -178,7 +187,12 @@ class LlmModel(str, metaclass=LlmModelMeta):
llm_model_metadata = {}
for model in cls:
model_name = model.value
metadata = model.metadata
# Use registry directly with None check to gracefully handle
# missing metadata during startup/import before registry is populated
metadata = llm_registry.get_llm_model_metadata(model_name)
if metadata is None:
# Skip models without metadata (registry not yet populated)
continue
llm_model_metadata[model_name] = {
"creator": metadata.creator_name,
"creator_name": metadata.creator_name,

View File

@@ -259,7 +259,7 @@ class BlockSchema(BaseModel):
super().__pydantic_init_subclass__(**kwargs)
# Reset cached JSON schema to prevent inheriting it from parent class
cls.cached_jsonschema = {}
cls.cached_jsonschema = None
credentials_fields = cls.get_credentials_fields()

View File

@@ -82,7 +82,7 @@ def refresh_llm_discriminator_mapping(field_schema: dict[str, Any]) -> None:
# Always refresh the mapping to get latest models
fresh_mapping = get_llm_discriminator_mapping()
if fresh_mapping:
if fresh_mapping is not None:
field_schema["discriminator_mapping"] = fresh_mapping

View File

@@ -1161,7 +1161,7 @@ const NodeStringInput: FC<{
value={option.value}
title={option.description}
>
{option.label}
{option.label || beautifyString(option.value)}
</SelectItem>
))}
</SelectContent>