File size: 3,074 Bytes
bc02199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c45600f
 
 
bc02199
 
 
 
 
 
 
 
 
 
c45600f
 
 
bc02199
 
 
 
 
 
 
e20e3d9
 
bc02199
 
e20e3d9
 
bc02199
e20e3d9
 
 
 
 
 
 
 
 
 
 
c45600f
e20e3d9
bc02199
 
 
c45600f
 
 
 
 
 
 
 
 
 
d30bd8e
 
bc02199
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Shared configuration for the initial mock MVP."""

import os
from collections.abc import Mapping
from dataclasses import dataclass
from pathlib import Path


APP_TITLE = "Objectverse Diary"
APP_SUBTITLE = "Every object has a secret life. / 每个物品都有秘密人生。"
APP_VERSION = "0.1.0-mock"

PERSONALITY_MODES = [
    "Cynical",
    "Dramatic",
    "Lonely",
    "Philosopher",
    "Romantic",
]

DEFAULT_MODE = "Cynical"


@dataclass(frozen=True)
class RuntimeSettings:
    vision_backend: str
    text_backend: str
    text_model_path: str
    text_model_repo_id: str
    text_model_filename: str
    text_model_revision: str
    vision_model_id: str
    trace_output_dir: Path


def get_runtime_settings(environ: Mapping[str, str] | None = None) -> RuntimeSettings:
    env = os.environ if environ is None else environ
    return RuntimeSettings(
        vision_backend=env.get("OBJECTVERSE_VISION_BACKEND", "mock"),
        text_backend=env.get("OBJECTVERSE_TEXT_BACKEND", "mock"),
        text_model_path=env.get("TEXT_MODEL_PATH", ""),
        text_model_repo_id=env.get("TEXT_MODEL_REPO_ID", ""),
        text_model_filename=env.get("TEXT_MODEL_FILENAME", ""),
        text_model_revision=env.get("TEXT_MODEL_REVISION", ""),
        vision_model_id=env.get("VISION_MODEL_ID", ""),
        trace_output_dir=Path(env.get("TRACE_OUTPUT_DIR", "data/traces")),
    )


def runtime_status(settings: RuntimeSettings | None = None) -> dict[str, str]:
    current = settings or get_runtime_settings()
    vision_backend = current.vision_backend.strip().lower()
    text_backend = current.text_backend.strip().lower()
    vision = (
        "mock object understanding"
        if vision_backend == "mock"
        else f"{vision_backend} object understanding"
    )
    text = "mock persona and diary generation"
    if text_backend in {"llama-cpp", "llama_cpp", "llamacpp"}:
        text = "llama-cpp text generation"
    elif text_backend != "mock":
        text = f"{text_backend} text generation"
    runtime_parts: list[str] = []
    if vision_backend != "mock":
        runtime_parts.append(f"vision model id: {current.vision_model_id or '[not configured]'}")
    if text_backend == "mock":
        runtime_parts.append("no llama.cpp model connected yet")
    else:
        runtime_parts.append(f"text model source: {_text_model_source_status(current)}")
    runtime = "; ".join(runtime_parts)
    return {"vision": vision, "text": text, "runtime": runtime}


def _text_model_source_status(settings: RuntimeSettings) -> str:
    if settings.text_model_path.strip():
        return "[configured external GGUF]"
    repo_id = settings.text_model_repo_id.strip()
    filename = settings.text_model_filename.strip()
    if repo_id and filename:
        revision = settings.text_model_revision.strip()
        suffix = f"@{revision}" if revision else ""
        return f"Hub GGUF: {repo_id}/{filename}{suffix}"
    return "[not configured]"


SETTINGS = get_runtime_settings()
TRACE_DIR = SETTINGS.trace_output_dir
MODEL_RUNTIME_STATUS = runtime_status(SETTINGS)