diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f980ab9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/main.go b/main.go index bdc1a65..ed518b6 100644 --- a/main.go +++ b/main.go @@ -235,6 +235,7 @@ func embeddings(c *gin.Context) { log.Printf("开始处理返回逻辑 %d", string(sss)) proxy.ModifyResponse = func(resp *http.Response) error { + resp.Header.Set("Openai-Organization", "api2gpt") var chatResponse ChatResponse body, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -321,7 +322,7 @@ func completions(c *gin.Context) { for k, v := range headers { c.Writer.Header().Set(k, v[0]) } - + c.Writer.Header().Set("Openai-Organization", "api2gpt") for { chunk, err := reader.ReadBytes('\n') if err != nil { @@ -364,6 +365,7 @@ func completions(c *gin.Context) { } else { // 非流式回应,处理 proxy.ModifyResponse = func(resp *http.Response) error { + resp.Header.Set("Openai-Organization", "api2gpt") var chatResponse ChatResponse body, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -462,6 +464,11 @@ func checkKeyMid() gin.HandlerFunc { } // 执行函数 c.Next() + var a = c.Writer.Header().Get("Openai-Organization") + if a != "" { + c.Writer.Header().Set("Openai-Organization", "12321321") + } + } } @@ -480,23 +487,13 @@ func main() { r := gin.Default() - r.GET("/v1/models", handleGetModels) - r.GET("/proxy/v1/models", handleGetModels) - - r.GET("/dashboard/billing/credit_grants", checkKeyMid(), balance) - r.GET("/proxy/dashboard/billing/credit_grants", checkKeyMid(), balance) + //r.GET("/dashboard/billing/credit_grants", checkKeyMid(), balance) + r.GET("/v1/models", handleGetModels) r.OPTIONS("/v1/*path", handleOptions) - r.OPTIONS("/proxy/v1/*path", handleOptions) - r.POST("/v1/chat/completions", checkKeyMid(), completions) - r.POST("/proxy/v1/chat/completions", checkKeyMid(), completions) - r.POST("/v1/completions", checkKeyMid(), completions) - r.POST("/proxy/v1/completions", checkKeyMid(), completions) - r.POST("/v1/embeddings", checkKeyMid(), embeddings) - r.POST("/proxy/v1/embeddings", checkKeyMid(), embeddings) r.POST("/mock1", mockBalanceInquiry) r.POST("/mock2", mockBalanceConsumption)