add default_settings to metadata

This commit is contained in:
maryhipp 2024-02-29 14:49:37 -05:00
parent 6e0665e3d7
commit f69e3ee01c
3 changed files with 21 additions and 2 deletions

View File

@ -267,11 +267,15 @@ async def update_model_metadata(
try: try:
original_metadata = record_store.get_metadata(key) original_metadata = record_store.get_metadata(key)
if original_metadata: if original_metadata:
if changes.trigger_phrases:
original_metadata.trigger_phrases = changes.trigger_phrases original_metadata.trigger_phrases = changes.trigger_phrases
if changes.default_settings:
original_metadata.default_settings = changes.default_settings
metadata_store.update_metadata(key, original_metadata) metadata_store.update_metadata(key, original_metadata)
else: else:
metadata_store.add_metadata(key, BaseMetadata(name="", author="",trigger_phrases=changes.trigger_phrases)) metadata_store.add_metadata(key, BaseMetadata(name="", author="",trigger_phrases=changes.trigger_phrases, default_settings=changes.default_settings))
except Exception as e: except Exception as e:
raise HTTPException( raise HTTPException(
status_code=500, status_code=500,

View File

@ -10,17 +10,22 @@ from pydantic import Field
from invokeai.app.util.model_exclude_null import BaseModelExcludeNull from invokeai.app.util.model_exclude_null import BaseModelExcludeNull
from invokeai.backend.model_manager.metadata import AnyModelRepoMetadata from invokeai.backend.model_manager.metadata import AnyModelRepoMetadata
from invokeai.backend.model_manager.metadata.metadata_base import ModelDefaultSettings
class ModelMetadataChanges(BaseModelExcludeNull, extra="allow"): class ModelMetadataChanges(BaseModelExcludeNull, extra="allow"):
"""A set of changes to apply to model metadata. """A set of changes to apply to model metadata.
Only limited changes are valid: Only limited changes are valid:
- `trigger_phrases`: the list of trigger phrases for this model - `trigger_phrases`: the list of trigger phrases for this model
- `default_settings`: the user-configured default settings for this model
""" """
trigger_phrases: Optional[List[str]] = Field(default=None, description="The model's list of trigger phrases") trigger_phrases: Optional[List[str]] = Field(default=None, description="The model's list of trigger phrases")
"""The model's list of trigger phrases""" """The model's list of trigger phrases"""
default_settings: Optional[ModelDefaultSettings] = Field(default=None, description="The user-configured default settings for this model")
"""The user-configured default settings for this model"""
class ModelMetadataStoreBase(ABC): class ModelMetadataStoreBase(ABC):
"""Store, search and fetch model metadata retrieved from remote repositories.""" """Store, search and fetch model metadata retrieved from remote repositories."""

View File

@ -24,6 +24,7 @@ from pydantic import BaseModel, Field, TypeAdapter
from pydantic.networks import AnyHttpUrl from pydantic.networks import AnyHttpUrl
from requests.sessions import Session from requests.sessions import Session
from typing_extensions import Annotated from typing_extensions import Annotated
from invokeai.app.invocations.constants import SCHEDULER_NAME_VALUES
from invokeai.backend.model_manager import ModelRepoVariant from invokeai.backend.model_manager import ModelRepoVariant
@ -68,6 +69,14 @@ class RemoteModelFile(BaseModel):
sha256: Optional[str] = Field(description="SHA256 hash of this model (not always available)", default=None) sha256: Optional[str] = Field(description="SHA256 hash of this model (not always available)", default=None)
class ModelDefaultSettings(BaseModel):
vae: str | None
vae_precision: str | None
scheduler: SCHEDULER_NAME_VALUES | None
steps: int | None
cfg_scale: float | None
cfg_rescale_multiplier: float | None
class ModelMetadataBase(BaseModel): class ModelMetadataBase(BaseModel):
"""Base class for model metadata information.""" """Base class for model metadata information."""
@ -75,6 +84,7 @@ class ModelMetadataBase(BaseModel):
author: str = Field(description="model's author") author: str = Field(description="model's author")
tags: Optional[Set[str]] = Field(description="tags provided by model source", default=None) tags: Optional[Set[str]] = Field(description="tags provided by model source", default=None)
trigger_phrases: Optional[List[str]] = Field(description="trigger phrases for this model", default=None) trigger_phrases: Optional[List[str]] = Field(description="trigger phrases for this model", default=None)
default_settings: Optional[ModelDefaultSettings] = Field(description="default settings for this model", default=None)
class BaseMetadata(ModelMetadataBase): class BaseMetadata(ModelMetadataBase):