Skip to content

Commit

Permalink
Add GPTSCRIPT_PROGRESS_TIME_STEP_MS
Browse files Browse the repository at this point in the history
  • Loading branch information
bindung committed Jun 21, 2024
1 parent a8c8c79 commit b793683
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -668,17 +670,29 @@ func streamProgress(callCtx *engine.Context, monitor Monitor) (chan<- types.Comp

wg := sync.WaitGroup{}
wg.Add(1)
progressTimeStepMs, err := strconv.Atoi(os.Getenv("GPTSCRIPT_PROGRESS_TIME_STEP_MS"))
if err != nil {
// 기본값 250ms를 사용하거나 오류를 처리합니다.
progressTimeStepMs = 250
}
progressTimeStep := time.Duration(progressTimeStepMs) * time.Millisecond
go func() {
defer wg.Done()
lastSentTimeMap := make(map[string]time.Time)
for status := range progress {
if message := status.PartialResponse; message != nil {
monitor.Event(Event{
Time: time.Now(),
CallContext: callCtx.GetCallContext(),
Type: EventTypeCallProgress,
ChatCompletionID: status.CompletionID,
Content: message.String(),
})
now := time.Now()
lastSentTime, ok := lastSentTimeMap[status.CompletionID]
if !ok || now.Sub(lastSentTime) > progressTimeStep {
lastSentTimeMap[status.CompletionID] = now
monitor.Event(Event{
Time: time.Now(),
CallContext: callCtx.GetCallContext(),
Type: EventTypeCallProgress,
ChatCompletionID: status.CompletionID,
Content: message.String(),
})
}
} else {
monitor.Event(Event{
Time: time.Now(),
Expand All @@ -690,6 +704,7 @@ func streamProgress(callCtx *engine.Context, monitor Monitor) (chan<- types.Comp
Usage: status.Usage,
ChatResponseCached: status.Cached,
})
delete(lastSentTimeMap, status.CompletionID)
}
}
}()
Expand Down

0 comments on commit b793683

Please sign in to comment.