Files
aigc-home/docs/hel-892/minimax-turbo-api-document-evidence/verify_sources.py
T
2026-11-02 03:15:56 +08:00

114 lines
4.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"Audit original API declarations and complete typed objects without implementation lookup."
import hashlib
import json
from collections import Counter
from build_definition import EXPECTED, OUT, PATHS, REPO, build, canonical
def typed(value):
if isinstance(value, dict):
return {key: typed(item) for key, item in value.items()}
if isinstance(value, list):
return [typed(item) for item in value]
return dict(json_type=type(value).__name__, value=value)
def main():
raw = (REPO / PATHS[0]).read_bytes()
assert hashlib.sha256(raw).hexdigest() == EXPECTED
graph, block = json.loads(raw), build()
types = Counter(f["json_type"] for f in block["fields"])
assert types == dict(str=35, int=20, bool=9, float=6, dict=2)
assert all(set(n) == {"inputs", "class_type", "_meta"} for n in graph.values())
assert len(graph) == len(block["node_bindings"]) == 55
assert block["sources"] == [] and all(
not n["implementation_verified"] and n["scope"] == "root" for n in block["node_bindings"]
)
assert set(graph["219"]["inputs"]) == {"prompt", "width", "height", "length", "clip", "vae"}
text = graph["6005"]["inputs"]["value"]
assert len(text) == 2341 and text.count("\n") == 4 and not text.endswith("\n")
assert (
hashlib.sha256(text.encode()).hexdigest()
== "5014a4f10c36ce7e0fe2d43916148c9ed146275414e548669dea2e7a616167a2"
)
objects = []
for key in ("PowerLoraLoaderHeaderWidget", "lora_1"):
obj = graph["6010"]["inputs"][key]
objects.append(
dict(
node_id="6010",
field=key,
pointer="/6010/inputs/" + key,
value=obj,
nested_types=typed(obj),
canonical_sha256=hashlib.sha256(canonical(obj)).hexdigest(),
)
)
assert graph["6010"]["inputs"]["lora_1"]["on"] is True
assert type(graph["6010"]["inputs"]["lora_1"]["strength"]) is int
assert graph["6010"]["inputs"]["➕ Add Lora"] == ""
expressions = [
dict(
node_id=nid,
field=key,
value=graph[nid]["inputs"][key],
sha256=hashlib.sha256(graph[nid]["inputs"][key].encode()).hexdigest(),
)
for nid, key in [("220", "expression"), ("5974", "expression"), ("6061:4985", "sigmas")]
]
(OUT / "original-audit.json").write_text(
json.dumps(
dict(
path=PATHS[0],
sha256=EXPECTED,
original_bytes=len(raw),
source_nodes=55,
saved_inputs=72,
scalar_inputs=70,
complete_objects=2,
json_types=types,
references=block["api_references"],
node_identity_gaps=block["node_bindings"],
exact_implementation_sources=0,
original_fetch_time="unknown:未保留可证精确取得时刻",
strings=[
dict(
node_id="6005",
field="value",
characters=len(text),
LF=4,
CR=text.count("\r"),
tail_LF=False,
sha256=hashlib.sha256(text.encode()).hexdigest(),
)
],
objects=objects,
expressions=expressions,
missing_inputs=[
dict(
node_id="219",
missing_keys=["first_frame", "last_frame", "audio_vae"],
state="原键缺失,不补null/素材",
)
],
media_histories=0,
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print(
(
"PASS original55 / typed72=scalar70+dict2 / re"
"ferences72 / implementation0 / complete text+"
"objects+expressions"
)
)
if __name__ == "__main__":
main()