154 lines
6.1 KiB
Python
154 lines
6.1 KiB
Python
"""H3 原生音视频使用独立实测证据,不能继承静音视频或后配口型认证。"""
|
|
|
|
import re
|
|
|
|
from app.domain import native_silence
|
|
|
|
from app.domain.video_generation import (
|
|
H3_NATIVE_AV_PROFILE,
|
|
H3_NATIVE_AV_TP2_PROFILE,
|
|
H3_NATIVE_AV_PROFILES,
|
|
)
|
|
|
|
CERTIFICATION_REASON = "H3原生音视频尚未启用或尚未完成独立实测认证。"
|
|
REVISION = "12253298adb81e36757eabebb81d2ba1c0cc70cc"
|
|
RUNTIME_REVISION = "f53d552036a0d1bd5570782a39cd40cfabf112bc"
|
|
TP2_RUNTIME_REVISION = "423ab90580b2847998591669b8326f47b6d14d8b"
|
|
ALIGNMENT_REASON = "原生对白逐词识别尚未完成独立实测认证。"
|
|
CANVASES = [[1344, 768], [768, 1344]]
|
|
CANVAS_REASON = "当前原生画布尚未通过实测验收,请使用实时能力中已认证的画布。"
|
|
|
|
|
|
def valid_canvases(value):
|
|
return (
|
|
isinstance(value, list)
|
|
and 1 <= len(value) <= len(CANVASES)
|
|
and all(
|
|
isinstance(c, list) and len(c) == 2 and all(type(v) is int for v in c) and c in CANVASES
|
|
for c in value
|
|
)
|
|
and value == [c for c in CANVASES if c in value]
|
|
)
|
|
|
|
|
|
def enabled(settings, profile):
|
|
if profile not in H3_NATIVE_AV_PROFILES:
|
|
return False
|
|
flag = (
|
|
"native_dialogue_tp2_enabled"
|
|
if profile == H3_NATIVE_AV_TP2_PROFILE
|
|
else "native_dialogue_enabled"
|
|
)
|
|
return (
|
|
bool(getattr(settings, "inference_base_url", "")) and getattr(settings, flag, False) is True
|
|
)
|
|
|
|
|
|
def select_evidence(snapshot, profile):
|
|
if not isinstance(snapshot, dict) or profile not in H3_NATIVE_AV_PROFILES:
|
|
return {}
|
|
generation = snapshot.get("video_generation")
|
|
if not isinstance(generation, dict):
|
|
return {}
|
|
key = "native_av_tp2" if profile == H3_NATIVE_AV_TP2_PROFILE else "native_av"
|
|
value = generation.get(key)
|
|
return value if isinstance(value, dict) else {}
|
|
|
|
|
|
def certified(evidence, profile=H3_NATIVE_AV_PROFILE):
|
|
if not isinstance(evidence, dict) or profile not in H3_NATIVE_AV_PROFILES:
|
|
return False
|
|
tp2 = profile == H3_NATIVE_AV_TP2_PROFILE
|
|
integers = {"fps": 24, "audio_sample_rate": 32000, "audio_channels": 2}
|
|
return (
|
|
evidence.get("available") is True
|
|
and evidence.get("decision") == "pass"
|
|
and evidence.get("audited") is True
|
|
and evidence.get("profile") == profile
|
|
and evidence.get("revision") == REVISION
|
|
and evidence.get("runtime_revision") == (TP2_RUNTIME_REVISION if tp2 else RUNTIME_REVISION)
|
|
and evidence.get("adapter_contract_version")
|
|
== ("h3-fl2va-native-av-tp2-v1" if tp2 else "h3-fl2va-native-av-v1")
|
|
and evidence.get("input_modes")
|
|
== (["first_frame"] if tp2 else ["first_frame", "first_last_frame"])
|
|
and evidence.get("output_policy") == "full_native"
|
|
and evidence.get("native_frame_counts") == list(range(124, 159 if tp2 else 346, 17))
|
|
and all(type(v) is int for v in evidence["native_frame_counts"])
|
|
and valid_canvases(evidence.get("canvases"))
|
|
and all(type(evidence.get(k)) is int and evidence[k] == v for k, v in integers.items())
|
|
and evidence.get("audio_output") is True
|
|
and evidence.get("upscale") is False
|
|
and bool(re.fullmatch(r"[0-9a-f]{64}", str(evidence.get("report_sha256", ""))))
|
|
)
|
|
|
|
|
|
def canvas_certified(evidence, profile, width, height):
|
|
return (
|
|
certified(evidence, profile)
|
|
and type(width) is int
|
|
and type(height) is int
|
|
and [width, height] in evidence["canvases"]
|
|
)
|
|
|
|
|
|
async def available(provider, profile=H3_NATIVE_AV_PROFILE, *, canvas=None, settings=None):
|
|
if not enabled(settings if settings is not None else provider.settings, profile):
|
|
return False
|
|
try:
|
|
snapshot = await provider.upstream_capabilities()
|
|
evidence = select_evidence(snapshot, profile)
|
|
if canvas is not None:
|
|
return (
|
|
isinstance(canvas, (list, tuple))
|
|
and len(canvas) == 2
|
|
and canvas_certified(evidence, profile, *canvas)
|
|
)
|
|
return certified(evidence, profile)
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
def alignment_evidence(snapshot):
|
|
dialogue = snapshot.get("dialogue") if isinstance(snapshot, dict) else None
|
|
speech = dialogue.get("speech_inspect") if isinstance(dialogue, dict) else None
|
|
result = speech.get("native_alignment") if isinstance(speech, dict) else None
|
|
return result if isinstance(result, dict) else {}
|
|
|
|
|
|
def alignment_certified(evidence):
|
|
return (
|
|
isinstance(evidence, dict)
|
|
and evidence.get("available") is True
|
|
and evidence.get("decision") == "pass"
|
|
and evidence.get("audited") is True
|
|
and evidence.get("profile") == "dialogue-audio-v1"
|
|
and evidence.get("revision") == "f0c48c298fd835726c27956a5d617bad7115627e"
|
|
and evidence.get("asr_revision") == "41f01f3fe87f28c78e2fbf8b568835947dd65ed9"
|
|
and evidence.get("content_verification_policy") == "whisper-sensevoice-consensus-v1"
|
|
and evidence.get("secondary_asr_revision") == "90c1c61912018b70ada0fcc024ea24aca62f2e63"
|
|
and evidence.get("secondary_runtime_revision") == "6991744856587fa44379e8b5dcc432debffeb1be"
|
|
and evidence.get("silence_verification_policy") == native_silence.POLICY
|
|
and evidence.get("silence_vad_revision") == native_silence.REVISION
|
|
and evidence.get("silence_vad_sha256") == native_silence.MODEL_SHA256
|
|
and evidence.get("policy") == "native_av_v1"
|
|
and evidence.get("timestamp_source") == "whisper-word-timestamps"
|
|
and type(evidence.get("sample_rate")) is int
|
|
and evidence["sample_rate"] == 48000
|
|
and bool(re.fullmatch(r"[0-9a-f]{64}", str(evidence.get("report_sha256", ""))))
|
|
)
|
|
|
|
|
|
def alignment_enabled(settings, snapshot):
|
|
return any(enabled(settings, p) for p in H3_NATIVE_AV_PROFILES) and alignment_certified(
|
|
alignment_evidence(snapshot)
|
|
)
|
|
|
|
|
|
async def alignment_available(provider):
|
|
if not any(enabled(provider.settings, p) for p in H3_NATIVE_AV_PROFILES):
|
|
return False
|
|
try:
|
|
return alignment_enabled(provider.settings, await provider.upstream_capabilities())
|
|
except Exception:
|
|
return False
|