also make None a valid option for options API for #11854

This commit is contained in:
AUTOMATIC1111 2023-07-18 11:48:40 +03:00
parent 6be5ccb530
commit 420cc8f68e

View File

@ -1,4 +1,6 @@
import inspect import inspect
import types
from pydantic import BaseModel, Field, create_model from pydantic import BaseModel, Field, create_model
from typing import Any, Optional from typing import Any, Optional
from typing_extensions import Literal from typing_extensions import Literal
@ -207,11 +209,14 @@ class PreprocessResponse(BaseModel):
fields = {} fields = {}
for key, metadata in opts.data_labels.items(): for key, metadata in opts.data_labels.items():
value = opts.data.get(key) value = opts.data.get(key)
if key == 'sd_model_checkpoint':
value = None
optType = opts.typemap.get(type(metadata.default), type(value)) optType = opts.typemap.get(type(metadata.default), type(value))
if (metadata is not None): if optType == types.NoneType:
fields.update({key: (Optional[optType], Field( pass
default=metadata.default ,description=metadata.label))}) elif metadata is not None:
fields.update({key: (Optional[optType], Field(default=metadata.default, description=metadata.label))})
else: else:
fields.update({key: (Optional[optType], Field())}) fields.update({key: (Optional[optType], Field())})