mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
34e3aa1f88
author Kyle Schouviller <kyle0654@hotmail.com> 1669872800 -0800 committer Kyle Schouviller <kyle0654@hotmail.com> 1676240900 -0800 Adding base node architecture Fix type annotation errors Runs and generates, but breaks in saving session Fix default model value setting. Fix deprecation warning. Fixed node api Adding markdown docs Simplifying Generate construction in apps [nodes] A few minor changes (#2510) * Pin api-related requirements * Remove confusing extra CORS origins list * Adds response models for HTTP 200 [nodes] Adding graph_execution_state to soon replace session. Adding tests with pytest. Minor typing fixes [nodes] Fix some small output query hookups [node] Fixing some additional typing issues [nodes] Move and expand graph code. Add base item storage and sqlite implementation. Update startup to match new code [nodes] Add callbacks to item storage [nodes] Adding an InvocationContext object to use for invocations to provide easier extensibility [nodes] New execution model that handles iteration [nodes] Fixing the CLI [nodes] Adding a note to the CLI [nodes] Split processing thread into separate service [node] Add error message on node processing failure Removing old files and duplicated packages Adding python-multipart
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
|
|
from typing import Callable, TypeVar, Generic
|
|
from pydantic import BaseModel, Field
|
|
from pydantic.generics import GenericModel
|
|
from abc import ABC, abstractmethod
|
|
|
|
T = TypeVar('T', bound=BaseModel)
|
|
|
|
class PaginatedResults(GenericModel, Generic[T]):
|
|
"""Paginated results"""
|
|
items: list[T] = Field(description = "Items")
|
|
page: int = Field(description = "Current Page")
|
|
pages: int = Field(description = "Total number of pages")
|
|
per_page: int = Field(description = "Number of items per page")
|
|
total: int = Field(description = "Total number of items in result")
|
|
|
|
|
|
class ItemStorageABC(ABC, Generic[T]):
|
|
_on_changed_callbacks: list[Callable[[T], None]]
|
|
_on_deleted_callbacks: list[Callable[[str], None]]
|
|
|
|
def __init__(self) -> None:
|
|
self._on_changed_callbacks = list()
|
|
self._on_deleted_callbacks = list()
|
|
|
|
"""Base item storage class"""
|
|
@abstractmethod
|
|
def get(self, item_id: str) -> T:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def set(self, item: T) -> None:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def list(self, page: int = 0, per_page: int = 10) -> PaginatedResults[T]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def search(self, query: str, page: int = 0, per_page: int = 10) -> PaginatedResults[T]:
|
|
pass
|
|
|
|
def on_changed(self, on_changed: Callable[[T], None]) -> None:
|
|
"""Register a callback for when an item is changed"""
|
|
self._on_changed_callbacks.append(on_changed)
|
|
|
|
def on_deleted(self, on_deleted: Callable[[str], None]) -> None:
|
|
"""Register a callback for when an item is deleted"""
|
|
self._on_deleted_callbacks.append(on_deleted)
|
|
|
|
def _on_changed(self, item: T) -> None:
|
|
for callback in self._on_changed_callbacks:
|
|
callback(item)
|
|
|
|
def _on_deleted(self, item_id: str) -> None:
|
|
for callback in self._on_deleted_callbacks:
|
|
callback(item_id)
|