Skip to content

Commit

Permalink
Revert "remove unuseful code"
Browse files Browse the repository at this point in the history
This reverts commit 63f7104.
  • Loading branch information
diemus committed Mar 27, 2023
1 parent 63f7104 commit 4c9854b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pkg/azure/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"github.com/tidwall/gjson"
"io"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -88,18 +89,18 @@ func NewOpenAIReverseProxy() *httputil.ReverseProxy {
log.Printf("proxying request [%s] %s -> %s", model, originURL, req.URL.String())
}
return &httputil.ReverseProxy{Director: director, ModifyResponse: func(response *http.Response) error {
//if response.Header.Get("Content-Type") == "text/event-stream" {
// //BUGFIX: try to fix the difference between azure and openai, Azure's response is missing a \n
// //see https://github.com/Chanzhaoyu/chatgpt-web/issues/831
// body := response.Body
// r, w := io.Pipe()
// response.Body = r
// go func() {
// defer w.Close()
// io.Copy(w, body)
// fmt.Fprint(w, "\n")
// }()
//}
if response.Header.Get("Content-Type") == "text/event-stream" {
//BUGFIX: try to fix the difference between azure and openai, Azure's response is missing a \n
//see https://github.com/Chanzhaoyu/chatgpt-web/issues/831
body := response.Body
r, w := io.Pipe()
response.Body = r
go func() {
defer w.Close()
io.Copy(w, body)
fmt.Fprint(w, "\n")
}()
}
return nil
}}
}
Expand All @@ -111,3 +112,6 @@ func GetDeploymentByModel(model string) string {
// This is a fallback strategy in case the model is not found in the AzureOpenAIModelMapper
return fallbackModelMapper.ReplaceAllString(model, "")
}

type Copier struct {
}

0 comments on commit 4c9854b

Please sign in to comment.