- return nil, fmt.Errorf("read usage file: %w", err)
- }
-
- return records, nil
-}
-
-// usedPercents returns the used percent of each quota window of record, by
-// header name.
-func usedPercents(record usageRecord) map[string]float64 {
- used := make(map[string]float64)
- for name, value := range record.Quota {
- if !strings.HasSuffix(name, "-used-percent") {
- continue
- }
-
- percent, err := strconv.ParseFloat(value, 64)
- if err == nil {
- used[name] = percent
- }
- }
-
- return used
-}
-
-// writeProbeReport writes the result of a probe run.
-func writeProbeReport(out io.Writer, appended int, stop string, records []usageRecord, sizes []int) error {
- var input, cached, output, failed int
- for _, record := range records {
- input += record.InputTokens
- cached += record.CachedTokens
- output += record.OutputTokens
- if record.Error != "" {
- failed++
- }
- }
-
- var lines []string
- if stop != "" {
- lines = append(lines, "stopped early: "+stop)
- }
-
- lines = append(lines,
- fmt.Sprintf("messages: %d", appended),
- fmt.Sprintf("calls: %d (%d failed), %.2f per message", len(records), failed, ratio(len(records), appended)),
- fmt.Sprintf("model lines: %d, retries: %d", len(sizes), len(records)-failed-len(sizes)),
- fmt.Sprintf("tokens: %d input, %d cached (%.1f%%), %d output", input, cached, 100*ratio(cached, input), output),
- )
-
- if len(sizes) > 0 {
- lines = append(lines, sizeText(sizes))
- }
-
- if len(records) > 0 {
- lines = append(lines,
- "quota at the first call: "+quotaText(records[0]),
- "quota at the last call: "+quotaText(records[len(records)-1]),
- )
- }
-
- _, err := io.WriteString(out, strings.Join(lines, "\n")+"\n")
-
- return err
-}
-
-// sizeText describes the sizes of the model lines.
-func sizeText(sizes []int) string {
- sorted := slices.Sorted(slices.Values(sizes))
- total, over := 0, 0
- for _, size := range sorted {
- total += size
- if size > nodeBytes {
- over++
- }