feat: 完成 echo 示例节点
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from wov_sdk.models import InvokeRequest, InvokeResponse, NodeManifest
|
||||
from wov_sdk.server import run_node
|
||||
|
||||
|
||||
def _resolve_input_text(request: InvokeRequest, node_root: Path) -> str:
|
||||
text = request.inputs.get("text")
|
||||
if text is not None:
|
||||
return str(text)
|
||||
|
||||
file_uri = request.inputs.get("file_uri")
|
||||
if file_uri:
|
||||
path = Path(file_uri)
|
||||
if not path.is_absolute():
|
||||
path = node_root / path
|
||||
return path.read_text(encoding="utf-8")
|
||||
|
||||
return "echo"
|
||||
|
||||
|
||||
def invoke(request: InvokeRequest) -> InvokeResponse:
|
||||
node_root = Path(__file__).resolve().parent.parent
|
||||
output_dir = Path(request.output_dir)
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
text = _resolve_input_text(request, node_root)
|
||||
output_path = output_dir / "echo.txt"
|
||||
output_path.write_text(text, encoding="utf-8")
|
||||
|
||||
return InvokeResponse(
|
||||
status="completed",
|
||||
outputs={
|
||||
"text": text,
|
||||
"file_uri": str(output_path),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
manifest_path = Path(__file__).resolve().parent.parent / "node.manifest.json"
|
||||
with open(manifest_path, "r", encoding="utf-8") as f:
|
||||
manifest = NodeManifest.from_dict(json.load(f))
|
||||
run_node(manifest, invoke)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user