diff --git a/README.md b/README.md index 23a2577..e05acb5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Azure OpenAI Service Proxy. Convert OpenAI official API request to Azure OpenAI API request. -![aoai-proxy.jpg](docs%2Fassets%2Fimages%2Faoai-proxy.jpg) +![aoai-proxy.jpg](assets%2Fimages%2Faoai-proxy.jpg) ## Get Start @@ -32,7 +32,7 @@ Azure Deployment Names: **Resource Management** > **Deployments** AZURE_OPENAI_MODEL_MAPPER: gpt-3.5-turbo=azure-gpt-35 ```` -![Screenshot of the overview UI for an OpenAI Resource in the Azure portal with the endpoint & access keys location circled in red.](docs/assets/images/endpoint.png) +![Screenshot of the overview UI for an OpenAI Resource in the Azure portal with the endpoint & access keys location circled in red.](assets/images/endpoint.png) API Key: This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`. @@ -74,7 +74,7 @@ curl --location --request POST 'localhost:8080/v1/chat/completions' \ ChatGPT Web: https://github.com/Chanzhaoyu/chatgpt-web -![image-20230324163357406](docs/assets/images/image-20230324163357406.png) +![chatgpt-web](assets/images/chatgpt-web.png) Envs: diff --git a/docs/assets/images/aoai-proxy.jpg b/assets/images/aoai-proxy.jpg similarity index 100% rename from docs/assets/images/aoai-proxy.jpg rename to assets/images/aoai-proxy.jpg diff --git a/docs/assets/images/image-20230324163357406.png b/assets/images/chatgpt-web.png similarity index 100% rename from docs/assets/images/image-20230324163357406.png rename to assets/images/chatgpt-web.png diff --git a/docs/assets/images/endpoint.png b/assets/images/endpoint.png similarity index 100% rename from docs/assets/images/endpoint.png rename to assets/images/endpoint.png diff --git a/cmd/main.go b/cmd/main.go index 249c186..87c6b89 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,13 +2,14 @@ package main import ( "context" - "github.com/gin-gonic/gin" - "github.com/pkg/errors" "log" "net/http" "os" "os/signal" "syscall" + + "github.com/gin-gonic/gin" + "github.com/pkg/errors" ) func main() { diff --git a/cmd/router.go b/cmd/router.go index 727d99a..c34737f 100644 --- a/cmd/router.go +++ b/cmd/router.go @@ -2,7 +2,7 @@ package main import ( "github.com/gin-gonic/gin" - "github.com/stulzq/azure-openai-proxy/azure" + "github.com/stulzq/azure-openai-proxy/pkg/azure" ) // registerRoute registers all routes diff --git a/azure/init.go b/pkg/azure/init.go similarity index 95% rename from azure/init.go rename to pkg/azure/init.go index a414cb2..d15f8a5 100644 --- a/azure/init.go +++ b/pkg/azure/init.go @@ -1,13 +1,12 @@ package azure import ( + "github.com/stulzq/azure-openai-proxy/pkg/constant" "log" "net/url" "os" "regexp" "strings" - - "github.com/stulzq/azure-openai-proxy/constant" ) const ( diff --git a/azure/proxy.go b/pkg/azure/proxy.go similarity index 89% rename from azure/proxy.go rename to pkg/azure/proxy.go index d0b74c7..2c2bf6b 100644 --- a/azure/proxy.go +++ b/pkg/azure/proxy.go @@ -3,9 +3,7 @@ package azure import ( "bytes" "fmt" - "github.com/bytedance/sonic" - "github.com/pkg/errors" - "github.com/stulzq/azure-openai-proxy/util" + "github.com/stulzq/azure-openai-proxy/pkg/util" "io" "log" "net/http" @@ -13,12 +11,14 @@ import ( "path" "strings" + "github.com/bytedance/sonic" "github.com/gin-gonic/gin" + "github.com/pkg/errors" ) // Proxy Azure OpenAI func Proxy(c *gin.Context) { - // improve performance some code from https://github.com/diemus/azure-openai-proxy/blob/main/pkg/azure/proxy.go + // some code from https://github.com/diemus/azure-openai-proxy/blob/main/pkg/azure/proxy.go director := func(req *http.Request) { if req.Body == nil { util.SendError(c, errors.New("request body is empty")) @@ -34,6 +34,7 @@ func Proxy(c *gin.Context) { return } + // get deployment from request deployment, err := model.String() if err != nil { util.SendError(c, errors.Wrap(err, "get deployment error")) @@ -64,7 +65,7 @@ func Proxy(c *gin.Context) { proxy := &httputil.ReverseProxy{Director: director} proxy.ServeHTTP(c.Writer, c.Request) - // https://github.com/Chanzhaoyu/chatgpt-web/issues/831 + // issue: https://github.com/Chanzhaoyu/chatgpt-web/issues/831 if c.Writer.Header().Get("Content-Type") == "text/event-stream" { if _, err := c.Writer.Write([]byte{'\n'}); err != nil { log.Printf("rewrite response error: %v", err) diff --git a/constant/env.go b/pkg/constant/env.go similarity index 100% rename from constant/env.go rename to pkg/constant/env.go diff --git a/util/response_err.go b/pkg/util/response_err.go similarity index 100% rename from util/response_err.go rename to pkg/util/response_err.go diff --git a/util/types.go b/pkg/util/types.go similarity index 100% rename from util/types.go rename to pkg/util/types.go