@@ -120,7 +120,7 @@ func extractAllMediaURLs(messages []Message) (imageURLs, videoURLs []string) {
120120 return imageURLs , videoURLs
121121}
122122
123- func makeUpstreamRequest (token string , messages []Message , model string , imageURLs , videoURLs []string ) (* http.Response , string , error ) {
123+ func makeUpstreamRequest (token string , messages []Message , model string , imageURLs , videoURLs []string , hasTools bool ) (* http.Response , string , error ) {
124124 payload , err := DecodeJWTPayload (token )
125125 if err != nil || payload == nil {
126126 return nil , "" , fmt .Errorf ("invalid token" )
@@ -244,8 +244,8 @@ func makeUpstreamRequest(token string, messages []Message, model string, imageUR
244244 "features" : map [string ]interface {}{
245245 "image_generation" : true ,
246246 "web_search" : true ,
247- "auto_web_search" : autoWebSearch ,
248- "preview_mode" : true ,
247+ "auto_web_search" : autoWebSearch && ! hasTools ,
248+ "preview_mode" : false ,
249249 "flags" : []string {},
250250 "enable_thinking" : enableThinking ,
251251 },
@@ -370,10 +370,15 @@ type ThinkingFilter struct {
370370
371371func (f * ThinkingFilter ) ProcessThinking (deltaContent string ) string {
372372 if ! f .hasSeenFirstThinking {
373- f .hasSeenFirstThinking = true
374- if idx := strings .Index (deltaContent , "> " ); idx != - 1 {
375- deltaContent = deltaContent [idx + 2 :]
373+ // 合并缓存和当前内容,查找 "> " 作为思考内容的开始标记
374+ combined := f .buffer + deltaContent
375+ if idx := strings .Index (combined , "> " ); idx != - 1 {
376+ f .hasSeenFirstThinking = true
377+ f .buffer = ""
378+ deltaContent = combined [idx + 2 :]
376379 } else {
380+ // 没找到开始标记,缓存当前内容继续等待
381+ f .buffer = combined
377382 return ""
378383 }
379384 }
@@ -556,7 +561,7 @@ func HandleChatCompletions(w http.ResponseWriter, r *http.Request) {
556561 }
557562 }
558563
559- resp , modelName , err := makeUpstreamRequest (token , messages , req .Model , reqImageURLs , reqVideoURLs )
564+ resp , modelName , err := makeUpstreamRequest (token , messages , req .Model , reqImageURLs , reqVideoURLs , len ( req . Tools ) > 0 )
560565 if err != nil {
561566 LogError ("Upstream request failed (attempt %d): %v" , attempt + 1 , err )
562567 lastError = err .Error ()
@@ -1094,6 +1099,8 @@ func handleNonStreamResponse(w http.ResponseWriter, body io.ReadCloser, completi
10941099
10951100 for scanner .Scan () {
10961101 line := scanner .Text ()
1102+ LogDebug ("[Upstream] %s" , line )
1103+
10971104 if ! strings .HasPrefix (line , "data: " ) {
10981105 continue
10991106 }
@@ -1723,6 +1730,8 @@ func handleNonStreamResponseWithRetry(w http.ResponseWriter, body io.ReadCloser,
17231730
17241731 for scanner .Scan () {
17251732 line := scanner .Text ()
1733+ LogDebug ("[Upstream] %s" , line )
1734+
17261735 if ! strings .HasPrefix (line , "data: " ) {
17271736 continue
17281737 }
0 commit comments