Trained adapters published, private to their owners like the knowledge bases they come from
An adapter now has an owner (org, team, project, user or key): only callers there see it, and to anyone else it is a model that does not exist, absent from /v1/models too. A training job's owner defaults to the one collection its pairs come from, must be able to read every collection they come from, and pairs from a knowledge base are never made public. ctl train publish keeps the GGUF or PEFT files on the mirror, which accepts uploads now, and sets the owned adapter after the usual architecture check. The knowledge bases' cache_salt follows the collections searched rather than the organization, so two teams of one organization no longer share cached passages. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
964b35ae65
commit
85025dfb03
29 files changed
+1049
-84
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -37,6 +38,7 @@ func (a *API) Handler() http.Handler {
|
||||
mux.HandleFunc("POST /v1/models", a.fetch)
|
||||
mux.HandleFunc("GET /v1/models/{model}/{version}", a.status)
|
||||
mux.HandleFunc("DELETE /v1/models/{model}/{version}", a.remove)
|
||||
mux.HandleFunc("PUT /v1/models/{model}/{version}/{file}", a.upload)
|
||||
mux.HandleFunc("GET /v1/health", a.health)
|
||||
return mux
|
||||
}
|
||||
@@ -199,3 +201,59 @@ func LastPathElement(u string) string {
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
||||
// maxUpload bounds a file sent to the mirror rather than fetched by it.
|
||||
const maxUpload = 8 << 30
|
||||
|
||||
// upload keeps a file the caller sends — an adapter a node trained, which
|
||||
// is on no registry to fetch from — with the same discipline as an import:
|
||||
// its checksum and source beside it, and an existing version never
|
||||
// replaced. X-Llmgw-Source says where it came from.
|
||||
func (a *API) upload(w http.ResponseWriter, r *http.Request) {
|
||||
e := Entry{Model: r.PathValue("model"), Version: r.PathValue("version"), File: r.PathValue("file")}
|
||||
for _, n := range []string{e.Model, e.Version, e.File} {
|
||||
if err := ValidName(n); err != nil {
|
||||
fail(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(e.Path(a.m.root)); err == nil {
|
||||
fail(w, http.StatusConflict, fmt.Errorf("%s/%s/%s: %w", e.Model, e.Version, e.File, ErrExists))
|
||||
return
|
||||
}
|
||||
tmp, err := os.CreateTemp(a.m.root, ".upload-*")
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(tmp.Name())
|
||||
n, err := io.Copy(tmp, http.MaxBytesReader(w, r.Body, maxUpload))
|
||||
if cerr := tmp.Close(); err == nil {
|
||||
err = cerr
|
||||
}
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadRequest, fmt.Errorf("receiving the file: %w", err))
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
fail(w, http.StatusBadRequest, errors.New("the file is empty"))
|
||||
return
|
||||
}
|
||||
source := strings.TrimSpace(r.Header.Get("X-Llmgw-Source"))
|
||||
if source == "" {
|
||||
source = "uploaded"
|
||||
}
|
||||
added, err := Import(r.Context(), a.m.root, tmp.Name(), e, "", source, nil)
|
||||
switch {
|
||||
case errors.Is(err, ErrExists):
|
||||
fail(w, http.StatusConflict, err)
|
||||
return
|
||||
case err != nil:
|
||||
fail(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusCreated, FetchResponse{
|
||||
Status: Status{Model: e.Model, Version: e.Version, File: e.File, State: Present, BytesDone: added.Entry.Bytes, BytesTotal: added.Entry.Bytes},
|
||||
URL: e.URL(a.base),
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user