remove upstream count

This commit is contained in:
2023-09-28 15:57:30 +08:00
parent f5dc8147e6
commit de1f9c1e94
2 changed files with 5 additions and 17 deletions

13
main.go
View File

@@ -67,9 +67,9 @@ func main() {
if *listMode { if *listMode {
result := make([]OPENAI_UPSTREAM, 0) result := make([]OPENAI_UPSTREAM, 0)
db.Find(&result) db.Find(&result)
fmt.Println("SK\tEndpoint\tSuccess\tFailed\tLast Success Time") fmt.Println("SK\tEndpoint")
for _, upstream := range result { for _, upstream := range result {
fmt.Println(upstream.SK, upstream.Endpoint, upstream.SuccessCount, upstream.FailedCount, upstream.LastCallSuccessTime) fmt.Println(upstream.SK, upstream.Endpoint)
} }
return return
} }
@@ -227,16 +227,9 @@ func main() {
// send notification // send notification
upstreams := []OPENAI_UPSTREAM{} upstreams := []OPENAI_UPSTREAM{}
db.Find(&upstreams) db.Find(&upstreams)
upstreamDescriptions := make([]string, 0) content := fmt.Sprintf("[%s] OpenAI 转发出错 ID: %d... 密钥: [%s] 上游: [%s] 错误: %s",
for _, upstream := range upstreams {
upstreamDescriptions = append(upstreamDescriptions, fmt.Sprintf("ID: %d, %s: %s 成功次数: %d, 失败次数: %d, 最后成功调用: %s",
upstream.ID, upstream.SK, upstream.Endpoint, upstream.SuccessCount, upstream.FailedCount, upstream.LastCallSuccessTime,
))
}
content := fmt.Sprintf("[%s] OpenAI 转发出错 ID: %d... 密钥: [%s] 上游: [%s] 错误: %s\n---\n%s",
c.ClientIP(), c.ClientIP(),
upstream.ID, upstream.SK, upstream.Endpoint, err.Error(), upstream.ID, upstream.SK, upstream.Endpoint, err.Error(),
strings.Join(upstreamDescriptions, "\n"),
) )
go sendMatrixMessage(content) go sendMatrixMessage(content)
if err.Error() != "context canceled" && r.Response.StatusCode != 400 { if err.Error() != "context canceled" && r.Response.StatusCode != 400 {

View File

@@ -1,17 +1,12 @@
package main package main
import ( import (
"time"
"gorm.io/gorm" "gorm.io/gorm"
) )
// one openai upstream contain a pair of key and endpoint // one openai upstream contain a pair of key and endpoint
type OPENAI_UPSTREAM struct { type OPENAI_UPSTREAM struct {
gorm.Model gorm.Model
SK string `gorm:"index:idx_sk_endpoint,unique"` // key SK string `gorm:"index:idx_sk_endpoint,unique"` // key
Endpoint string `gorm:"index:idx_sk_endpoint,unique"` // endpoint Endpoint string `gorm:"index:idx_sk_endpoint,unique"` // endpoint
SuccessCount int64
FailedCount int64
LastCallSuccessTime time.Time
} }