|
@@ -3,6 +3,7 @@ package openai
|
|
|
import (
|
|
import (
|
|
|
"bufio"
|
|
"bufio"
|
|
|
"bytes"
|
|
"bytes"
|
|
|
|
|
+ "context"
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"io"
|
|
"io"
|
|
@@ -120,13 +121,16 @@ func OaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
|
|
|
ticker := time.NewTicker(streamingTimeout)
|
|
ticker := time.NewTicker(streamingTimeout)
|
|
|
defer ticker.Stop()
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
- stopChan := make(chan bool)
|
|
|
|
|
|
|
+ stopChan := make(chan bool, 2)
|
|
|
defer close(stopChan)
|
|
defer close(stopChan)
|
|
|
var (
|
|
var (
|
|
|
lastStreamData string
|
|
lastStreamData string
|
|
|
mu sync.Mutex
|
|
mu sync.Mutex
|
|
|
)
|
|
)
|
|
|
- gopool.Go(func() {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ ctx := context.WithValue(context.Background(), "stop_chan", stopChan)
|
|
|
|
|
+
|
|
|
|
|
+ common.CtxGo(ctx, func() {
|
|
|
for scanner.Scan() {
|
|
for scanner.Scan() {
|
|
|
//info.SetFirstResponseTime()
|
|
//info.SetFirstResponseTime()
|
|
|
ticker.Reset(time.Duration(constant.StreamingTimeout) * time.Second)
|
|
ticker.Reset(time.Duration(constant.StreamingTimeout) * time.Second)
|