Skip to content

Commit

Permalink
feat: support specific default api version now (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 13, 2023
1 parent 74c1ba7 commit 83e86b9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion controller/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down
3 changes: 3 additions & 0 deletions middleware/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions model/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion web/src/pages/Channel/EditChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -92,6 +93,16 @@ const EditChannel = () => {
autoComplete='new-password'
/>
</Form.Field>
<Form.Field>
<Form.Input
label='默认 API 版本'
name='other'
placeholder={'请输入默认 API 版本,例如:2023-03-15-preview,该配置可以被实际的请求查询参数所覆盖'}
onChange={handleInputChange}
value={inputs.other}
autoComplete='new-password'
/>
</Form.Field>
</>
)
}
Expand Down

0 comments on commit 83e86b9

Please sign in to comment.