5
5
"encoding/json"
6
6
"errors"
7
7
"fmt"
8
+ "os"
8
9
"sort"
10
+ "strconv"
9
11
"strings"
10
12
"sync"
11
13
"time"
@@ -668,17 +670,29 @@ func streamProgress(callCtx *engine.Context, monitor Monitor) (chan<- types.Comp
668
670
669
671
wg := sync.WaitGroup {}
670
672
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
671
679
go func () {
672
680
defer wg .Done ()
681
+ lastSentTimeMap := make (map [string ]time.Time )
673
682
for status := range progress {
674
683
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
+ }
682
696
} else {
683
697
monitor .Event (Event {
684
698
Time : time .Now (),
@@ -690,6 +704,7 @@ func streamProgress(callCtx *engine.Context, monitor Monitor) (chan<- types.Comp
690
704
Usage : status .Usage ,
691
705
ChatResponseCached : status .Cached ,
692
706
})
707
+ delete (lastSentTimeMap , status .CompletionID )
693
708
}
694
709
}
695
710
}()
0 commit comments