mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
402cf9b0ee
Refactor services folder/module structure. **Motivation** While working on our services I've repeatedly encountered circular imports and a general lack of clarity regarding where to put things. The structure introduced goes a long way towards resolving those issues, setting us up for a clean structure going forward. **Services** Services are now in their own folder with a few files: - `services/{service_name}/__init__.py`: init as needed, mostly empty now - `services/{service_name}/{service_name}_base.py`: the base class for the service - `services/{service_name}/{service_name}_{impl_type}.py`: the default concrete implementation of the service - typically one of `sqlite`, `default`, or `memory` - `services/{service_name}/{service_name}_common.py`: any common items - models, exceptions, utilities, etc Though it's a bit verbose to have the service name both as the folder name and the prefix for files, I found it is _extremely_ confusing to have all of the base classes just be named `base.py`. So, at the cost of some verbosity when importing things, I've included the service name in the filename. There are some minor logic changes. For example, in `InvocationProcessor`, instead of assigning the model manager service to a variable to be used later in the file, the service is used directly via the `Invoker`. **Shared** Things that are used across disparate services are in `services/shared/`: - `default_graphs.py`: previously in `services/` - `graphs.py`: previously in `services/` - `paginatation`: generic pagination models used in a few services - `sqlite`: the `SqliteDatabase` class, other sqlite-specific things
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from typing import Optional
|
|
|
|
from pydantic import Field
|
|
|
|
from invokeai.app.services.image_records.image_records_common import ImageRecord
|
|
from invokeai.app.util.model_exclude_null import BaseModelExcludeNull
|
|
|
|
|
|
class ImageUrlsDTO(BaseModelExcludeNull):
|
|
"""The URLs for an image and its thumbnail."""
|
|
|
|
image_name: str = Field(description="The unique name of the image.")
|
|
"""The unique name of the image."""
|
|
image_url: str = Field(description="The URL of the image.")
|
|
"""The URL of the image."""
|
|
thumbnail_url: str = Field(description="The URL of the image's thumbnail.")
|
|
"""The URL of the image's thumbnail."""
|
|
|
|
|
|
class ImageDTO(ImageRecord, ImageUrlsDTO):
|
|
"""Deserialized image record, enriched for the frontend."""
|
|
|
|
board_id: Optional[str] = Field(description="The id of the board the image belongs to, if one exists.")
|
|
"""The id of the board the image belongs to, if one exists."""
|
|
|
|
pass
|
|
|
|
|
|
def image_record_to_dto(
|
|
image_record: ImageRecord,
|
|
image_url: str,
|
|
thumbnail_url: str,
|
|
board_id: Optional[str],
|
|
) -> ImageDTO:
|
|
"""Converts an image record to an image DTO."""
|
|
return ImageDTO(
|
|
**image_record.dict(),
|
|
image_url=image_url,
|
|
thumbnail_url=thumbnail_url,
|
|
board_id=board_id,
|
|
)
|