Procházet zdrojové kódy

fix: openai response time

CalciumIon před 1 rokem
rodič
revize
220ab412e2

+ 1 - 0
relay/channel/openai/relay-openai.go

@@ -40,6 +40,7 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
 
 	go func() {
 		for scanner.Scan() {
+			info.SetFirstResponseTime()
 			ticker.Reset(time.Duration(constant.StreamingTimeout) * time.Second)
 			data := scanner.Text()
 			if len(data) < 6 { // ignore blank line or wrong format

+ 8 - 0
relay/common/relay_info.go

@@ -17,6 +17,7 @@ type RelayInfo struct {
 	TokenUnlimited       bool
 	StartTime            time.Time
 	FirstResponseTime    time.Time
+	setFirstResponse     bool
 	ApiType              int
 	IsStream             bool
 	RelayMode            int
@@ -83,6 +84,13 @@ func (info *RelayInfo) SetIsStream(isStream bool) {
 	info.IsStream = isStream
 }
 
+func (info *RelayInfo) SetFirstResponseTime() {
+	if !info.setFirstResponse {
+		info.FirstResponseTime = time.Now()
+		info.setFirstResponse = true
+	}
+}
+
 type TaskRelayInfo struct {
 	ChannelType       int
 	ChannelId         int