]> git.giacomolli.uk - onechat/blobdiff - build_run.go
Send stored images to WhatsApp chats
[onechat] / build_run.go
index 9c6b7671cb9b5262121662461ab6b6087919e262..cc12cf26d2d66542bbab2216a96350079e32d422 100644 (file)
@@ -19,12 +19,12 @@ import (
 // buildLineBytes is the most bytes of one line in a build input or usage log.
 const buildLineBytes = 1 << 20
 
 // buildLineBytes is the most bytes of one line in a build input or usage log.
 const buildLineBytes = 1 << 20
 
+// buildWaitTimeout is the longest wait for pending memory builds.
+const buildWaitTimeout = time.Second
+
 // buildQuotaLimit is the largest increase in used quota points of a run.
 const buildQuotaLimit = 15.0
 
 // buildQuotaLimit is the largest increase in used quota points of a run.
 const buildQuotaLimit = 15.0
 
-// buildCallLimit is the most model calls of a run.
-const buildCallLimit = 660
-
 // BuildRun appends messages, builds their tree, and stops the run by the rules
 // of buildStop.
 type BuildRun struct {
 // BuildRun appends messages, builds their tree, and stops the run by the rules
 // of buildStop.
 type BuildRun struct {
@@ -116,7 +116,7 @@ func (r *BuildRun) check() string {
 
 // waitBuilds waits up to one second without leaving a child context open.
 func (r *BuildRun) waitBuilds(ctx context.Context) error {
 
 // waitBuilds waits up to one second without leaving a child context open.
 func (r *BuildRun) waitBuilds(ctx context.Context) error {
-       ctx, cancel := context.WithTimeout(ctx, time.Second)
+       ctx, cancel := context.WithTimeout(ctx, buildWaitTimeout)
        defer cancel()
 
        return r.memory.Wait(ctx)
        defer cancel()
 
        return r.memory.Wait(ctx)
@@ -151,8 +151,10 @@ func buildReadUsage(path string) (records []ModelUsageRecord, 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 scanner.Scan() {
                var record ModelUsageRecord
        for scanner.Scan() {
                var record ModelUsageRecord
+
                err = json.Unmarshal(scanner.Bytes(), &record)
                if err != nil {
                        return nil, fmt.Errorf("decode usage: %w", err)
                err = json.Unmarshal(scanner.Bytes(), &record)
                if err != nil {
                        return nil, fmt.Errorf("decode usage: %w", err)
@@ -176,6 +178,7 @@ func buildReadUsage(path string) (records []ModelUsageRecord, err error) {
 // buildWriteReport writes the result of a build run.
 func buildWriteReport(out io.Writer, appended int, stop string, records []ModelUsageRecord, sizes []int) error {
        var input, cached, output, failed int
 // buildWriteReport writes the result of a build run.
 func buildWriteReport(out io.Writer, appended int, stop string, records []ModelUsageRecord, sizes []int) error {
        var input, cached, output, failed int
+
        for _, record := range records {
                input += record.InputTokens
                cached += record.CachedTokens
        for _, record := range records {
                input += record.InputTokens
                cached += record.CachedTokens
@@ -186,6 +189,7 @@ func buildWriteReport(out io.Writer, appended int, stop string, records []ModelU
        }
 
        var lines []string
        }
 
        var lines []string
+
        if stop != "" {
                lines = append(lines, "stopped early: "+stop)
        }
        if stop != "" {
                lines = append(lines, "stopped early: "+stop)
        }
@@ -288,6 +292,7 @@ func buildTimeText(records []ModelUsageRecord) string {
        }
 
        var events []event
        }
 
        var events []event
+
        seconds := make([]float64, 0, len(records))
        total := 0.0
        for _, record := range records {
        seconds := make([]float64, 0, len(records))
        total := 0.0
        for _, record := range records {
@@ -324,6 +329,7 @@ func buildTimeText(records []ModelUsageRecord) string {
        }
 
        wall := events[len(events)-1].at.Sub(events[0].at).Seconds()
        }
 
        wall := events[len(events)-1].at.Sub(events[0].at).Seconds()
+
        slices.Sort(seconds)
 
        return fmt.Sprintf("time: %.0f s in all, %.1f calls per minute, %.1f s per call (median %.1f, max %.1f), calls at once: at most %d, %.1f on average", wall, 60*float64(len(seconds))/max(wall, 1e-9), total/float64(len(seconds)), seconds[len(seconds)/2], seconds[len(seconds)-1], most, total/max(wall, 1e-9))
        slices.Sort(seconds)
 
        return fmt.Sprintf("time: %.0f s in all, %.1f calls per minute, %.1f s per call (median %.1f, max %.1f), calls at once: at most %d, %.1f on average", wall, 60*float64(len(seconds))/max(wall, 1e-9), total/float64(len(seconds)), seconds[len(seconds)/2], seconds[len(seconds)-1], most, total/max(wall, 1e-9))