Skip to content

Commit

Permalink
Pipeline草稿,开始1.0路线图
Browse files Browse the repository at this point in the history
  • Loading branch information
sena-nana committed Oct 10, 2023
1 parent 7dc1b42 commit 7a387d5
Show file tree
Hide file tree
Showing 39 changed files with 150 additions and 980 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,5 @@ node_modules/
docs/.vuepress/.cache/
docs/.vuepress/.temp/
docs/.vuepress/dist/
.VSCodeCounter
.VSCodeCounter
build
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
10 changes: 0 additions & 10 deletions nonebot_plugin_novelai/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
from ..config import config

if config.novelai_mode == "novelai":
from .novelai import Draw
elif config.novelai_mode == "naifu":
from .naifu import Draw
elif config.novelai_mode == "sd":
from .sd import Draw
else:
raise RuntimeError(f"错误的mode设置,支持的字符串为'novelai','naifu','sd'")
5 changes: 5 additions & 0 deletions nonebot_plugin_novelai/backend/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ..core.pipeline import ParallelPipeline, SelectivePipeline


class BackendBase(ParallelPipeline, SelectivePipeline):
...
File renamed without changes.
78 changes: 78 additions & 0 deletions nonebot_plugin_novelai/core/pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import heapq
from typing import Callable, Type


class Processor:
"""加工器"""

def run(self):
...


class PipelineMeta(type):
def __new__(cls, name, bases, attrs):
if "run" not in attrs:
# 检查是否存在父类,并按继承顺序调用各个父类的run方法
def run(self):
for base in bases:
if hasattr(base, "run"):
getattr(base, "run")(self)

attrs["run"] = run
return super().__new__(cls, name, bases, attrs)


class Pipeline(Processor, metaclass=PipelineMeta):
"""
流水线基类,不包含处理加工器的流程,除非要自己实现,否则应继承子类
流水线本身也是一个加工器,只是流水线的工作方式不同
"""

Pipelines = []

def _register(self, Pipeline, priority, block):
heapq.heappush(self.Pipelines, (priority, block, Pipeline))

async def preprocess(self):
"""预处理"""
...

async def on_preprocess(self, func):
...

async def postprocess(self):
...

async def on_postprocess(self, func):
...

def handle(
self, priority: int, block: bool
) -> Callable[[Callable | Type["Processor"]], Type["Processor"]]:
"""通过该函数将函数注册为加工器"""

def wrapper(subPipeline: Callable | Type["Processor"]) -> Type["Processor"]:
if isinstance(subPipeline, Callable):
sub = type(subPipeline.__name__, (Processor,), {}) # TODO
return sub
else:
self._register(subPipeline, priority, block)
return subPipeline

return wrapper


class LinearPipeline(Pipeline):
...


class ParallelPipeline(Pipeline):
...


class SelectivePipeline(Pipeline):
...


class Context:
"""事件,只保存数据在各个Pipeline之间传递"""
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions nonebot_plugin_novelai/outofdate/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ..config import config

if config.novelai_mode == "novelai":
from .novelai import Draw
elif config.novelai_mode == "naifu":
from .naifu import Draw
elif config.novelai_mode == "sd":
from .sd import Draw
else:
raise RuntimeError(f"错误的mode设置,支持的字符串为'novelai','naifu','sd'")
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

class DrawBase:
MAX_RESOLUTION: int = 16
sampler: str
MAX_STEPS: int = 50

def __init__(
Expand Down Expand Up @@ -240,7 +239,6 @@ def keys(self):
"scale",
"strength",
"noise",
"sampler",
"model",
"steps",
"width",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7a387d5

Please sign in to comment.