usage: a provider's requests made while it was being added are listed under it, not its host (yyddbds)
yyddbds on Discord added one custom provider, 大灰狼 on dahuilang.best, and the Usage page's provider filter listed it twice: 大灰狼 and dahuilang.best. The Add sheet's Detect and model-list requests run before the provider has an id, so probelog records them under the host asked (probelog.Note: "a provider being added has no id yet"). Those rows are listed on the Requests page, and their provider went into the page's provider list as a provider of its own. Renames now also knows each provider by the hosts of its URLs, and probeChunk reads a probe row through Renames.ProbeOf: a host exactly one provider is on is that provider's id. It is done when the log is read, so rows written before this release are merged too. A host no provider is on (an Add given up) or two providers share stays as it was recorded; a provider id is never taken for a host. Run: - go test -tags nogui ./internal/usage ./internal/usageapi ./internal/probelog ./internal/provider (-skip TestUnreadLoginsWriteErrorsKeepCredentials, #3632) ./internal/gui: ok. - New TestProbesOfAProviderBeingAddedListItOnce: Detect rows written through probelog.Note under dahuilang.best and DaHuiLang.best before provider.Add("大灰狼"), plus a gateway call under its id; providers are [dahuilang other.example shared.example:8443], and the filter on dahuilang has its 3 rows. - gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows. Broken by hand: probeChunk back on Renames.Of fails it with providers [DaHuiLang.best dahuilang dahuilang.best other.example shared.example:8443], the reporter's two entries. Not tried: the reporter's own usage.jsonl; the full go test ./... (other sessions' suites were on this machine).
This commit is contained in:
@@ -168,6 +168,9 @@ type Gave struct {
|
||||
type Renames struct {
|
||||
now map[string]string
|
||||
gave map[string][]gaveTo
|
||||
// hosts are the providers by the host each is on, for magpie's own
|
||||
// requests to a provider being added, which has no id yet (ProbeOf)
|
||||
hosts map[string]string
|
||||
}
|
||||
|
||||
type gaveTo struct {
|
||||
@@ -190,6 +193,20 @@ func (r Renames) Of(id string, at time.Time) string {
|
||||
return id
|
||||
}
|
||||
|
||||
// ProbeOf is Of for one of magpie's own requests (probelog): one sent
|
||||
// while a provider was being added, its Detect or Test before it had an
|
||||
// id, is recorded under its host, and is the provider's on that host now.
|
||||
// yyddbds on Discord: 大灰狼, on dahuilang.best, was listed twice in the
|
||||
// Requests page's providers, once as dahuilang.best for the model lists
|
||||
// asked while adding it. A host two providers are on, or none, stays as
|
||||
// it is.
|
||||
func (r Renames) ProbeOf(id string, at time.Time) string {
|
||||
if to := r.hosts[strings.ToLower(id)]; to != "" {
|
||||
return to
|
||||
}
|
||||
return r.Of(id, at)
|
||||
}
|
||||
|
||||
// Timed is whether the id's calls go to more than one provider by when
|
||||
// they were made, so Of needs each call's time.
|
||||
func (r Renames) Timed(id string) bool { return len(r.gave[id]) > 0 }
|
||||
@@ -261,6 +278,27 @@ func renamesOf(ps []Provider) Renames {
|
||||
for _, gs := range r.gave {
|
||||
slices.SortStableFunc(gs, func(a, b gaveTo) int { return a.Until.Compare(b.Until) })
|
||||
}
|
||||
for _, p := range ps {
|
||||
if p.Hidden {
|
||||
continue
|
||||
}
|
||||
for _, u := range []string{p.Chat, p.Responses, p.Anthropic, p.Gemini, p.Decide} {
|
||||
h := HostOf(u)
|
||||
// a provider's id (one stored by hand can have a dot, b.ai)
|
||||
// is that provider's, never a host's
|
||||
if h == "" || held[h] {
|
||||
continue
|
||||
}
|
||||
if r.hosts == nil {
|
||||
r.hosts = map[string]string{}
|
||||
}
|
||||
if to, ok := r.hosts[h]; ok && to != p.ID {
|
||||
r.hosts[h] = "" // two providers on it: which one is unknown
|
||||
continue
|
||||
}
|
||||
r.hosts[h] = p.ID
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ func clipProbeError(s string) string {
|
||||
// row's is; nil for none.
|
||||
// A provider renamed since is listed by the id it has now (Renames): the
|
||||
// Requests page's provider list named a renamed one twice (cybercaius).
|
||||
// One asked while a provider was being added, under its host, is listed
|
||||
// by the id of the provider on that host (Renames.ProbeOf).
|
||||
func probeChunk(probes []probeRow, since time.Time, renames provider.Renames) *rowChunk {
|
||||
var c *rowChunk
|
||||
for _, p := range probes {
|
||||
@@ -67,7 +69,7 @@ func probeChunk(probes []probeRow, since time.Time, renames provider.Renames) *r
|
||||
c = &rowChunk{}
|
||||
}
|
||||
r := p.Record
|
||||
r.Provider = renames.Of(r.Provider, r.Time)
|
||||
r.Provider = renames.ProbeOf(r.Provider, r.Time)
|
||||
c.add(Row{Record: r, Source: SourceProbe}, "", p.off, false)
|
||||
}
|
||||
if c == nil {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package usage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -80,3 +82,40 @@ func TestRenamedProviderShownOnce(t *testing.T) {
|
||||
t.Fatalf("summary %v", calls)
|
||||
}
|
||||
}
|
||||
|
||||
// yyddbds on Discord: one custom provider, 大灰狼 on dahuilang.best, was
|
||||
// listed twice in the Requests page's providers, 大灰狼 and
|
||||
// dahuilang.best. The model lists asked while it was being added had no
|
||||
// id to go under, so they were recorded under its host, and the page
|
||||
// listed that host as a provider. They are the provider's on that host
|
||||
// now, in a log written before this was fixed too, while a host no
|
||||
// provider is on, or two are, stays as it was recorded.
|
||||
func TestProbesOfAProviderBeingAddedListItOnce(t *testing.T) {
|
||||
reportedHome(t)
|
||||
then := time.Now().Add(-time.Hour)
|
||||
// the Add sheet's Detect, before the provider has an id: written as
|
||||
// probelog writes it, under the host of the address asked
|
||||
adding := probelog.With(context.Background(), probelog.KindDetect, "", "")
|
||||
probelog.Note(adding, "https://dahuilang.best/v1/models", http.MethodGet, then, 200, nil)
|
||||
probelog.Note(adding, "https://other.example/v1/models", http.MethodGet, then, 200, nil)
|
||||
probelog.Note(adding, "https://DaHuiLang.best/v1/chat/completions", http.MethodPost, then, 401, nil)
|
||||
probelog.Note(adding, "https://shared.example:8443/v1/models", http.MethodGet, then, 200, nil)
|
||||
id, err := provider.Add(provider.Provider{Name: "大灰狼", Key: "k", Chat: "https://dahuilang.best/v1", Models: []string{"gpt-9"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, k := range []string{"k1", "k2"} {
|
||||
if err := provider.Save(provider.Provider{ID: "shared-" + k, Name: "Shared " + k, Key: k, Chat: "https://shared.example:8443/v" + string(rune('1'+i)), Models: []string{"m"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Append(Record{Time: then.Add(time.Minute), Agent: "codex", Session: "s1", Provider: id, Model: "gpt-9", Input: 100, Output: 10, Status: 200})
|
||||
|
||||
page := QueryPage(All, Filter{}, 0, 50)
|
||||
if want := []string{id, "other.example", "shared.example:8443"}; !slices.Equal(page.Providers, want) {
|
||||
t.Fatalf("providers %v, want %v", page.Providers, want)
|
||||
}
|
||||
if p := QueryPage(All, Filter{Provider: id}, 0, 50); p.Total != 3 || p.Sum.Calls != 1 {
|
||||
t.Fatalf("%s's rows: total %d, sum %+v", id, p.Total, p.Sum)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user