Skip to content

Latest commit

 

History

History
257 lines (150 loc) · 26.7 KB

admin.md

File metadata and controls

257 lines (150 loc) · 26.7 KB

The admin panel

Almost everything that makes one instance different from another lives at /admin, in the database, editable while the instance runs. The .env file holds only what has to exist before the app starts: database, Redis, API keys, SMTP.

You need an admin account to get in. Put your email in ADMIN_EMAILS and restart the backend; the account is created if it does not exist and promoted if it does.

ADMIN_EMAILS='["you@example.com"]'

On an instance that is already running, ./comparia-cli db seed-admins does the same thing without a restart.

Two-factor authentication

Every admin has to pair an authenticator app (Google Authenticator, Aegis, FreeOTP, or any app that reads a QR code and shows six digits). The first time an admin opens /admin without one, they land on /settings and are asked to set it up; after that, signing in asks for the email code and then the six digits. Promoting someone signs them out everywhere, so they pair their app at their next sign-in. An admin who has just accepted an invite should pair it straight away: until they do, anyone holding their session can pair a device in their name.

The app's secrets are encrypted in the database with COMPARIA_ENCRYPTION_KEY. The same key protects the provider API keys of the endpoints, the moderation key and the publishing credentials. The backend refuses to start without one outside debug mode, and refuses to start anywhere with one that is not a Fernet key (a hex string from openssl rand -hex 32 is not). The migration job needs the same variable, since backend.config checks it at import before Alembic runs. Generate one with:

python -c 'from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())'

To rotate it, put the new key first and keep the old one after a comma: COMPARIA_ENCRYPTION_KEY=new,old, restart, then run ./comparia-cli db reencrypt-secrets. Every stored secret, the admins' authenticator secrets and the OIDC client secret included, is rewritten with the new key in one transaction, and the command reports how many rows it rewrote per table. It refuses to run, and changes nothing, if any stored secret cannot be decrypted with the keys given: keep the old key in the list until a run has reported success, then drop it. Signing in also re-encrypts an admin's own authenticator secret with the first key, as before.

A secret whose key was dropped too early is not lost, but nothing can use it: at startup the backend logs an error naming each such row, an endpoint whose key cannot be read has its models disabled while the others keep running, the admin panel still shows the key as set, and a publishing destination in that state fails its run. Put the key back in the list and everything comes back.

An admin changes device from /settings: a code from the current app, then the new QR code. Their other sessions are signed out when the new app is confirmed.

An admin who lost their phone asks another admin, who opens /admin/utilisateurs and uses the reset action on their row. That signs them out everywhere and sends them back to the setup screen at their next visit. Do this over a channel you trust, since the email code alone then opens the admin area again. Nobody can reset their own row.

If the only admin is locked out, there is no button left. Run the same reset from the machine that has the database:

./comparia-cli db reset-totp admin@example.org
# or: make db-reset-totp EMAIL=admin@example.org

Then sign in with an email code and set the app up again from /settings.

Activity

/admin/activite shows what happens in the arena. The two filters at the top, period and model, apply to both tabs and stay in the address, so a link shows a colleague the same view. Mode, cohort, custom dates and archived conversations have no control on the page but still work when set in the address (mode=, cohort=, start=/end=, include_archived=true).

Vue d'ensemble opens on the journey as a funnel: conversations started, those with at least one vote, those where the models were revealed, with the share that goes on at each step. Each step, and each group that stopped before the next one, opens the matching conversations. Under it sit the message counts, the activity over time, and the share of each vote and mode. Prompt checks have their own page under Vérifications. The counts are kept for five minutes; the link at the bottom computes them again. The period still under way is drawn as an estimate of what it will hold once full, read from how a typical day fills up, rather than as the drop its partial count would show.

Conversations lists every conversation, newest first, and can search the text of the messages. Each row shows the first message, the two models with the preferred one in bold, any comment, and how far the conversation went on the same steps as the funnel. Search and the journey filter narrow the list; the vote, topic and flag filters work from the address, which the overview's funnel links use. A click opens the conversation in a pop-up: each question, the start of both answers side by side with the preferred one marked, and the tags and comments left on each, with the full answer one click away; the arrows, or the left and right keys, step to the next row without closing it. Subjects and languages come from the analysis the publishing pipeline runs, so a conversation not analysed yet has none; keywords only show on conversations analysed before the decision model. Text the analysis flagged as personal data stays blurred until you ask to see it, and every conversation opened is logged with the admin who opened it.

To try the panel at the size of a real instance on a debug database:

make db-seed-activity COUNT=500000

LLMs

/admin/llms has four tabs, and the order matters, because a model points at the other three.

Labs are who made the model: name, country of origin, logo. Licences carry the name, the kind, and whether reuse and commercial use are allowed. Endpoints are where requests go: api_type (the LiteLLM provider), api_base, and the API key. Several models normally share one endpoint.

LLMs are the models themselves. Each one names a lab, a licence and an endpoint, plus the api_model_id the provider expects, prices per token, parameter count, context window, and the openness flags the model catalogue displays: public weights, public training data, public training code, EU-hostable.

Status decides what the arena does with a model:

Status Meaning
enabled drawn in matches
disabled not drawn, still shown in past conversations
archived retired, kept for the record and the leaderboard

Adding models one by one through the panel is fine for a handful. For more, write them to JSON and import:

./comparia-cli llms import path/to/llms-data.json

./comparia-cli llms export writes the current catalogue to data/llms-data.json, which is the easiest way to see what the format looks like.

Tools

/admin/outils lists the tools visitors can offer to both models before a comparison: web search, built in, and the MCP servers added here. A tool sends queries the models write from visitor prompts to an outside service, so every tool starts switched off, web search included, and an admin turns each one on from the list.

Each row shows whether the tool answers now, how many calls models made to it over the last 30 days and how many failed, and a switch that offers or withdraws it at once. Every tool is tested when the list opens and the verdict is kept for 10 minutes; "Revérifier" tests them all again. A tool missing its credential or its address is left out of the visitor picker even when switched on.

Web search goes through Linkup. Its page takes the Linkup key, falling back on LINKUP_API_KEY when empty, and either the only sites results may come from or sites they never come from, not both.

MCP servers are added in four steps at /admin/outils/create: the address and an optional credential, which must pass a connection test; the functions offered to models, all of them when none is ticked, so functions the server adds later are offered too; the name and description visitors see; then a summary. A credential is a token sent as Authorization: Bearer, or a whole header written as Name: value.

Credentials are stored encrypted with COMPARIA_ENCRYPTION_KEY and never shown again; the page only says whether one is set. The test button runs the tool with what is saved and says why it failed: credential refused, no credit left, server not answering, timeout or no address. A tool can also carry a logo, shown in the picker and next to its steps in the answers.

Customization

/admin/customization controls the platform name, logo, the four brand colours (primary and secondary, each in a light and a dark variant), the homepage link, and the vote target the public counter counts towards.

It also sets three leaderboard thresholds: the votes a model needs before it is ranked (0 by default), how many places its rank may move either way before it is hidden (30 by default), and how many before a shown model is greyed out (30 by default, which greys out nothing). A small instance can relax them to show something while votes come in, or raise the hide threshold and grey out the uncertain models instead. The vote minimum applies at the next ranking update, within the hour.

Languages

/admin/locales sets which languages the instance offers and which one it defaults to. The default has to be one of the enabled ones.

Seven locales are wired up: da, en, fr, it, lt, nb-NO, sv. There are more translation files in frontend/locales/messages/, but a locale is only selectable once it is added to SupportedLocale in utils/i18n.py and ./comparia-cli internal i18n has been run.

Authentication

/admin/authentification decides whether people can use the arena without an account.

  • anonymous_first: anyone can vote, signing in is optional. The default.
  • sign_in_required: no arena without a session.

An optional domain allowlist restricts who can ask for a login code, which is how you keep an instance to one organisation.

Single sign-on (OIDC)

The same page lets people sign in through an OpenID Connect provider (ProConnect, Keycloak, Entra ID, or any provider that publishes a /.well-known/openid-configuration document) next to, or instead of, the email code. An email is one account whatever the method, and its letter case does not matter.

  1. At the provider, register a confidential client (authorization code flow) and give it this redirect URI:

    <origin the backend answers on>/api/auth/oidc/callback
    

    The origin is COMPARIA_API_URL when set, and COMPARIA_APP_URL otherwise. Behind the usual ingress, which serves the backend under /api of the app origin, leave COMPARIA_API_URL empty (config.apiUrl in the Helm chart). Set it only when the backend is reached on another origin, as in local development.

  2. In /admin/authentification, fill in the issuer URL, client ID, client secret and scopes (openid and email at least), and optionally the button label and logo. The issuer and the endpoints it announces have to be https; http://localhost and http://127.0.0.1 are accepted for a local Keycloak.

  3. Use Test connection. It fetches the discovery document and checks that the stored secret can be decrypted, and says what is wrong when it fails. Removing the email code method is only possible once a test has passed for the current provider settings; changing the issuer, client ID or secret asks for a new test. This keeps you from locking everybody out, yourself included.

  4. Tick oidc in the enabled methods.

The client secret is stored encrypted with COMPARIA_ENCRYPTION_KEY, like the other secrets, and is never sent back to the browser. If the key is rotated without keeping the old one after a comma (see above), the secret can no longer be read: the SSO button disappears from the login page until you enter the secret again.

If the button is there but every sign-in comes back to the login page with an error, check that the origin in the address bar when signing in is the one in the redirect URI above. The backend refuses to start a sign-in from another origin and logs both origins, because the browser would never send its state cookie back to the callback.

Legal pages

/admin/legal holds the terms, privacy policy, the participation conditions, and any extra informational pages. Terms and the privacy policy are versioned: you edit a draft and publish it, and the published version is what visitors see.

Users

/admin/utilisateurs is where you search accounts, change roles, invite people by email, reset someone's two-factor authentication and delete an account. Anyone in ADMIN_EMAILS gets admin again on every restart, so remove them from the env before demoting them here.

Changing someone's role signs them out everywhere, you included if you demote yourself. A pending invite still works, so to add an admin, invite them and then change their role. Changing someone's address signs them out too and cancels the links and codes already sent: send a new invite to the corrected address.

A deleted account cannot ask for an email code. Inviting or re-adding its address brings it back signed out and without an authenticator: as a plain user by invite, or with the role you pick when you add it here.

Inactive accounts

comparia-cli db purge-inactive --months N (or make db-purge-inactive MONTHS=N) removes accounts nobody has signed into for N months. The default is 24, the two years the privacy policy states. It is a dry run until you pass --apply (APPLY=1 with make): it lists who would get the warning, who would be erased, which rows asked for a login code but never signed in, and which admins would have matched. Run it that way from the CLI first to preview what the CronJob below will do.

An account is first warned by email, once, 30 days before the deadline or as soon as it is found past it, in the language the person accepted the terms in. It is erased at the later of the deadline and 30 days after the warning, unless the person signs in again meanwhile, which resets the clock. Erasure is what the person gets when they delete their own account from the settings page. A deletion from the admin panel already signs the person out, closes their codes and links, and refuses new email codes; erasure also replaces the email address with a placeholder, keeps the consent proof without its address, and leaves the conversations in the research datasets with no link back to the person. Rows that asked for a login code but never signed in are erased without a warning once past the deadline, as there was never an account to keep. Accounts holding an invite that can still be accepted are left alone. Admins are never erased, only listed. "Signed in" is what counts, not visits: a session lasts AUTH_SESSION_LENGTH_DAYS (30 by default), so the command refuses a number of months whose window, 30 days of notice included, would reach an account still on a live session.

The Helm chart carries a weekly CronJob for it, cronjobs.purgeInactive, off by default. Before you turn it on, publish a privacy policy that states the retention period you chose, and check SMTP is set up: the CronJob reads the same config.smtp.* and config.appUrl values as the backend, and without them no warning goes out. Accounts warned on an earlier run, and rows that never signed in, are still erased.

Retention

comparia-cli db purge-retention (or make db-purge-retention) applies the other retention periods of the privacy policy. Each rule runs on its own, in batches of 5,000 rows (200 conversations for the rules that delete whole conversations), so a run that stops halfway is picked up by the next one. Defaults, all overridable on the command line:

  • comparison IP addresses are replaced by erased after 3 months (--ip-months). Nothing in the app reads them back.
  • comparisons lose their account, Matomo visitor id and anonymous session hash after 24 months (--comparison-months). The conversation text and votes stay, which is what the datasets are built from.
  • session rows, login codes and 2FA challenges are deleted 12 months after they expired or were revoked (--session-months). An account that still exists keeps its latest session row, with the IP and browser blanked: purge-inactive reads it to tell a dormant account, which gets a warning, from a login code nobody used, which does not. A consent proof that names a deleted session keeps everything but that link.
  • moderation results are deleted after 12 months (--prompt-check-months).
  • consent proofs are deleted 5 years after the account was deleted, or after the anonymous session ended for a visitor who never signed in (--consent-years).
  • conversations the analysis flagged as holding personal data are deleted 30 days after the analysis (--pii-days), with their turns, messages and moderation results. They are never published nor counted in the ranking. Rows imported without an analysis date count from their creation.
  • conversations that came through a partner programme (the cohorts column, Pix pupils for now) are deleted 30 days after they were written (--cohort-days), the same way. They are never published nor counted in the ranking, so only the person's own history loses them.

Accounts themselves are left to purge-inactive. Like it, the command is a dry run until you pass --apply, and only counts the rows each rule would change. The dry run counts each rule against today's data, so the anonymous consents freed by deleting an account's proof in the same run only show up once applied.

The Helm chart runs it daily with cronjobs.purgeRetention, off by default. Change the periods there and in the published privacy policy together: the policy is what people were told.

Audience measurement

Matomo only stays exempt from consent while its data is kept apart from the arena's. Comparisons no longer keep the Matomo visitor id, but older rows may still hold one. Count them, then clear them:

make db-clear-visitor-ids            # counts, changes nothing
make db-clear-visitor-ids COMMIT=1   # clears them

Publishing

/admin/publication sets where the open datasets go, and how often.

A run produces two datasets: normal, the open one, and raw, which still holds flagged comparisons. Each destination picks which of the two it receives, so an instance can publish the open dataset publicly and keep the raw one somewhere private.

Two kinds of destination:

  • Hugging Face: a token and a repository path like org/name. The raw dataset goes to org/name-raw.
  • S3: endpoint, bucket, optional region and key prefix. One bucket can hold several instances.

Frequency is per destination: off, daily, weekly or monthly. You choose the frequency, not the hour.

Voter ids in the raw dataset

Off by default. Turned on, the raw dataset carries extra_metadata.voter_id and extra_metadata.voter_type (account or anonymous) on each row, so whoever analyses it can group one person's comparisons: to leave out someone who replays the same prompt, or runs experiments. The open dataset never carries them.

  • The id is the same for every comparison of an account, or of an anonymous session (a browser, until its session cookie expires). An anonymous visitor who signs in and merges their history gets the account's id on it from the next run.
  • It is an HMAC of the internal identifier under a key made once per instance and stored encrypted, so it does not give away the account or the session, and stays the same from one run to the next.
  • It goes when the identifiers go: on account erasure, and when the retention period blanks them (24 months).
  • A Hugging Face repository has to be private, or gated with manual review, to receive the raw dataset while the ids are on; a new one is created private. The run cannot check an S3 bucket's access, so keep it private.

Turning it on lets anyone holding the raw dataset link one person's conversations together, and with the survey answers once those are published. Cover it in the terms of use before turning it on.

To check a run before trusting it with credentials:

make dataset-export-dry-run   # builds the datasets, sends them nowhere

Analysis before publishing

Before a run builds the open dataset, the decision model of the prompt checks reads each new conversation, the visitor's messages and both answers. It answers the exclusion criteria set on /admin/publication (personal data and spam to start with), one question per topic and one per language. A conversation that reaches the threshold of any exclusion criterion stays out of the open dataset; it still goes to the raw one. Topics and languages are tagged from their own thresholds, and a conversation with no topic over the threshold is tagged Other. The languages asked about are the instance's own, a few common ones, and "other". Partner cohorts (Pix) are never sent.

A long conversation is read in windows of 8,000 characters, and each question keeps its highest score. One over about 300,000 characters is not sent and counts as failed. A conversation the model cannot score after three tries is marked failed and is never published. A refused key or no credits stops the run.

The key comes from the panel, then from the prompt checks, then from OPENROUTER_API_KEY. With no model set, nothing is analysed, so no new conversation is published. The page has a test box for a pasted conversation, against the settings on screen, saved or not.

Every score is kept on the conversation (analysis_scores). short_summary and keywords are no longer written: conversations analysed before keep theirs, newer ones publish null.

Three commands help tune it:

make db-analysis-shadow SAMPLE=500   # scores conversations the old chat model analysed and compares, writes nothing
make db-analysis-reapply             # what the current thresholds would change on scored conversations; COMMIT=1 writes it
make db-analysis-rescore             # how many published conversations the model would score again; COMMIT=1 does it

Rescoring gives the published conversations the old chat model analysed, or that another decision model scored, new topics, languages and scores, and holds back those that reach an exclusion criterion. EVERY=1 scores all published conversations, which a new criterion needs: reapplying only works with the criteria a conversation was scored on. Reapplying also leaves alone a conversation held for personal data or spam when a criterion with that reason was renamed, removed or never scored on it, so a changed criterion list never releases it. Held conversations are left alone and one the model cannot score keeps what it had, so rescoring never publishes anything that was not. Stopped and run again, it skips the conversations already done (not with EVERY=1). A conversation flagged for personal data is deleted 30 days after the analysis, so loosening a rule only releases what is still there.

Prompt checks

/admin/prompt-checks checks what people type before it reaches the models. A decision model on OpenRouter reads each message next to a short description of the instance and answers the criteria you write, one yes/no question each, with the probability of yes.

Each criterion has a question, an optional description of what counts as yes and as no, a threshold, an action (off, log, warn or block) and the message a visitor sees when it warns or blocks: general, self-harm (names a helpline) or personal data. Criteria can be added, edited and removed. Keep a criterion's key once it has fired: stored verdicts and the stats are counted by key. The model is picked from the decision models OpenRouter lists, or typed in. The page has a try box for testing a prompt against the settings on screen, saved or not, and stats on what has fired.

The API key comes from the panel if you set it there, and from OPENROUTER_API_KEY otherwise. With neither, the checks pass everything through whatever their configured action says, and the page warns about it.

With "Vérification obligatoire" (required) on, the default, a message the check cannot answer (a timeout, OpenRouter busy or failing, a refused key, no credits left) is refused. Off, it goes through, and the failure still shows in the stats. Either way, after five provider failures in a row the check counts OpenRouter as down and lets messages through unchecked for a minute at a time, until a call works again.

The same page sets two limits on how many conversations one IP may start over a sliding hour: in all, and with the same pair of models. Over a limit the arena answers rate_limited. 0 turns a limit off, and unset they follow RATELIMIT_CONVERSATIONS_PER_IP_PER_HOUR (20) and RATELIMIT_CONVERSATIONS_SAME_MODELS_PER_IP_PER_HOUR (5); emptying a field on the page goes back to them. The limits hold even when the checks are switched off. Everyone behind one IP shares them, a school or a ministry included, and the pix cohort is not counted (it is what the browser declares, nothing verifies it).

Vote tags

/admin/vote-tags lists the reasons offered to someone who has just voted. Each tag has an emoji, a sign saying whether it is praise or criticism, a label per language, and a display order. They are per instance, so a sector-specific arena can ask about what matters to it.

Tags are archived rather than deleted, so old votes keep meaning something.

Survey

/admin/survey holds the questions asked to describe who takes part. Each question is a single choice or a set of checkboxes, with a label per language and its options. There is no free text answer: add an option instead.

The table lists every question in the order it is asked, with its respondent count. Drag a row or use the arrows to reorder.

  • Required: a signed-in account must answer it before it can chat or vote again. The questions come up right after sign-in. Optional questions are offered in a card in the navigation bar, to anonymous visitors too.
  • Published: only the answers to published questions go into the public dataset. A set of answers shared by fewer than five respondents is exported empty, and only answers given under the terms in force are exported.
  • Archive: a question with answers is archived rather than deleted, and a removed option is archived too, so existing answers keep their label. Delete only works on a question nobody answered.

An optional question shown but left blank comes back at most three times, with a gap between showings set by survey_reask_after_days in the instance settings (7 days by default). People see and edit their answers on their settings page, and the answers are part of their data export.

Suggestions

/admin/suggestions holds the starter prompts on an empty arena page, grouped into categories. Both categories and prompts are per language, so each locale gets its own.