feat: code clean

This commit is contained in:
Zhiqiang Li
2023-03-30 16:55:15 +08:00
parent 26d230f587
commit 656a7d1f1c
11 changed files with 14 additions and 13 deletions

View File

@@ -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:

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 156 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View File

@@ -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() {

View File

@@ -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

View File

@@ -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 (

View File

@@ -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)