Stop shipping a placeholder that looks like a value, and say what is served
A user copied the curl from the profile page and sent it as it stood. Every other field in that snippet is filled in for them — the base URL, the key they had just been issued — so "model": "MODEL" reads as a value rather than a blank, and they got: no endpoint serves "MODEL" which is true and useless. It reads the same whether the name was a typo, a placeholder left in from the documentation, or a real outage, and it never says what would have worked. The message now lists what is being served, capped at ten with a count for the rest, and says plainly when nothing is. That list is what /v1/models already returns to the same caller, so it discloses nothing new. The profile page's example now names a model that is actually running, real ones before simulated — the point of an example someone can run is that it runs, and sending a first request to the sim engine would answer in Greek letters. The landing and claim pages keep a placeholder, because they are served without a key and deliberately say nothing about what is here; theirs is <model-name>, which cannot be mistaken for a value, with a line saying where to get the real one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6f3bde099e
commit
082d52bc97
8 files changed
+170
-6
No files matched your search
+34
-2
@@ -47,6 +47,33 @@ type AccountPages struct {
|
||||
passwords account.PasswordChanger
|
||||
version string
|
||||
log *slog.Logger
|
||||
// served, when set, names the models an endpoint is currently serving. The
|
||||
// curl example on this page fills its model field from it: every other
|
||||
// field in that snippet is real, so the one placeholder left in it was
|
||||
// copied verbatim and sent as the literal string MODEL.
|
||||
served func() []string
|
||||
}
|
||||
|
||||
// ServedModels supplies the names the profile page's example should use.
|
||||
//
|
||||
// A setter rather than a constructor argument because only the router knows
|
||||
// what is being served, and the page is useful without it — with no source the
|
||||
// example falls back to a placeholder, which is what it always was.
|
||||
func (p *AccountPages) ServedModels(f func() []string) { p.served = f }
|
||||
|
||||
// exampleModel picks the model the copy-pasteable example should name.
|
||||
//
|
||||
// A real model over a simulated one is not expressible here — this package does
|
||||
// not know which is which — so it takes the first served name and relies on the
|
||||
// router listing real models first.
|
||||
func (p *AccountPages) exampleModel() string {
|
||||
if p.served == nil {
|
||||
return "<model-name>"
|
||||
}
|
||||
if names := p.served(); len(names) > 0 {
|
||||
return names[0]
|
||||
}
|
||||
return "<model-name>"
|
||||
}
|
||||
|
||||
// NewAccountPages builds the handlers.
|
||||
@@ -189,8 +216,11 @@ type profileData struct {
|
||||
|
||||
CSRF string
|
||||
BaseURL string
|
||||
Version string
|
||||
Now string
|
||||
// ExampleModel is a model that is actually being served, so the example on
|
||||
// the page can be copied and run as it stands.
|
||||
ExampleModel string
|
||||
Version string
|
||||
Now string
|
||||
}
|
||||
|
||||
func (p *AccountPages) profile(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -272,6 +302,7 @@ func (p *AccountPages) render(w http.ResponseWriter, r *http.Request,
|
||||
d.User = user
|
||||
d.MinPassword = account.MinPasswordLen
|
||||
d.BaseURL = baseURL(r)
|
||||
d.ExampleModel = p.exampleModel()
|
||||
d.Version = p.version
|
||||
d.Now = time.Now().UTC().Format(time.RFC3339)
|
||||
// The form token comes from the cookie, never from whatever the request
|
||||
@@ -474,6 +505,7 @@ func (p *AccountPages) renderWithCSRF(w http.ResponseWriter, r *http.Request,
|
||||
d.User = user
|
||||
d.MinPassword = account.MinPasswordLen
|
||||
d.BaseURL = baseURL(r)
|
||||
d.ExampleModel = p.exampleModel()
|
||||
d.Version = p.version
|
||||
d.Now = time.Now().UTC().Format(time.RFC3339)
|
||||
d.CSRF = csrf
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package web
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTheExampleNamesARealModel(t *testing.T) {
|
||||
// Every other field in that curl is filled in — the base URL, the key —
|
||||
// so the one placeholder in it reads like a value. It was copied verbatim
|
||||
// and sent as the literal string MODEL.
|
||||
p := &AccountPages{}
|
||||
if got := p.exampleModel(); got != "<model-name>" {
|
||||
t.Errorf("with no source the example should be an obvious placeholder, got %q", got)
|
||||
}
|
||||
p.ServedModels(func() []string { return nil })
|
||||
if got := p.exampleModel(); got != "<model-name>" {
|
||||
t.Errorf("with nothing served the example should be a placeholder, got %q", got)
|
||||
}
|
||||
p.ServedModels(func() []string { return []string{"qwen", "big-model"} })
|
||||
if got := p.exampleModel(); got != "qwen" {
|
||||
t.Errorf("example model = %q, want the first served name", got)
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ Tell whoever you asked for access that you have signed up.</p>
|
||||
<pre>curl {{.BaseURL}}/v1/chat/completions \
|
||||
-H "Authorization: Bearer {{.NewKey}}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "MODEL", "messages": [{"role":"user","content":"hello"}]}'</pre>
|
||||
-d '{"model": "{{.ExampleModel}}", "messages": [{"role":"user","content":"hello"}]}'</pre>
|
||||
{{end}}
|
||||
|
||||
<h2>Create a key</h2>
|
||||
|
||||
@@ -20,7 +20,12 @@
|
||||
curl {{.BaseURL}}/v1/chat/completions \
|
||||
-H "Authorization: Bearer $LLMGW_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "MODEL", "messages": [{"role":"user","content":"hello"}]}'</pre>
|
||||
-d '{"model": "<model-name>", "messages": [{"role":"user","content":"hello"}]}'</pre>
|
||||
<p class="note">
|
||||
Replace <model-name> with a name from
|
||||
<code>GET {{.BaseURL}}/v1/models</code>, which needs your key. Sending the
|
||||
placeholder unchanged is answered with the list of models that are available.
|
||||
</p>
|
||||
<pre>from openai import OpenAI
|
||||
client = OpenAI(base_url="{{.BaseURL}}/v1", api_key=os.environ["LLMGW_API_KEY"])</pre>
|
||||
<p class="note"><code>GET {{.BaseURL}}/v1/models</code> lists what this key may use.
|
||||
|
||||
@@ -18,7 +18,12 @@ client for; only the base URL changes.</p>
|
||||
<pre>curl {{.BaseURL}}/v1/chat/completions \
|
||||
-H "Authorization: Bearer $LLMGW_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "MODEL", "messages": [{"role":"user","content":"hello"}]}'</pre>
|
||||
-d '{"model": "<model-name>", "messages": [{"role":"user","content":"hello"}]}'</pre>
|
||||
<p class="note">
|
||||
Replace <model-name> with a name from
|
||||
<code>GET {{.BaseURL}}/v1/models</code>, which needs your key. Sending the
|
||||
placeholder unchanged is answered with the list of models that are available.
|
||||
</p>
|
||||
|
||||
<pre>from openai import OpenAI
|
||||
client = OpenAI(base_url="{{.BaseURL}}/v1", api_key=os.environ["LLMGW_API_KEY"])</pre>
|
||||
|
||||
Reference in new issue
Block a user