Skip to content

Commit

Permalink
fix azure streaming difference from openai
Browse files Browse the repository at this point in the history
  • Loading branch information
diemus committed Mar 25, 2023
1 parent 44d4a32 commit 3d736f0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 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 @@ -87,7 +88,15 @@ func NewOpenAIReverseProxy() *httputil.ReverseProxy {

log.Printf("proxying request [%s] %s -> %s", model, originURL, req.URL.String())
}
return &httputil.ReverseProxy{Director: director}
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
azureBugFixSuffix := strings.NewReader("\n")
response.Body = ioutil.NopCloser(io.MultiReader(response.Body, azureBugFixSuffix))
}
return nil
}}
}

func GetDeploymentByModel(model string) string {
Expand Down

0 comments on commit 3d736f0

Please sign in to comment.