Merge 46ac4cf28f
into 923e24534b
This commit is contained in:
commit
13d05ec338
@ -63,7 +63,9 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
|
||||
if channel.Type == common.ChannelTypeAzure {
|
||||
req.Header.Set("api-key", channel.Key)
|
||||
} else {
|
||||
req.Header.Set("Authorization", "Bearer "+channel.Key)
|
||||
apiKey, organization := parseOpenaiConfig(channel.Key)
|
||||
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||
req.Header.Set("OpenAI-Organization", organization)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := httpClient.Do(req)
|
||||
|
@ -101,7 +101,14 @@ func relayAudioHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
|
||||
if err != nil {
|
||||
return errorWrapper(err, "new_request_failed", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
apiKey := c.Request.Header.Get("Authorization")
|
||||
apiKey, organization := parseOpenaiConfig(apiKey)
|
||||
c.Request.Header.Set("Authorization", apiKey)
|
||||
c.Request.Header.Set("OpenAI-Organization", organization)
|
||||
|
||||
req.Header.Set("Authorization", c.Request.Header.Get("Authorization"))
|
||||
req.Header.Set("OpenAI-Organization", c.Request.Header.Get("OpenAI-Organization"))
|
||||
req.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
||||
req.Header.Set("Accept", c.Request.Header.Get("Accept"))
|
||||
|
||||
|
@ -127,7 +127,13 @@ func relayImageHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
|
||||
if err != nil {
|
||||
return errorWrapper(err, "new_request_failed", http.StatusInternalServerError)
|
||||
}
|
||||
apiKey := c.Request.Header.Get("Authorization")
|
||||
apiKey, organization := parseOpenaiConfig(apiKey)
|
||||
c.Request.Header.Set("Authorization", apiKey)
|
||||
c.Request.Header.Set("OpenAI-Organization", organization)
|
||||
|
||||
req.Header.Set("Authorization", c.Request.Header.Get("Authorization"))
|
||||
req.Header.Set("OpenAI-Organization", c.Request.Header.Get("OpenAI-Organization"))
|
||||
|
||||
req.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
||||
req.Header.Set("Accept", c.Request.Header.Get("Accept"))
|
||||
|
@ -11,6 +11,16 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func parseOpenaiConfig(config string) (apiKey string, organization string) {
|
||||
parts := strings.Split(config, "|")
|
||||
if len(parts) < 2 {
|
||||
parts = append(parts, "")
|
||||
}
|
||||
apiKey = parts[0]
|
||||
organization = parts[1]
|
||||
return
|
||||
}
|
||||
|
||||
func openaiStreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*OpenAIErrorWithStatusCode, string) {
|
||||
responseText := ""
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
|
@ -249,6 +249,11 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
||||
requestBody = c.Request.Body
|
||||
}
|
||||
switch apiType {
|
||||
case APITypeOpenAI:
|
||||
apiKey := c.Request.Header.Get("Authorization")
|
||||
apiKey, organization := parseOpenaiConfig(apiKey)
|
||||
c.Request.Header.Set("Authorization", apiKey)
|
||||
c.Request.Header.Set("OpenAI-Organization", organization)
|
||||
case APITypeClaude:
|
||||
claudeRequest := requestOpenAI2Claude(textRequest)
|
||||
jsonStr, err := json.Marshal(claudeRequest)
|
||||
@ -344,6 +349,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
||||
req.Header.Set("api-key", apiKey)
|
||||
} else {
|
||||
req.Header.Set("Authorization", c.Request.Header.Get("Authorization"))
|
||||
req.Header.Set("OpenAI-Organization", c.Request.Header.Get("OpenAI-Organization"))
|
||||
if channelType == common.ChannelTypeOpenRouter {
|
||||
req.Header.Set("HTTP-Referer", "https://github.com/songquanpeng/one-api")
|
||||
req.Header.Set("X-Title", "One API")
|
||||
|
@ -13,6 +13,8 @@ const MODEL_MAPPING_EXAMPLE = {
|
||||
function type2secretPrompt(type) {
|
||||
// inputs.type === 15 ? '按照如下格式输入:APIKey|SecretKey' : (inputs.type === 18 ? '按照如下格式输入:APPID|APISecret|APIKey' : '请输入渠道对应的鉴权密钥')
|
||||
switch (type) {
|
||||
case 1:
|
||||
return '按照如下格式输入:APIKey 或者 APIKey|OpenAI-Organization';
|
||||
case 15:
|
||||
return '按照如下格式输入:APIKey|SecretKey';
|
||||
case 18:
|
||||
|
Loading…
Reference in New Issue
Block a user