Explorar o código

fix: make the 'openai_organization' parameter actually work.

我秦始皇 hai 1 ano
pai
achega
0fb98e44a7
Modificáronse 2 ficheiros con 9 adicións e 0 borrados
  1. 3 0
      middleware/distributor.go
  2. 6 0
      relay/channel/openai/adaptor.go

+ 3 - 0
middleware/distributor.go

@@ -155,6 +155,9 @@ func Distribute() func(c *gin.Context) {
 				if channel.AutoBan != nil && *channel.AutoBan == 0 {
 					ban = false
 				}
+				if nil != channel.OpenAIOrganization {
+					c.Request.Header.Set("OpenAI-Organization", *channel.OpenAIOrganization)
+				}
 				c.Set("auto_ban", ban)
 				c.Set("model_mapping", channel.GetModelMapping())
 				c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", channel.Key))

+ 6 - 0
relay/channel/openai/adaptor.go

@@ -49,6 +49,12 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, info *re
 		req.Header.Set("api-key", info.ApiKey)
 		return nil
 	}
+	if info.ChannelType == common.ChannelTypeOpenAI {
+		orgId := c.GetHeader("OpenAI-Organization")
+		if "" != orgId {
+			req.Header.Set("OpenAI-Organization", orgId)
+		}
+	}
 	req.Header.Set("Authorization", "Bearer "+info.ApiKey)
 	//if info.ChannelType == common.ChannelTypeOpenRouter {
 	//	req.Header.Set("HTTP-Referer", "https://github.com/songquanpeng/one-api")