Commit 24739afb by CalciumIon

fix: openai response time

parent 917c1690
...@@ -40,6 +40,7 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon. ...@@ -40,6 +40,7 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
go func() { go func() {
for scanner.Scan() { for scanner.Scan() {
info.SetFirstResponseTime()
ticker.Reset(time.Duration(constant.StreamingTimeout) * time.Second) ticker.Reset(time.Duration(constant.StreamingTimeout) * time.Second)
data := scanner.Text() data := scanner.Text()
if len(data) < 6 { // ignore blank line or wrong format if len(data) < 6 { // ignore blank line or wrong format
......
...@@ -17,6 +17,7 @@ type RelayInfo struct { ...@@ -17,6 +17,7 @@ type RelayInfo struct {
TokenUnlimited bool TokenUnlimited bool
StartTime time.Time StartTime time.Time
FirstResponseTime time.Time FirstResponseTime time.Time
setFirstResponse bool
ApiType int ApiType int
IsStream bool IsStream bool
RelayMode int RelayMode int
...@@ -83,6 +84,13 @@ func (info *RelayInfo) SetIsStream(isStream bool) { ...@@ -83,6 +84,13 @@ func (info *RelayInfo) SetIsStream(isStream bool) {
info.IsStream = isStream info.IsStream = isStream
} }
func (info *RelayInfo) SetFirstResponseTime() {
if !info.setFirstResponse {
info.FirstResponseTime = time.Now()
info.setFirstResponse = true
}
}
type TaskRelayInfo struct { type TaskRelayInfo struct {
ChannelType int ChannelType int
ChannelId int ChannelId int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment