Skip to content

Commit

Permalink
fix options request
Browse files Browse the repository at this point in the history
  • Loading branch information
diemus committed Apr 1, 2023
1 parent 1e4c90e commit 26ee79f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/diemus/azure-openai-proxy/pkg/openai"
"github.com/gin-gonic/gin"
"log"
"net/http"
"os"
)

Expand All @@ -29,6 +30,15 @@ func main() {
r := gin.Default()
r.Any("*path", func(c *gin.Context) {
if ProxyMode == "azure" {
// BUGFIX: fix options request, see https://github.com/diemus/azure-openai-proxy/issues/1
if c.Request.Method == http.MethodOptions {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
c.Status(200)
return
}

server := azure.NewOpenAIReverseProxy()
server.ServeHTTP(c.Writer, c.Request)
//BUGFIX: try to fix the difference between azure and openai
Expand Down
1 change: 1 addition & 0 deletions pkg/azure/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func init() {
}
if v := os.Getenv("AZURE_OPENAI_TOKEN"); v != "" {
AzureOpenAIToken = v
log.Printf("loading azure api token from env")
}

log.Printf("loading azure api endpoint: %s", AzureOpenAIEndpoint)
Expand Down

0 comments on commit 26ee79f

Please sign in to comment.