added support for additional more user-friendly interfaces, improved some part of the application loading process to make it a bit simpler

This commit is contained in:
faraphel 2025-01-12 12:52:19 +01:00
parent 1a49aa3779
commit f647c960dd
20 changed files with 353 additions and 107 deletions

View file

@ -2,10 +2,14 @@
"type": "python",
"tags": ["dummy"],
"file": "model.py",
"interface": "chat",
"output_type": "video/mp4",
"summary": "Echo model",
"description": "The most basic example model, simply echo the input",
"inputs": {
"file": {"type": "file"}
}
"messages": {"type": "list[dict]", "default": "[{\"role\": \"user\", \"content\": \"who are you ?\"}]"}
},
"output_type": "text/markdown"
}

View file

@ -7,5 +7,5 @@ def load(model) -> None:
def unload(model) -> None:
pass
async def infer(model, file) -> typing.AsyncIterator[bytes]:
yield await file.read()
async def infer(model, messages: list[dict]) -> typing.AsyncIterator[bytes]:
yield messages[-1]["content"].encode("utf-8")

View file

@ -16,7 +16,7 @@ def unload(model) -> None:
model.model = None
model.tokenizer = None
def infer(model, prompt: str) -> typing.Iterator[bytes]:
async def infer(model, prompt: str) -> typing.AsyncIterator[bytes]:
inputs = model.tokenizer(prompt, return_tensors="pt")
with torch.no_grad():

View file

@ -16,7 +16,7 @@ def unload(model) -> None:
model.model = None
model.tokenizer = None
def infer(model, prompt: str) -> typing.Iterator[bytes]:
async def infer(model, prompt: str) -> typing.AsyncIterator[bytes]:
inputs = model.tokenizer(prompt, return_tensors="pt")
with torch.no_grad():