]> git.giacomolli.uk - onechat/blobdiff - probe.go
Order model and chat declarations
[onechat] / probe.go
index 69d81d1024da77b2018555ac11c1819f468b25de..a1ee38d17d6e43ff94c994e0c3a8f61d3b86f627 100644 (file)
--- a/probe.go
+++ b/probe.go
@@ -7,7 +7,7 @@ import (
        "errors"
        "fmt"
        "io"
        "errors"
        "fmt"
        "io"
-       "log"
+       "log/slog"
        "os"
        "path/filepath"
        "strconv"
        "os"
        "path/filepath"
        "strconv"
@@ -18,13 +18,38 @@ const (
        // probeName is the agent name of a probe run. The cache key comes from
        // it.
        probeName = "Probe"
        // probeName is the agent name of a probe run. The cache key comes from
        // it.
        probeName = "Probe"
+
+       // probeCallLimit is the most model calls of a probe run.
+       probeCallLimit = 660
 )
 
 )
 
+// ProbeSlotSummarizer lets at most cap(slots) builds call inner at once. A
+// build past the limit waits for a slot.
+type ProbeSlotSummarizer struct {
+       inner Summarizer
+       slots chan struct{}
+}
+
+// Summarize waits for a slot and builds the node with inner.
+func (s ProbeSlotSummarizer) Summarize(ctx context.Context, task Task) (string, error) {
+       select {
+       case s.slots <- struct{}{}:
+       case <-ctx.Done():
+               return "", ctx.Err()
+       }
+
+       defer func() {
+               <-s.slots
+       }()
+
+       return s.inner.Summarize(ctx, task)
+}
+
 // probe runs "onechat probe LOG COUNT [BUILDS]". It appends the first COUNT
 // messages of LOG, one JSON object {kind, text} per line, to a new chat in
 // probe/ in the data directory, and builds its tree with the real compactor.
 // Before each user message it waits for the builds, as a turn does. It stops at
 // probe runs "onechat probe LOG COUNT [BUILDS]". It appends the first COUNT
 // messages of LOG, one JSON object {kind, text} per line, to a new chat in
 // probe/ in the data directory, and builds its tree with the real compactor.
 // Before each user message it waits for the builds, as a turn does. It stops at
-// the first failed call, after buildCallLimit calls, or when the used percent
+// the first failed call, after probeCallLimit calls, or when the used percent
 // of a quota window grows by more than buildQuotaLimit points. At the end it
 // reports the calls, the time per call, the calls at once, the cached share,
 // the quota, the retries, and the line sizes. BUILDS, from 1 to buildMax,
 // of a quota window grows by more than buildQuotaLimit points. At the end it
 // reports the calls, the time per call, the calls at once, the cached share,
 // the quota, the retries, and the line sizes. BUILDS, from 1 to buildMax,
@@ -97,15 +122,16 @@ func probe(ctx context.Context, args []string, out io.Writer) (err error) {
 
        usagePath := filepath.Join(root, "usage.jsonl")
        client := newModelClient(address, auth, "onechat-"+probeName, usagePath)
 
        usagePath := filepath.Join(root, "usage.jsonl")
        client := newModelClient(address, auth, "onechat-"+probeName, usagePath)
-       client.LimitCalls(buildCallLimit)
+       client.LimitCalls(probeCallLimit)
+
        summarizer := ProbeSlotSummarizer{
        summarizer := ProbeSlotSummarizer{
-               inner: newCompactor(client, probePrompt, config.Compactor),
+               inner: newCompactor(client, probePrompt, config.Compactor, promptTools(), &ImageStore{dir: filepath.Join(dir, imageDirName)}),
                slots: make(chan struct{}, builds),
        }
 
        // The report of the probe counts the failed calls, so the lines of the
        // failed builds are not needed.
                slots: make(chan struct{}, builds),
        }
 
        // The report of the probe counts the failed calls, so the lines of the
        // failed builds are not needed.
-       memory, err := openMemory(ctx, root, time.Now, summarizer, log.New(io.Discard, "", 0))
+       memory, err := openMemory(ctx, root, time.Now, summarizer, slog.New(slog.DiscardHandler))
        if err != nil {
                return fmt.Errorf("open probe memory: %w", err)
        }
        if err != nil {
                return fmt.Errorf("open probe memory: %w", err)
        }
@@ -141,28 +167,6 @@ func probe(ctx context.Context, args []string, out io.Writer) (err error) {
        return nil
 }
 
        return nil
 }
 
-// ProbeSlotSummarizer lets at most cap(slots) builds call inner at once. A
-// build past the limit waits for a slot.
-type ProbeSlotSummarizer struct {
-       inner Summarizer
-       slots chan struct{}
-}
-
-// Summarize waits for a slot and builds the node with inner.
-func (s ProbeSlotSummarizer) Summarize(ctx context.Context, task Task) (string, error) {
-       select {
-       case s.slots <- struct{}{}:
-       case <-ctx.Done():
-               return "", ctx.Err()
-       }
-
-       defer func() {
-               <-s.slots
-       }()
-
-       return s.inner.Summarize(ctx, task)
-}
-
 // probeReadLog reads the first count messages of the probe log at path. Source
 // dates are ignored because a probe uses its own clock.
 func probeReadLog(path string, count int) (entries []DatedMessage, err error) {
 // probeReadLog reads the first count messages of the probe log at path. Source
 // dates are ignored because a probe uses its own clock.
 func probeReadLog(path string, count int) (entries []DatedMessage, err error) {
@@ -180,8 +184,10 @@ func probeReadLog(path string, count int) (entries []DatedMessage, err error) {
 
        scanner := bufio.NewScanner(file)
        scanner.Buffer(make([]byte, 64*1024), buildLineBytes)
 
        scanner := bufio.NewScanner(file)
        scanner.Buffer(make([]byte, 64*1024), buildLineBytes)
+
        for len(entries) < count && scanner.Scan() {
                var entry DatedMessage
        for len(entries) < count && scanner.Scan() {
                var entry DatedMessage
+
                err = json.Unmarshal(scanner.Bytes(), &entry)
                if err != nil {
                        return nil, fmt.Errorf("probe log line %d: %w", len(entries)+1, err)
                err = json.Unmarshal(scanner.Bytes(), &entry)
                if err != nil {
                        return nil, fmt.Errorf("probe log line %d: %w", len(entries)+1, err)