cellmap_flow.ai_annotate.config
The server-side config that turns AI-assisted annotation on, and what it allows.
The feature sends EM data to a hosted model, which costs money and moves data off site, so it is off unless the user who runs the dashboard writes a config file saying which providers and models may be used. The browser only ever picks a provider id and model id from this file’s lists; endpoints, projects and credentials come from here and from the environment, never from a request.
The file holds no secrets. A key-based provider names an environment variable
(api_key_env) or a key file (api_key_file); an inline api_key is
a config error, so a key cannot end up in a file that gets copied, shared or
committed. Error messages name the setting that is wrong, never its value,
in case the value is a key pasted in the wrong place.
The file is read on each request that needs it (it is small), so an edit takes effect without restarting the dashboard.
Attributes
Classes
One provider the config allows: its id, type, models, and the rest of |
|
The parsed config file. Built only by |
Functions
Where the config is read from: |
|
The config, or None when the file does not exist or says |
|
Why the feature is off, and how to turn it on, for the dashboard to show. |
Module Contents
- cellmap_flow.ai_annotate.config.CONFIG_ENV = 'CELLMAP_FLOW_AI_ANNOTATE_CONFIG'
- cellmap_flow.ai_annotate.config.DOCS = 'docs/ai_annotate.md'
- cellmap_flow.ai_annotate.config.DEFAULT_DAILY_CALL_LIMIT = 200
- cellmap_flow.ai_annotate.config.DEFAULT_CROP_SIZE_PX = 512
- cellmap_flow.ai_annotate.config.DEFAULT_VERTEX_LOCATION = 'global'
- cellmap_flow.ai_annotate.config.DEFAULT_TIMEOUT_S = 120
- cellmap_flow.ai_annotate.config.PROVIDER_OPTIONS
- cellmap_flow.ai_annotate.config.config_path()
Where the config is read from:
$CELLMAP_FLOW_AI_ANNOTATE_CONFIG, else~/.cellmap_flow/ai_annotate.yaml.
- class cellmap_flow.ai_annotate.config.ProviderConfig
One provider the config allows: its id, type, models, and the rest of its settings (
options: project, location, timeout_s, …).- id: str
- type: str
- models: tuple
- options: dict
- destination()
Where a request to this provider sends the data, in words, for the user to acknowledge before the first call. Names the location but not the project: the user needs to know which company and region, not an account id.
- class cellmap_flow.ai_annotate.config.AIAnnotateConfig
The parsed config file. Built only by
load_config, which validates it.- enabled: bool
- providers: dict
- default_provider: str
- daily_call_limit: int
- crop_size_px: int
- allowed_dataset_prefixes: tuple
- provider(provider_id)
The provider with this id. Raises a config error (400: the id came from the browser) when the config has no such provider.
- check_model(provider_id, model)
Raise unless
modelis one of the provider’s listed models.
- check_dataset(dataset_path)
Refuse a dataset outside
allowed_dataset_prefixes, when that list is set.Local paths are normalised first, so
/allowed/../elsewheredoes not pass as/allowed. A URL is not rewritten (normpath would mangle it), so one with a.or..segment, plain or percent-encoded, is refused outright: an HTTP client resolves those, andhttps://host/allowed/../secretwould read/secret. A prefix matches as text: end it with/to mean one directory and not also its siblings that share the name’s start.
- public()
What the browser may see: provider ids, types, models and destinations, and the limits. No other option value (project, timeouts, key variable or file names) is included.
- cellmap_flow.ai_annotate.config.load_config()
The config, or None when the file does not exist or says
enabled: false.Raises a config error for a file that exists but is malformed, naming the problem and never echoing a value from the file.
- cellmap_flow.ai_annotate.config.disabled_reason()
Why the feature is off, and how to turn it on, for the dashboard to show.
Called when
load_configreturned None; a malformed file raises instead.