diff --git a/controller/model.go b/controller/model.go index 6cb530db..b2a11295 100644 --- a/controller/model.go +++ b/controller/model.go @@ -244,6 +244,7 @@ func init() { Parent: nil, }, { + Id: "gpt-4-vision-preview", Object: "model", Created: 1699593571, diff --git a/controller/relay-text.go b/controller/relay-text.go index 64338545..361f8221 100644 --- a/controller/relay-text.go +++ b/controller/relay-text.go @@ -48,6 +48,7 @@ func init() { } func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { + channelType := c.GetInt("channel") channelId := c.GetInt("channel_id") tokenId := c.GetInt("token_id") @@ -130,6 +131,11 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { if c.GetString("base_url") != "" { baseURL = c.GetString("base_url") } + Organization := "" + if c.GetString("openai_organization") != "" { + Organization = c.GetString("openai_organization") + } + fullRequestURL := getFullRequestURL(baseURL, requestURL, channelType) switch apiType { case APITypeOpenAI: @@ -368,6 +374,9 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { req.Header.Set("HTTP-Referer", "https://github.com/songquanpeng/one-api") req.Header.Set("X-Title", "One API") } + if Organization != "" { + req.Header.Set("OpenAI-Organization", Organization) + } } case APITypeClaude: req.Header.Set("x-api-key", apiKey) diff --git a/middleware/distributor.go b/middleware/distributor.go index 81338130..42310b0e 100644 --- a/middleware/distributor.go +++ b/middleware/distributor.go @@ -82,6 +82,7 @@ func Distribute() func(c *gin.Context) { c.Set("model_mapping", channel.GetModelMapping()) c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", channel.Key)) c.Set("base_url", channel.GetBaseURL()) + c.Set("openai_organization", channel.Organization) switch channel.Type { case common.ChannelTypeAzure: c.Set("api_version", channel.Other) diff --git a/model/channel.go b/model/channel.go index 7e7b42e6..980842ec 100644 --- a/model/channel.go +++ b/model/channel.go @@ -1,8 +1,9 @@ package model import ( - "gorm.io/gorm" "one-api/common" + + "gorm.io/gorm" ) type Channel struct { @@ -24,6 +25,7 @@ type Channel struct { UsedQuota int64 `json:"used_quota" gorm:"bigint;default:0"` ModelMapping *string `json:"model_mapping" gorm:"type:varchar(1024);default:''"` Priority *int64 `json:"priority" gorm:"bigint;default:0"` + Organization string `json:"openai_organization" gorm:"column:openai_organization;default:''"` } func GetAllChannels(startIdx int, num int, selectAll bool) ([]*Channel, error) { diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 0d4e114d..1dece8cf 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -1,8 +1,8 @@ import React, { useEffect, useState } from 'react'; -import { Button, Form, Header, Input, Message, Segment } from 'semantic-ui-react'; import { useNavigate, useParams } from 'react-router-dom'; -import { API, showError, showInfo, showSuccess, verifyJSON } from '../../helpers'; +import { Button, Form, Header, Input, Message, Segment } from 'semantic-ui-react'; import { CHANNEL_OPTIONS } from '../../constants'; +import { API, showError, showInfo, showSuccess, verifyJSON } from '../../helpers'; const MODEL_MAPPING_EXAMPLE = { 'gpt-3.5-turbo-0301': 'gpt-3.5-turbo', @@ -41,6 +41,7 @@ const EditChannel = () => { type: 1, key: '', base_url: '', + openai_organization: '', other: '', model_mapping: '', models: [], @@ -325,6 +326,20 @@ const EditChannel = () => { options={groupOptions} /> + { + inputs.type === 1 && ( + + + + ) + } { inputs.type === 18 && (