From 83e86b9f8ae0757c416a51ebb4f689c1bb6b146c Mon Sep 17 00:00:00 2001 From: JustSong Date: Sat, 13 May 2023 12:53:57 +0800 Subject: [PATCH] feat: support specific default api version now (#57) --- controller/relay.go | 3 ++- middleware/distributor.go | 3 +++ model/channel.go | 1 + web/src/pages/Channel/EditChannel.js | 13 ++++++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/controller/relay.go b/controller/relay.go index 902852223b..8e1ad985ee 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -95,7 +95,8 @@ func relayHelper(c *gin.Context) error { // https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?pivots=rest-api&tabs=command-line#rest-api query := c.Request.URL.Query() if query.Get("api-version") == "" { - requestURL = fmt.Sprintf("%s?api-version=2023-03-15-preview", requestURL) + apiVersion := c.GetString("api_version") + requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, apiVersion) } baseURL = c.GetString("base_url") task := strings.TrimPrefix(requestURL, "/v1/") diff --git a/middleware/distributor.go b/middleware/distributor.go index 04e9f84d4e..65fcbd3daf 100644 --- a/middleware/distributor.go +++ b/middleware/distributor.go @@ -65,6 +65,9 @@ func Distribute() func(c *gin.Context) { c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", channel.Key)) if channel.Type == common.ChannelTypeCustom || channel.Type == common.ChannelTypeAzure { c.Set("base_url", channel.BaseURL) + if channel.Type == common.ChannelTypeAzure { + c.Set("api_version", channel.Other) + } } c.Next() } diff --git a/model/channel.go b/model/channel.go index ef76bf5455..f653f06881 100644 --- a/model/channel.go +++ b/model/channel.go @@ -15,6 +15,7 @@ type Channel struct { CreatedTime int64 `json:"created_time" gorm:"bigint"` AccessedTime int64 `json:"accessed_time" gorm:"bigint"` BaseURL string `json:"base_url" gorm:"column:base_url"` + Other string `json:"other"` } func GetAllChannels(startIdx int, num int) ([]*Channel, error) { diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index db77ed56ac..1d87ee2587 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -13,7 +13,8 @@ const EditChannel = () => { name: '', type: 1, key: '', - base_url: '' + base_url: '', + other: '' }; const [inputs, setInputs] = useState(originInputs); const handleInputChange = (e, { name, value }) => { @@ -92,6 +93,16 @@ const EditChannel = () => { autoComplete='new-password' /> + + + ) }