fix: draw the API key once, and let status answer the dimensions question
Release / release (push) Successful in 6s
Release / release (push) Successful in 6s
Two things a user setting this up hit immediately. The card drew `embeddingApiKey` twice. The render loop walked every entry in FIELDS, and the secret — which is drawn by hand, as a write-only password control — was one of them, so a second control appeared beside it: an ordinary text input, echoing the key in clear as you typed. One key, two boxes, one of them visible. The loop skips secrets now, and the tests count controls rather than checking that each expected label is present, because a duplicate beside the real control passed the old assertions. `status` could not answer the one question a new user cannot look up: how wide is this model? The probe that reports it was gated on every required setting being present, so in exactly the state that needs the answer — dimensions unset — it reported nothing and said "Missing: embedding_dimensions". It now runs whenever the endpoint can be named (a model and a base URL), and the status message names the width it observed: Missing: embedding_dimensions. The endpoint is reachable and returned 768 dimensions, so set embeddingDimensions to 768. The probe also tells "not set yet" apart from "set wrong", because the two have different remedies. Also documents both ways to read the width by hand, since a wrong value is frozen into the index at first use and costs a full re-embed to correct.
This commit is contained in:
1 parent
85c0d4dccd
commit
9ebd484e60
7 files changed
+142
-7
No files matched your search
@@ -537,21 +537,43 @@ export function apply(ctx, config) {
|
||||
// A direct fetch rather than the shell seam: the probe is one small
|
||||
// HTTP request and does not belong behind a sandbox boundary that
|
||||
// exists to confine filesystem writes.
|
||||
//
|
||||
// It runs whenever the endpoint can be NAMED — a base URL and a model
|
||||
// — not only once every required setting is present. Gating it on
|
||||
// completeness hid it in the one state that needs it most: nobody can
|
||||
// look up how wide an arbitrary embedding model is, and the probe is
|
||||
// what reports the width it observed.
|
||||
const apiBase = typeof settings.embeddingApiBase === 'string' ? settings.embeddingApiBase : ''
|
||||
const model = String(slopoConfig.embedding_model ?? '')
|
||||
const endpoint =
|
||||
missing.length === 0
|
||||
apiBase.trim() !== '' && model.trim() !== ''
|
||||
? await probeEmbeddingEndpoint({
|
||||
apiBase: typeof settings.embeddingApiBase === 'string' ? settings.embeddingApiBase : '',
|
||||
model: String(slopoConfig.embedding_model ?? ''),
|
||||
apiBase,
|
||||
model,
|
||||
dimensions: Number(slopoConfig.embedding_dimensions ?? 0),
|
||||
apiKey: typeof settings.embeddingApiKey === 'string' ? settings.embeddingApiKey : '',
|
||||
})
|
||||
: { checked: false, skipped: 'nothing is configured yet' }
|
||||
: {
|
||||
checked: false,
|
||||
skipped: 'set embeddingModel and embeddingApiBase to probe the endpoint and read its dimensions',
|
||||
}
|
||||
|
||||
let message
|
||||
if (missing.length > 0) {
|
||||
message =
|
||||
`Not configured yet. Missing: ${missing.join(', ')}. Run this tool with action "configure" ` +
|
||||
'to set embeddingModel and embeddingDimensions, then "prepare".'
|
||||
// The one thing a new user cannot look up anywhere: how wide this
|
||||
// model's vectors are. Say it plainly when that is what is missing.
|
||||
if (
|
||||
endpoint.checked === true &&
|
||||
typeof endpoint.dimensions === 'number' &&
|
||||
missing.includes('embedding_dimensions')
|
||||
) {
|
||||
message +=
|
||||
` The endpoint is reachable and returned ${endpoint.dimensions} dimensions, so ` +
|
||||
`set embeddingDimensions to ${endpoint.dimensions}.`
|
||||
}
|
||||
} else if (endpoint.ok === false) {
|
||||
message =
|
||||
`Configured, but the embedding backend failed its check: ${endpoint.error}. ` +
|
||||
|
||||
Reference in new issue
Block a user