Skip to content

tdfs4ds.serve.model_keys

tdfs4ds.serve.model_keys

The model API keys typed in the app, kept by the gateway (0.3.8.2).

In the Docker deployment every person has an app process of their own, so a key typed on the Parameters page would live and die with that process. The gateway keeps it instead: encrypted (AES-256-GCM) in the credentials volume, and hands it to every worker it starts. The key of the file is derived from TDFS4DS_SERVE_SECRET; without a configured secret nothing is written (a random per-process secret could not decrypt the file after a restart).

Only the two model keys are kept, never a database password.

logger module-attribute

logger = logging.getLogger('tdfs4ds.gateway')

KEY_NAMES module-attribute

KEY_NAMES = ('INSTRUCT_MODEL_API_KEY', 'EMBEDDING_MODEL_API_KEY')

FILE module-attribute

FILE = 'model_keys.bin'

_AAD module-attribute

_AAD = b'tdfs4ds-model-keys-v1'

ModelKeyStore

Encrypted file with the model keys. Thread safe; never raises on a bad or missing file.

dir instance-attribute

dir = directory or os.environ.get('TDFS4DS_SERVE_CREDENTIALS_DIR') or os.path.join(os.environ.get('TDFS4DS_SERVE_DATA_DIR') or '/data', 'credentials')

path instance-attribute

path = os.path.join(self.dir, FILE)

available property

available: bool

True when a stable secret is configured, so what is written can be read back.

__init__

__init__(directory: Optional[str] = None)

load

load() -> Dict[str, str]

update

update(changes: Dict[str, str]) -> bool

Merge changes (a non-empty value replaces) and write the file. True when written.

_configured_secret

_configured_secret() -> Optional[bytes]

_aes_key

_aes_key(secret: bytes) -> bytes