Header信息删除,proxy地址修改

main
lvxiu_ext 3 years ago
parent fd8cb3c976
commit 57b03b97ac

@ -0,0 +1,7 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}

@ -235,6 +235,7 @@ func embeddings(c *gin.Context) {
log.Printf("开始处理返回逻辑 %d", string(sss)) log.Printf("开始处理返回逻辑 %d", string(sss))
proxy.ModifyResponse = func(resp *http.Response) error { proxy.ModifyResponse = func(resp *http.Response) error {
resp.Header.Set("Openai-Organization", "api2gpt")
var chatResponse ChatResponse var chatResponse ChatResponse
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
@ -321,7 +322,7 @@ func completions(c *gin.Context) {
for k, v := range headers { for k, v := range headers {
c.Writer.Header().Set(k, v[0]) c.Writer.Header().Set(k, v[0])
} }
c.Writer.Header().Set("Openai-Organization", "api2gpt")
for { for {
chunk, err := reader.ReadBytes('\n') chunk, err := reader.ReadBytes('\n')
if err != nil { if err != nil {
@ -364,6 +365,7 @@ func completions(c *gin.Context) {
} else { } else {
// 非流式回应,处理 // 非流式回应,处理
proxy.ModifyResponse = func(resp *http.Response) error { proxy.ModifyResponse = func(resp *http.Response) error {
resp.Header.Set("Openai-Organization", "api2gpt")
var chatResponse ChatResponse var chatResponse ChatResponse
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
@ -462,6 +464,11 @@ func checkKeyMid() gin.HandlerFunc {
} }
// 执行函数 // 执行函数
c.Next() 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 := gin.Default()
r.GET("/v1/models", handleGetModels) //r.GET("/dashboard/billing/credit_grants", checkKeyMid(), balance)
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("/v1/models", handleGetModels)
r.OPTIONS("/v1/*path", handleOptions) r.OPTIONS("/v1/*path", handleOptions)
r.OPTIONS("/proxy/v1/*path", handleOptions)
r.POST("/v1/chat/completions", checkKeyMid(), completions) r.POST("/v1/chat/completions", checkKeyMid(), completions)
r.POST("/proxy/v1/chat/completions", checkKeyMid(), completions)
r.POST("/v1/completions", checkKeyMid(), completions) r.POST("/v1/completions", checkKeyMid(), completions)
r.POST("/proxy/v1/completions", checkKeyMid(), completions)
r.POST("/v1/embeddings", checkKeyMid(), embeddings) r.POST("/v1/embeddings", checkKeyMid(), embeddings)
r.POST("/proxy/v1/embeddings", checkKeyMid(), embeddings)
r.POST("/mock1", mockBalanceInquiry) r.POST("/mock1", mockBalanceInquiry)
r.POST("/mock2", mockBalanceConsumption) r.POST("/mock2", mockBalanceConsumption)

Loading…
Cancel
Save