fix: fix channel test & clear response_time on test failed
This commit is contained in:
parent
0bcb91e5ef
commit
8ffc76084c
@ -45,10 +45,13 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
|
||||
requestURL := common.ChannelBaseURLs[channel.Type]
|
||||
if channel.Type == common.ChannelTypeAzure {
|
||||
modelMap := channel.GetModelMapping()
|
||||
var deployment string
|
||||
if modelMap[request.Model] != "" {
|
||||
request.Model = modelMap[request.Model]
|
||||
deployment = modelMap[request.Model]
|
||||
} else {
|
||||
deployment = model.ModelToDeployment(request.Model)
|
||||
}
|
||||
requestURL = getFullRequestURL(channel.GetBaseURL(), fmt.Sprintf("/openai/deployments/%s/chat/completions?api-version=%s", request.Model, channel.Other), channel.Type)
|
||||
requestURL = getFullRequestURL(channel.GetBaseURL(), fmt.Sprintf("/openai/deployments/%s/chat/completions?api-version=%s", deployment, channel.Other), channel.Type)
|
||||
} else {
|
||||
if baseURL := channel.GetBaseURL(); len(baseURL) > 0 {
|
||||
requestURL = baseURL
|
||||
@ -125,6 +128,9 @@ func TestChannel(c *gin.Context) {
|
||||
err, _ = testChannel(channel, *testRequest)
|
||||
tok := time.Now()
|
||||
milliseconds := tok.Sub(tik).Milliseconds()
|
||||
if err != nil {
|
||||
milliseconds = 0
|
||||
}
|
||||
go channel.UpdateResponseTime(milliseconds)
|
||||
consumedTime := float64(milliseconds) / 1000.0
|
||||
if err != nil {
|
||||
|
@ -99,7 +99,7 @@ func (channel *Channel) GetBaseURL() string {
|
||||
}
|
||||
|
||||
func (channel *Channel) GetModelMapping() (m map[string]string) {
|
||||
if channel.ModelMapping == nil {
|
||||
if channel.ModelMapping == nil || *channel.ModelMapping == "" {
|
||||
return
|
||||
}
|
||||
err := json.Unmarshal([]byte(*channel.ModelMapping), &m)
|
||||
|
@ -219,15 +219,15 @@ const ChannelsTable = () => {
|
||||
const res = await API.get(`/api/channel/test/${id}/`);
|
||||
const { success, message, time } = res.data;
|
||||
if (success) {
|
||||
let newChannels = [...channels];
|
||||
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
||||
newChannels[realIdx].response_time = time * 1000;
|
||||
newChannels[realIdx].test_time = Date.now() / 1000;
|
||||
setChannels(newChannels);
|
||||
showInfo(`通道 ${name} 测试成功,耗时 ${time.toFixed(2)} 秒。`);
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
let newChannels = [...channels];
|
||||
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
||||
newChannels[realIdx].response_time = time * 1000;
|
||||
newChannels[realIdx].test_time = Date.now() / 1000;
|
||||
setChannels(newChannels);
|
||||
};
|
||||
|
||||
const testAllChannels = async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user