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]
|
requestURL := common.ChannelBaseURLs[channel.Type]
|
||||||
if channel.Type == common.ChannelTypeAzure {
|
if channel.Type == common.ChannelTypeAzure {
|
||||||
modelMap := channel.GetModelMapping()
|
modelMap := channel.GetModelMapping()
|
||||||
|
var deployment string
|
||||||
if modelMap[request.Model] != "" {
|
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 {
|
} else {
|
||||||
if baseURL := channel.GetBaseURL(); len(baseURL) > 0 {
|
if baseURL := channel.GetBaseURL(); len(baseURL) > 0 {
|
||||||
requestURL = baseURL
|
requestURL = baseURL
|
||||||
@ -125,6 +128,9 @@ func TestChannel(c *gin.Context) {
|
|||||||
err, _ = testChannel(channel, *testRequest)
|
err, _ = testChannel(channel, *testRequest)
|
||||||
tok := time.Now()
|
tok := time.Now()
|
||||||
milliseconds := tok.Sub(tik).Milliseconds()
|
milliseconds := tok.Sub(tik).Milliseconds()
|
||||||
|
if err != nil {
|
||||||
|
milliseconds = 0
|
||||||
|
}
|
||||||
go channel.UpdateResponseTime(milliseconds)
|
go channel.UpdateResponseTime(milliseconds)
|
||||||
consumedTime := float64(milliseconds) / 1000.0
|
consumedTime := float64(milliseconds) / 1000.0
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -99,7 +99,7 @@ func (channel *Channel) GetBaseURL() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (channel *Channel) GetModelMapping() (m map[string]string) {
|
func (channel *Channel) GetModelMapping() (m map[string]string) {
|
||||||
if channel.ModelMapping == nil {
|
if channel.ModelMapping == nil || *channel.ModelMapping == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := json.Unmarshal([]byte(*channel.ModelMapping), &m)
|
err := json.Unmarshal([]byte(*channel.ModelMapping), &m)
|
||||||
|
@ -219,15 +219,15 @@ const ChannelsTable = () => {
|
|||||||
const res = await API.get(`/api/channel/test/${id}/`);
|
const res = await API.get(`/api/channel/test/${id}/`);
|
||||||
const { success, message, time } = res.data;
|
const { success, message, time } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
|
showInfo(`通道 ${name} 测试成功,耗时 ${time.toFixed(2)} 秒。`);
|
||||||
|
} else {
|
||||||
|
showError(message);
|
||||||
|
}
|
||||||
let newChannels = [...channels];
|
let newChannels = [...channels];
|
||||||
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
||||||
newChannels[realIdx].response_time = time * 1000;
|
newChannels[realIdx].response_time = time * 1000;
|
||||||
newChannels[realIdx].test_time = Date.now() / 1000;
|
newChannels[realIdx].test_time = Date.now() / 1000;
|
||||||
setChannels(newChannels);
|
setChannels(newChannels);
|
||||||
showInfo(`通道 ${name} 测试成功,耗时 ${time.toFixed(2)} 秒。`);
|
|
||||||
} else {
|
|
||||||
showError(message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const testAllChannels = async () => {
|
const testAllChannels = async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user