forked from MartialBE/one-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_error.go
59 lines (51 loc) · 1.4 KB
/
check_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package check_channel
import (
"fmt"
"one-api/types"
"strings"
)
type CheckErrorProcess struct {
ModelName string
}
func CreateCheckErrorProcess(modelName string) *CheckErrorProcess {
return &CheckErrorProcess{
ModelName: modelName,
}
}
func (c *CheckErrorProcess) GetName() string {
return "错误检测"
}
func (c *CheckErrorProcess) GetRequest() *types.ChatCompletionRequest {
return &types.ChatCompletionRequest{
Model: c.ModelName,
Messages: []types.ChatCompletionMessage{
{
Role: types.ChatMessageRoleUser,
Content: "hi",
},
{
Role: "user11",
Content: "hi",
},
},
}
}
func (c *CheckErrorProcess) Check(req *types.ChatCompletionRequest, resp *types.ChatCompletionResponse, openaiErr *types.OpenAIError) []*CheckResult {
checkResults := make([]*CheckResult, 0)
if openaiErr == nil {
checkResults = append(checkResults, &CheckResult{
Name: "响应",
Status: CheckStatusFailed,
Remark: "应该有报错,但是没有报错(不是绝对的,自行判断)",
})
return checkResults
}
// 判断错误中存在多少个 request id:
requestIDCount := strings.Count(openaiErr.Message, "request id:")
checkResults = append(checkResults, &CheckResult{
Name: "错误",
Status: CheckStatusSuccess,
Remark: fmt.Sprintf("错误中存在 %d 个 request id(此指标表示经过多少个类oneapi程序)", requestIDCount),
})
return checkResults
}