33 lines
2.0 KiB
Python
33 lines
2.0 KiB
Python
"""Pinned, native CPU-only Redux runtime; no implicit download or inference."""
|
|
import hashlib,json,os,time
|
|
from pathlib import Path
|
|
REPO='mudler/parakeet-cpp-gguf'
|
|
REVISION='741158ae71e64ef5c89385862c18f777d07a97a1'
|
|
MODEL='redux-packed.gguf'
|
|
SHA256='574614b9a4d9f72ab202877a7ad6a1f4bf819dd1d27b9d42dfe8cd429fcebdd5'
|
|
VERSION='v0.6.1'
|
|
def supported(model):return bool(model and model.get('repo')==REPO and model.get('revision')==REVISION and model.get('file')==MODEL)
|
|
class ParakeetRuntime:
|
|
def __init__(self,root):self.root=Path(root)
|
|
def paths(self):
|
|
root=self.root/VERSION
|
|
binary=root/'runtime'/('parakeet-'+VERSION+'-bin-linux-cpu-x64')/'parakeet-server'
|
|
return binary,root/MODEL
|
|
def status(self):
|
|
binary,model=self.paths();manifest=self.root/VERSION/'manifest.json'
|
|
try:
|
|
data=json.loads(manifest.read_text());verified=data['version']==VERSION and data['model_revision']==REVISION and any(r['path']==MODEL and r['sha256']==SHA256 for r in data['files'])
|
|
except (OSError,ValueError,KeyError,TypeError):verified=False
|
|
return dict(installed=bool(verified and binary.is_file() and os.access(binary,os.X_OK) and model.is_file()),version=VERSION,repo=REPO,revision=REVISION,device='cpu')
|
|
def binary(self):
|
|
if not self.status()['installed']:raise ValueError('Parakeet-CPU-Laufzeit fehlt. Gepinntes Vorbereitungsrezept ausführen.')
|
|
return self.paths()[0]
|
|
def register(self,catalog):
|
|
if not self.status()['installed']:raise ValueError('Parakeet-Dateien fehlen.')
|
|
_,model=self.paths();ident=hashlib.sha256((REPO+REVISION+MODEL).encode()).hexdigest();target=catalog.root/ident
|
|
target.mkdir(parents=True,exist_ok=True,mode=0o700)
|
|
dest=target/'model.gguf'
|
|
if not dest.exists():dest.symlink_to(model.resolve())
|
|
entry=dict(repo=REPO,revision=REVISION,file=MODEL,kind='stt',size=model.stat().st_size,sha256=SHA256,upstream_hash_verified=True,downloaded_at=time.time(),state='downloaded',runtime_ready=True)
|
|
temp=target/'entry.tmp';temp.write_text(json.dumps(entry));temp.replace(target/'entry.json');return ident
|