feat: 添加流模式下的SSE保活机制 #945
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"one-api/dto"
|
||||
relayconstant "one-api/relay/constant"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -54,6 +55,7 @@ type RelayInfo struct {
|
||||
StartTime time.Time
|
||||
FirstResponseTime time.Time
|
||||
isFirstResponse bool
|
||||
responseMutex sync.Mutex // Add mutex for protecting concurrent access
|
||||
//SendLastReasoningResponse bool
|
||||
ApiType int
|
||||
IsStream bool
|
||||
@@ -212,12 +214,19 @@ func (info *RelayInfo) SetIsStream(isStream bool) {
|
||||
}
|
||||
|
||||
func (info *RelayInfo) SetFirstResponseTime() {
|
||||
info.responseMutex.Lock()
|
||||
defer info.responseMutex.Unlock()
|
||||
|
||||
if info.isFirstResponse {
|
||||
info.FirstResponseTime = time.Now()
|
||||
info.isFirstResponse = false
|
||||
}
|
||||
}
|
||||
|
||||
func (info *RelayInfo) HasSendResponse() bool {
|
||||
return info.FirstResponseTime.After(info.StartTime)
|
||||
}
|
||||
|
||||
type TaskRelayInfo struct {
|
||||
*RelayInfo
|
||||
Action string
|
||||
|
||||
Reference in New Issue
Block a user