app/core/schema_loader.py hinzugefügt
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
This commit is contained in:
parent
d0471050fc
commit
039e5b80df
22
app/core/schema_loader.py
Normal file
22
app/core/schema_loader.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from functools import lru_cache
|
||||||
|
from jsonschema import Draft202012Validator, RefResolver
|
||||||
|
|
||||||
|
SCHEMAS_DIR = os.getenv("SCHEMAS_DIR", os.path.join(os.path.dirname(os.path.dirname(__file__)), "..", "schemas"))
|
||||||
|
|
||||||
|
@lru_cache(maxsize=16)
|
||||||
|
def load_schema(name: str) -> dict:
|
||||||
|
# name: "note.schema.json" | "chunk.schema.json" | "edge.schema.json"
|
||||||
|
path = os.path.join(SCHEMAS_DIR, name)
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
raise FileNotFoundError(f"Schema not found: {path}")
|
||||||
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
@lru_cache(maxsize=16)
|
||||||
|
def get_validator(name: str) -> Draft202012Validator:
|
||||||
|
schema = load_schema(name)
|
||||||
|
resolver = RefResolver.from_schema(schema)
|
||||||
|
return Draft202012Validator(schema, resolver=resolver)
|
||||||
Loading…
Reference in New Issue
Block a user