vkae / app.py
openfree's picture
Add Darwin-36B-Opus VKAE row (11.2x, 25->280.8) + links
2184184 verified
Raw
History Blame Contribute Delete
28.6 kB
from __future__ import annotations
import json
import os
import re
import threading
import time
import urllib.request
import uuid
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import FileResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel, Field
APP_ROOT = Path(__file__).resolve().parent
STATIC_ROOT = APP_ROOT / "static"
DATA_ROOT = APP_ROOT / "data"
LEADS_PATH = Path(os.environ.get("VKAE_LEADS_PATH", DATA_ROOT / "leads.jsonl"))
BENCHMARK_RESULTS_PATH = DATA_ROOT / "benchmark_results.json"
BENCHMARK_RESULTS_URL = os.environ.get(
"VKAE_BENCHMARK_RESULTS_URL",
"https://huggingface.co/spaces/VIDraft/vkae/resolve/main/data/benchmark_results.json",
).strip()
LEADS_DATASET = os.environ.get("VKAE_LEADS_DATASET", "").strip()
SYNC_TO_DATASET = os.environ.get("VKAE_SYNC_TO_DATASET", "0") == "1"
HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HF_TOKEN_VIDRAFT")
EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
PHONE_RE = re.compile(r"^[0-9+().\-\s]{0,40}$")
LOCK = threading.Lock()
SERVICE_TYPES = [
{
"id": "benchmark_report",
"title": "Private Benchmark Report",
"summary": "Claim-scoped fit, TPS, latency, quality risk, and cost view.",
"default": True,
},
{
"id": "managed_endpoint",
"title": "Managed VKAE Endpoint",
"summary": "Private OpenAI-compatible endpoint operated by VIDRAFT.",
"default": True,
},
{
"id": "docker_eval",
"title": "Private Docker Evaluation",
"summary": "Time-limited container evaluation for customer GPUs.",
"default": False,
},
{
"id": "enterprise_onprem",
"title": "Enterprise On-Prem Deployment",
"summary": "Licensed deployment in the customer environment with support.",
"default": False,
},
{
"id": "custom_engine",
"title": "Custom Engine Build",
"summary": "VKAE-Qwen, VKAE-Llama, or a fine-tuned model-specific engine.",
"default": False,
},
{
"id": "partnership",
"title": "Partnership / Research / Investment",
"summary": "Strategic collaboration, research, or investment discussion.",
"default": False,
},
]
PRODUCT_STATUS = {
"name": "VKAE-Gemma-E4B",
"expanded_name": "VIDRAFT Kernel Acceleration Engine for Gemma E4B",
"stage": "Private Preview / Controlled Deployment",
"positioning": (
"The first productized VKAE engine is the Gemma E4B lane. Other Gemma "
"families are handled as model-specific engine ports, not as completed "
"product claims."
),
"primary_claim": (
"E4B challenge profile: 95.36 TPS reference path to 506.94 TPS VIDRAFT "
"acceleration recipe, 5.315x relative lift, PPL 2.3929 dashboard-valid. "
"The before number is the challenge reference serving path for that "
"same E4B profile; it is not a generic customer serving baseline."
),
"production_boundary": (
"Only the E4B optimized profile is launch-ready for private preview. "
"Additional model lanes (Qwen dense, customer-tuned) are qualified with "
"separate same-harness VKAE benchmark reports."
),
"control_plane": "L40S-managed qualification lane, with H100/H200/B200 fallback for larger models.",
}
OPENAI_COMPAT_MODELS = [
{
"id": "vkae-gemma-e4b-private-preview",
"object": "model",
"created": 1782698400,
"owned_by": "VIDRAFT",
"root": "google/gemma-4-E4B-it",
"parent": None,
"permission": [],
"metadata": {
"engine": "VKAE-Gemma-E4B",
"stage": "private_preview",
"claim_scope": "dashboard_valid_challenge_showcase",
"serving_surface": "managed_endpoint_or_private_docker_eval",
"quality_guard": "PPL 2.3929 dashboard-valid challenge profile",
},
}
]
CUSTOMER_BENCHMARK_SCHEMA = {
"schema_id": "vkae.customer_benchmark_report.v1",
"required_fields": [
"model_id",
"hardware",
"precision",
"prompt_profile",
"request_count",
"context_length",
"baseline_stack",
"vkae_stack",
"baseline_tps",
"vkae_tps",
"latency_p50_ms",
"latency_p95_ms",
"gpu_memory_peak_gb",
"quality_guard",
"artifact_uri",
],
"claim_rules": [
"same model",
"same hardware",
"same precision",
"same prompt/load harness",
"same request count",
"promoted/default VKAE recipe",
],
"non_claim_rows": [
"failed candidate gates",
"short-harness positives",
"generic baseline-vs-reference preview checks",
"raw compatibility/package-validation measurements",
],
}
DELIVERY_PACKAGES = [
{
"id": "managed_endpoint",
"title": "Managed VKAE Endpoint",
"stage": "first commercial offer",
"summary": "VIDRAFT operates a private OpenAI-compatible endpoint for Gemma E4B workloads.",
"best_for": "Teams that want speed validation without handling kernels, containers, or GPU orchestration.",
"customer_gets": [
"private endpoint",
"claim-scoped benchmark report",
"usage and latency telemetry",
"quality and PPL guard report",
],
"ip_exposure": "No kernel or binary delivery.",
},
{
"id": "docker_eval",
"title": "Private Docker Evaluation",
"stage": "qualified preview",
"summary": "Time-limited container for customer-controlled L40S/H100/H200 tests.",
"best_for": "GPU operators that need reproducible on-hardware numbers before procurement.",
"customer_gets": [
"signed container image",
"fixed benchmark harness",
"license-bound runtime key",
"structured artifact bundle",
],
"ip_exposure": "Binary/runtime only; no source kernels.",
},
{
"id": "enterprise_onprem",
"title": "Enterprise On-Prem License",
"stage": "design partner",
"summary": "On-prem deployment with SLA, private integration, and controlled upgrade channel.",
"best_for": "Regulated or high-volume customers that need the engine inside their own environment.",
"customer_gets": [
"deployment package",
"integration support",
"benchmark acceptance criteria",
"versioned acceleration recipe updates",
],
"ip_exposure": "Licensed binary plus operational recipes.",
},
{
"id": "custom_engine",
"title": "Custom Model Port",
"stage": "paid engineering track",
"summary": "Model-specific VKAE port for Qwen or customer-tuned models.",
"best_for": "Customers whose target model is not yet a finished VKAE engine.",
"customer_gets": [
"model profiling",
"kernel and serving recipe search",
"acceptance benchmark",
"private launch plan",
],
"ip_exposure": "Deliverable depends on commercial scope.",
},
]
ENGINE_ROADMAP = [
{
"engine": "VKAE-Gemma-E4B",
"stage": "private preview",
"goal": "Package the verified challenge-derived profile into a controlled serving engine.",
"next_gate": "same-harness L40S/H100 endpoint benchmark plus customer demo workload.",
},
{
"engine": "VKAE-Qwen",
"stage": "measured (Qwen3-8B 1.85x, B200 optimized)",
"goal": "Apply the VKAE model-specialized engine pattern to Qwen after Gemma E4B packaging.",
"next_gate": "extend to Qwen3.5 / Qwen3.6 and MoE targets; publish same-harness rows.",
},
]
BENCHMARK_SERIES = [
{
"model": "Gemma 4 E4B / Challenge Profile",
"model_id": "google/gemma-4-E4B-it",
"size": "E4B / small multimodal",
"hardware": "Challenge A10G profile",
"measurement_status": "measured",
"claim_ready": True,
"claim_scope": "dashboard_valid_showcase",
"package_status": "engine profile",
"baseline_label": "Challenge reference path",
"vkae_label": "VIDRAFT optimized serving",
"baseline_tps": 95.36,
"vkae_tps": 506.94,
"ppl": 2.3929,
"quality": "Dashboard-valid VIDRAFT row on the same challenge profile; customer-style generic serving comparisons remain separate.",
"tag": "verified-profile",
},
{
"model": "Qwen3-8B",
"model_id": "Qwen/Qwen3-8B",
"size": "8B dense",
"hardware": "B200 single-GPU VKAE lane",
"measurement_status": "measured (B200, baseline vs VIDRAFT optimized serving)",
"claim_ready": True,
"claim_scope": "vidraft_b200_graph_measured",
"package_status": "measured",
"baseline_label": "Baseline serving (reference)",
"vkae_label": "VIDRAFT optimized serving",
"baseline_tps": 142.1,
"vkae_tps": 262.6,
"ppl": None,
"quality": "B200 single-GPU, single-stream decode. 1.85x (142.1 to 262.6 tok/s), TTFT 0.019 to 0.009s; concurrency-32 aggregate 4352 to 7801 tok/s.",
"tag": "measured-b200-graph",
},
{
"model": "Qwen3.5-9B",
"model_id": "Qwen/Qwen3.5-9B",
"size": "9B dense (Qwen3.5)",
"hardware": "B200 single-GPU VKAE lane",
"measurement_status": "measured (B200, baseline vs VIDRAFT optimized serving)",
"claim_ready": True,
"claim_scope": "vidraft_b200_graph_measured",
"package_status": "measured",
"baseline_label": "Baseline serving (reference)",
"vkae_label": "VIDRAFT optimized serving",
"baseline_tps": 69.8,
"vkae_tps": 237.7,
"ppl": None,
"quality": "B200 single-GPU, single-stream decode. 3.41x (69.8 to 237.7 tok/s), TTFT 0.044 to 0.018s; concurrency-32 aggregate 1920 to 5180 tok/s. Newer Qwen3.5 arch has higher eager overhead, so optimized serving gain is larger.",
"tag": "measured-b200-graph",
},
{
"model": "Qwen3.6-27B",
"model_id": "Qwen/Qwen3.6-27B",
"size": "27B dense (Qwen3.6)",
"hardware": "B200 single-GPU VKAE lane",
"measurement_status": "measured (B200, baseline vs VIDRAFT optimized serving)",
"claim_ready": True,
"claim_scope": "vidraft_b200_graph_measured",
"package_status": "measured",
"baseline_label": "Baseline serving (reference)",
"vkae_label": "VIDRAFT optimized serving",
"baseline_tps": 36.9,
"vkae_tps": 91.0,
"ppl": None,
"quality": "B200 single-GPU, single-stream decode. 2.47x (36.9 to 91.0 tok/s), TTFT 0.081 to 0.029s; concurrency-32 aggregate 1070 to 2156 tok/s. Latest-generation Qwen3.6 dense.",
"tag": "measured-b200-graph",
},
{
"model": "Qwen3.5-35B-A3B (MoE)",
"model_id": "Qwen/Qwen3.5-35B-A3B",
"size": "35B total / 3B active (MoE)",
"hardware": "B200 single-GPU VKAE lane",
"measurement_status": "measured (B200, baseline vs VIDRAFT optimized serving)",
"claim_ready": True,
"claim_scope": "vidraft_b200_graph_measured",
"package_status": "measured",
"baseline_label": "Baseline serving (reference)",
"vkae_label": "VIDRAFT optimized serving",
"baseline_tps": 25.7,
"vkae_tps": 601.0,
"ppl": None,
"quality": "MoE 35B total / 3B active. B200 single-GPU single-stream 601 tok/s (realistic varied-content ~455 tok/s); baseline reference 25.7 tok/s. Peak aggregate throughput ~10,516 tok/s at high concurrency. 23.4x vs baseline reference, the largest per-model VKAE gain measured, accuracy preserved. Method internals withheld (proprietary).",
"docker_url": "https://hub.docker.com/r/vidraft/qwen35-vkae",
"hf_url": "https://huggingface.co/FINAL-Bench/Qwen3.5-35B-A3B-VKAE",
"tag": "measured-b200-vkae-moe",
},
{
"model": "JGOS-398B (Qwen3.5-MoE)",
"model_id": "FINAL-Bench/JGOS-398B-VID",
"size": "398B total MoE (flagship)",
"hardware": "B200 x6 (TP2 x PP3) VKAE lane",
"measurement_status": "measured (B200 x6, baseline eager vs VIDRAFT optimized serving)",
"claim_ready": True,
"claim_scope": "verified_large_moe_serving",
"package_status": "measured",
"baseline_label": "Baseline serving (eager)",
"vkae_label": "VIDRAFT optimized serving",
"baseline_tps": 88.0,
"vkae_tps": 382.0,
"ppl": None,
"quality": "Flagship 398B large-MoE. B200 x6 (TP2 x PP3), FP8, same-harness before/after. 4.33x (88.0 to 382.0 tok/s). Serving-optimization track distinct from the per-family Gemma recipe; method internals withheld (proprietary).",
"tag": "measured-b200-moe",
},
{
"model": "Darwin-36B-Opus (MoE)",
"model_id": "FINAL-Bench/Darwin-36B-Opus",
"size": "36B MoE (~3B active)",
"hardware": "B200 single-GPU VKAE lane",
"measurement_status": "measured (B200, baseline eager vs VIDRAFT optimized serving)",
"claim_ready": True,
"claim_scope": "vidraft_b200_graph_measured",
"package_status": "measured",
"baseline_label": "Baseline serving (eager)",
"vkae_label": "VIDRAFT optimized serving",
"baseline_tps": 25.0,
"vkae_tps": 280.8,
"ppl": None,
"quality": "VIDRAFT house flagship model (36B MoE). B200 single-GPU, single-stream, bf16. 11.2x (25.0 to 280.8 tok/s), accuracy preserved. Method internals withheld (proprietary).",
"docker_url": "https://hub.docker.com/r/vidraft/darwin36-vkae",
"hf_url": "https://huggingface.co/FINAL-Bench/Darwin-36B-Opus-VKAE",
"tag": "measured-b200-vkae-moe-house",
},
]
OFFICIAL_MODEL_CATALOG = [
{
"family": "Gemma 4 E4B",
"serving_priority": "Primary small-model acceleration lane and challenge-derived showcase profile.",
"repos": [
"google/gemma-4-E4B",
"google/gemma-4-E4B-it",
"google/gemma-4-E4B-it-assistant",
],
},
]
ADJACENT_GEMMA_MODELS = [
{
"family": "DiffusionGemma 26B-A4B",
"note": "Adjacent Google release, not under the google/gemma-4-* repo prefix.",
"repos": ["google/diffusiongemma-26B-A4B-it"],
}
]
GPU_SIZING_GUIDE = [
{
"family": "Gemma 4 E4B",
"speed_index": 68,
"min_gpu": "L4 / A10G class, 24GB",
"recommended_gpu": "L40S 48GB",
"precision_path": "BF16 challenge profile plus engine recipe",
"fit_note": "Primary VKAE-Gemma public showcase lane; challenge profile already has a verified VIDRAFT row.",
"measurement_status": "measured-profile",
"measured_tps": 506.94,
},
]
BENCHMARK_PLAN = {
"hardware_control": "L40S first, with per-model baseline and VKAE runs controlled from the local L40S lane.",
"minimum_report_fields": [
"model_id",
"precision",
"context_length",
"batch_or_concurrency",
"baseline_stack",
"baseline_tps",
"vkae_tps",
"latency_p50_ms",
"latency_p95_ms",
"gpu_memory_peak_gb",
"quality_guard",
],
"claim_boundary": "speed_index is a planning visualization, not measured TPS. Replace it with L40S measured TPS per model before using it as a public benchmark claim.",
}
class LeadSubmission(BaseModel):
full_name: str
email: str
contact: str | None = None
company: str | None = None
role: str | None = None
model_family: str | None = None
model_name: str | None = None
current_stack: str | None = None
gpu_target: str | None = None
monthly_tokens: str | None = None
service_types: list[str]
notes: str | None = None
consent: bool
class ChatCompletionRequest(BaseModel):
model: str
messages: list[dict[str, Any]] = Field(default_factory=list)
stream: bool = False
max_tokens: int | None = None
temperature: float | None = None
def _clean_text(value: str | None, limit: int = 500) -> str:
if not value:
return ""
return " ".join(value.strip().split())[:limit]
def _validate_lead(lead: LeadSubmission) -> dict[str, Any]:
full_name = _clean_text(lead.full_name, 120)
email = _clean_text(lead.email, 160).lower()
contact = _clean_text(lead.contact, 80)
service_ids = {item["id"] for item in SERVICE_TYPES}
selected = [item for item in lead.service_types if item in service_ids]
if len(full_name) < 2:
raise HTTPException(status_code=400, detail="Full name is required.")
if not EMAIL_RE.match(email):
raise HTTPException(status_code=400, detail="A valid email is required.")
if contact and not PHONE_RE.match(contact):
raise HTTPException(status_code=400, detail="Contact contains unsupported characters.")
if not selected:
raise HTTPException(status_code=400, detail="Select at least one service type.")
if not lead.consent:
raise HTTPException(status_code=400, detail="Consent is required.")
return {
"lead_id": f"vkae-{uuid.uuid4().hex[:12]}",
"created_at": datetime.now(timezone.utc).isoformat(),
"full_name": full_name,
"email": email,
"contact": contact,
"company": _clean_text(lead.company, 160),
"role": _clean_text(lead.role, 120),
"model_family": _clean_text(lead.model_family, 120),
"model_name": _clean_text(lead.model_name, 160),
"current_stack": _clean_text(lead.current_stack, 220),
"gpu_target": _clean_text(lead.gpu_target, 120),
"monthly_tokens": _clean_text(lead.monthly_tokens, 120),
"service_types": selected,
"notes": _clean_text(lead.notes, 1200),
"source": "vkae-gemma-space",
}
def _append_local(record: dict[str, Any]) -> None:
LEADS_PATH.parent.mkdir(parents=True, exist_ok=True)
with LOCK:
with LEADS_PATH.open("a", encoding="utf-8") as handle:
handle.write(json.dumps(record, ensure_ascii=False, sort_keys=True) + "\n")
def _sync_private_dataset() -> dict[str, Any]:
if not SYNC_TO_DATASET:
return {"enabled": False, "status": "skipped"}
if not HF_TOKEN or not LEADS_DATASET:
return {"enabled": True, "status": "missing_env"}
try:
from huggingface_hub import HfApi
api = HfApi(token=HF_TOKEN)
api.create_repo(
repo_id=LEADS_DATASET,
repo_type="dataset",
private=True,
exist_ok=True,
)
api.upload_file(
repo_id=LEADS_DATASET,
repo_type="dataset",
path_or_fileobj=str(LEADS_PATH),
path_in_repo="leads/leads.jsonl",
commit_message="Update VKAE-Gemma private leads",
)
return {"enabled": True, "status": "synced"}
except Exception as exc: # Do not expose token or full internals.
return {"enabled": True, "status": "error", "error": exc.__class__.__name__}
def _load_benchmark_results() -> dict[str, Any]:
if BENCHMARK_RESULTS_PATH.exists():
try:
with BENCHMARK_RESULTS_PATH.open("r", encoding="utf-8") as handle:
data = json.load(handle)
rows = data.get("rows", [])
if not isinstance(rows, list):
data["rows"] = []
return data
except Exception as exc:
return {
"status": "error",
"hardware": "L40S",
"rows": [],
"error": exc.__class__.__name__,
"claim_boundary": "Benchmark artifact could not be loaded.",
}
if BENCHMARK_RESULTS_URL:
try:
separator = "&" if "?" in BENCHMARK_RESULTS_URL else "?"
url = f"{BENCHMARK_RESULTS_URL}{separator}refresh={int(time.time() // 30)}"
request = urllib.request.Request(
url,
headers={
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"User-Agent": "vkae-space-benchmark-loader",
},
)
with urllib.request.urlopen(request, timeout=5) as response:
data = json.loads(response.read().decode("utf-8"))
rows = data.get("rows", [])
if isinstance(rows, list):
return data
except Exception:
pass
return {
"status": "not_started",
"hardware": "L40S",
"rows": [],
"claim_boundary": "No claim-scoped benchmark artifact has been published yet.",
}
def _runtime_packages(data: dict[str, Any] | None = None) -> list[dict[str, Any]]:
benchmark_data = data if data is not None else _load_benchmark_results()
packages: list[dict[str, Any]] = []
for row in benchmark_data.get("rows", []):
package_url = row.get("package_url")
if not package_url:
continue
claim_ready = (
row.get("public_before_after") is True
or row.get("public_claim_level") == "verified_showcase"
)
packages.append(
{
"family": row.get("family"),
"model_id": row.get("model_id"),
"hardware": row.get("hardware"),
"precision": row.get("precision"),
"package_status": row.get("package_status"),
"package_url": package_url,
"package_sha256": row.get("package_sha256"),
"benchmark_artifact": row.get("benchmark_artifact"),
"claim_ready": claim_ready,
"public_before_after": row.get("public_before_after") is True,
"public_claim_level": row.get("public_claim_level"),
"measurement_role": row.get("measurement_role"),
}
)
return packages
app = FastAPI(
title="VKAE-Gemma Showcase",
description="VIDRAFT Kernel Acceleration Engine for Gemma lead and benchmark showcase.",
version="0.1.0",
)
app.mount("/static", StaticFiles(directory=STATIC_ROOT), name="static")
@app.get("/")
def index() -> FileResponse:
return FileResponse(STATIC_ROOT / "index.html")
@app.get("/api/health")
def health() -> dict[str, Any]:
return {
"ok": True,
"service": "vkae-gemma-showcase",
"dataset_sync_enabled": SYNC_TO_DATASET,
"dataset_configured": bool(LEADS_DATASET),
"openai_compat_surface": True,
"serving_enabled": False,
}
@app.get("/api/service-types")
def service_types() -> dict[str, Any]:
return {"service_types": SERVICE_TYPES}
@app.get("/api/productization")
def productization() -> dict[str, Any]:
l40s_benchmarks = _load_benchmark_results()
return {
"status": PRODUCT_STATUS,
"delivery_packages": DELIVERY_PACKAGES,
"engine_roadmap": ENGINE_ROADMAP,
"runtime_packages": _runtime_packages(l40s_benchmarks),
}
@app.get("/api/metrics")
def metrics() -> dict[str, Any]:
l40s_benchmarks = _load_benchmark_results()
return {
"notice": "Showcase data. Queued rows are measurement plans, not public performance claims.",
"product_status": PRODUCT_STATUS,
"delivery_packages": DELIVERY_PACKAGES,
"runtime_packages": _runtime_packages(l40s_benchmarks),
"engine_roadmap": ENGINE_ROADMAP,
"series": BENCHMARK_SERIES,
"gpu_sizing": GPU_SIZING_GUIDE,
"benchmark_plan": BENCHMARK_PLAN,
"l40s_benchmarks": l40s_benchmarks,
"official_catalog_count": sum(len(item["repos"]) for item in OFFICIAL_MODEL_CATALOG),
"measurement_axes": [
"throughput_tps",
"latency_p50_p95",
"gpu_memory_peak",
"quality_or_ppl_guard",
"baseline_stack",
"vkae_recipe",
],
}
@app.get("/api/packages")
def packages() -> dict[str, Any]:
l40s_benchmarks = _load_benchmark_results()
runtime_packages = _runtime_packages(l40s_benchmarks)
return {
"status": l40s_benchmarks.get("status"),
"packages": runtime_packages,
"claim_ready": [item for item in runtime_packages if item["claim_ready"]],
"raw_only": [item for item in runtime_packages if not item["claim_ready"]],
"claim_boundary": l40s_benchmarks.get("claim_boundary"),
}
@app.get("/api/benchmark-schema")
def benchmark_schema() -> dict[str, Any]:
return {
"schema": CUSTOMER_BENCHMARK_SCHEMA,
"benchmark_plan": BENCHMARK_PLAN,
"claim_boundary": (
"This schema is for customer/private benchmark reports. The public "
"Space does not promote raw compatibility rows as before/after "
"VKAE performance claims."
),
}
@app.get("/api/model-catalog")
def model_catalog() -> dict[str, Any]:
return {
"source": "Hugging Face Hub google/gemma-4-* model ids checked from the public Google namespace.",
"official_prefix": "google/gemma-4-*",
"families": OFFICIAL_MODEL_CATALOG,
"adjacent": ADJACENT_GEMMA_MODELS,
"gpu_sizing": GPU_SIZING_GUIDE,
"benchmark_plan": BENCHMARK_PLAN,
"official_repo_count": sum(len(item["repos"]) for item in OFFICIAL_MODEL_CATALOG),
}
@app.get("/v1/models")
def openai_models() -> dict[str, Any]:
return {"object": "list", "data": OPENAI_COMPAT_MODELS}
@app.post("/v1/chat/completions")
async def chat_completions(payload: ChatCompletionRequest) -> JSONResponse:
known_models = {item["id"] for item in OPENAI_COMPAT_MODELS}
if payload.model not in known_models:
return JSONResponse(
status_code=404,
content={
"error": {
"message": f"Model {payload.model!r} is not available on this VKAE preview surface.",
"type": "invalid_request_error",
"param": "model",
"code": "model_not_found",
}
},
)
return JSONResponse(
status_code=501,
content={
"error": {
"message": (
"This public Space exposes VKAE-Gemma discovery and intake only. "
"Chat completions are enabled through a managed private endpoint "
"or private Docker evaluation after qualification."
),
"type": "not_implemented_error",
"param": None,
"code": "managed_endpoint_required",
},
"vkae": {
"service_paths": ["managed_endpoint", "docker_eval", "enterprise_onprem"],
"lead_endpoint": "/api/leads",
"benchmark_schema": "/api/benchmark-schema",
},
},
)
@app.post("/api/leads")
async def submit_lead(lead: LeadSubmission, request: Request) -> JSONResponse:
record = _validate_lead(lead)
record["client"] = {
"user_agent": request.headers.get("user-agent", "")[:240],
"referer": request.headers.get("referer", "")[:240],
}
_append_local(record)
sync = _sync_private_dataset()
return JSONResponse(
{
"ok": True,
"lead_id": record["lead_id"],
"message": "Request received. VIDRAFT will follow up for the selected service path.",
"dataset_sync": sync["status"],
}
)