feat: able to set default test model (#138)

This commit is contained in:
CaIon 2024-04-04 17:28:56 +08:00
parent cdf2087952
commit 660b9b3c99
4 changed files with 20 additions and 4 deletions

View File

@ -27,7 +27,6 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
if channel.Type == common.ChannelTypeMidjourney { if channel.Type == common.ChannelTypeMidjourney {
return errors.New("midjourney channel test is not supported"), nil return errors.New("midjourney channel test is not supported"), nil
} }
common.SysLog(fmt.Sprintf("testing channel %d with model %s", channel.Id, testModel))
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
c.Request = &http.Request{ c.Request = &http.Request{
@ -60,12 +59,16 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
return fmt.Errorf("invalid api type: %d, adaptor is nil", apiType), nil return fmt.Errorf("invalid api type: %d, adaptor is nil", apiType), nil
} }
if testModel == "" { if testModel == "" {
testModel = adaptor.GetModelList()[0] if channel.TestModel != nil && *channel.TestModel != "" {
meta.UpstreamModelName = testModel testModel = *channel.TestModel
} else {
testModel = adaptor.GetModelList()[0]
}
} }
request := buildTestRequest() request := buildTestRequest()
request.Model = testModel request.Model = testModel
meta.UpstreamModelName = testModel meta.UpstreamModelName = testModel
common.SysLog(fmt.Sprintf("testing channel %d with model %s", channel.Id, testModel))
adaptor.Init(meta, *request) adaptor.Init(meta, *request)

View File

@ -163,7 +163,7 @@ func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, mode
if channel.AutoBan != nil && *channel.AutoBan == 0 { if channel.AutoBan != nil && *channel.AutoBan == 0 {
ban = false ban = false
} }
if nil != channel.OpenAIOrganization { if nil != channel.OpenAIOrganization && "" != *channel.OpenAIOrganization {
c.Set("channel_organization", *channel.OpenAIOrganization) c.Set("channel_organization", *channel.OpenAIOrganization)
} }
c.Set("auto_ban", ban) c.Set("auto_ban", ban)

View File

@ -10,6 +10,7 @@ type Channel struct {
Type int `json:"type" gorm:"default:0"` Type int `json:"type" gorm:"default:0"`
Key string `json:"key" gorm:"not null"` Key string `json:"key" gorm:"not null"`
OpenAIOrganization *string `json:"openai_organization"` OpenAIOrganization *string `json:"openai_organization"`
TestModel *string `json:"test_model"`
Status int `json:"status" gorm:"default:1"` Status int `json:"status" gorm:"default:1"`
Name string `json:"name" gorm:"index"` Name string `json:"name" gorm:"index"`
Weight *uint `json:"weight" gorm:"default:0"` Weight *uint `json:"weight" gorm:"default:0"`

View File

@ -63,6 +63,7 @@ const EditChannel = (props) => {
model_mapping: '', model_mapping: '',
models: [], models: [],
auto_ban: 1, auto_ban: 1,
test_model: '',
groups: ['default'], groups: ['default'],
}; };
const [batch, setBatch] = useState(false); const [batch, setBatch] = useState(false);
@ -669,6 +670,17 @@ const EditChannel = (props) => {
}} }}
value={inputs.openai_organization} value={inputs.openai_organization}
/> />
<div style={{ marginTop: 10 }}>
<Typography.Text strong>默认测试模型</Typography.Text>
</div>
<Input
name='test_model'
placeholder='不填则为模型列表第一个'
onChange={(value) => {
handleInputChange('test_model', value);
}}
value={inputs.test_model}
/>
<div style={{ marginTop: 10, display: 'flex' }}> <div style={{ marginTop: 10, display: 'flex' }}>
<Space> <Space>
<Checkbox <Checkbox