mirror of
https://github.com/stulzq/azure-openai-proxy.git
synced 2025-12-20 07:44:19 +01:00
feat: code clean
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
Azure OpenAI Service Proxy. Convert OpenAI official API request to Azure OpenAI API request.
|
||||
|
||||

|
||||

|
||||
|
||||
## Get Start
|
||||
|
||||
@@ -32,7 +32,7 @@ Azure Deployment Names: **Resource Management** > **Deployments**
|
||||
AZURE_OPENAI_MODEL_MAPPER: gpt-3.5-turbo=azure-gpt-35
|
||||
````
|
||||
|
||||

|
||||

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

|
||||

|
||||
|
||||
Envs:
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 156 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 (
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user