Skip to content

Commit b793683

Browse files
committed
Add GPTSCRIPT_PROGRESS_TIME_STEP_MS
1 parent a8c8c79 commit b793683

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

Diff for: pkg/runner/runner.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"os"
89
"sort"
10+
"strconv"
911
"strings"
1012
"sync"
1113
"time"
@@ -668,17 +670,29 @@ func streamProgress(callCtx *engine.Context, monitor Monitor) (chan<- types.Comp
668670

669671
wg := sync.WaitGroup{}
670672
wg.Add(1)
673+
progressTimeStepMs, err := strconv.Atoi(os.Getenv("GPTSCRIPT_PROGRESS_TIME_STEP_MS"))
674+
if err != nil {
675+
// 기본값 250ms를 사용하거나 오류를 처리합니다.
676+
progressTimeStepMs = 250
677+
}
678+
progressTimeStep := time.Duration(progressTimeStepMs) * time.Millisecond
671679
go func() {
672680
defer wg.Done()
681+
lastSentTimeMap := make(map[string]time.Time)
673682
for status := range progress {
674683
if message := status.PartialResponse; message != nil {
675-
monitor.Event(Event{
676-
Time: time.Now(),
677-
CallContext: callCtx.GetCallContext(),
678-
Type: EventTypeCallProgress,
679-
ChatCompletionID: status.CompletionID,
680-
Content: message.String(),
681-
})
684+
now := time.Now()
685+
lastSentTime, ok := lastSentTimeMap[status.CompletionID]
686+
if !ok || now.Sub(lastSentTime) > progressTimeStep {
687+
lastSentTimeMap[status.CompletionID] = now
688+
monitor.Event(Event{
689+
Time: time.Now(),
690+
CallContext: callCtx.GetCallContext(),
691+
Type: EventTypeCallProgress,
692+
ChatCompletionID: status.CompletionID,
693+
Content: message.String(),
694+
})
695+
}
682696
} else {
683697
monitor.Event(Event{
684698
Time: time.Now(),
@@ -690,6 +704,7 @@ func streamProgress(callCtx *engine.Context, monitor Monitor) (chan<- types.Comp
690704
Usage: status.Usage,
691705
ChatResponseCached: status.Cached,
692706
})
707+
delete(lastSentTimeMap, status.CompletionID)
693708
}
694709
}
695710
}()

0 commit comments

Comments
 (0)