record model name
This commit is contained in:
4
main.go
4
main.go
@@ -147,8 +147,8 @@ func main() {
|
|||||||
if db.Create(&record).Error != nil {
|
if db.Create(&record).Error != nil {
|
||||||
log.Println("Error to save record:", record)
|
log.Println("Error to save record:", record)
|
||||||
}
|
}
|
||||||
if record.Status != 200 && record.Response != "context canceled" {
|
if record.Status != 200 {
|
||||||
errMessage := fmt.Sprintf("IP: %s request all upstreams error %d with %s", record.IP, record.Status, record.Response)
|
errMessage := fmt.Sprintf("IP: %s request %s error %d with %s", record.IP, record.Model, record.Status, record.Response)
|
||||||
go sendFeishuMessage(errMessage)
|
go sendFeishuMessage(errMessage)
|
||||||
go sendMatrixMessage(errMessage)
|
go sendMatrixMessage(errMessage)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
|||||||
// record chat message from user
|
// record chat message from user
|
||||||
record.Body = string(inBody)
|
record.Body = string(inBody)
|
||||||
requestBody, requestBodyOK := ParseRequestBody(inBody)
|
requestBody, requestBodyOK := ParseRequestBody(inBody)
|
||||||
|
// record if parse success
|
||||||
|
if requestBodyOK == nil {
|
||||||
|
record.Model = requestBody.Model
|
||||||
|
}
|
||||||
|
|
||||||
// set timeout, default is 5 second
|
// set timeout, default is 5 second
|
||||||
timeout := 5 * time.Second
|
timeout := 5 * time.Second
|
||||||
@@ -95,7 +99,6 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
|||||||
var contentType string
|
var contentType string
|
||||||
proxy.ModifyResponse = func(r *http.Response) error {
|
proxy.ModifyResponse = func(r *http.Response) error {
|
||||||
haveResponse = true
|
haveResponse = true
|
||||||
log.Println("haveResponse set to true")
|
|
||||||
record.Status = r.StatusCode
|
record.Status = r.StatusCode
|
||||||
if !shouldResponse && r.StatusCode != 200 {
|
if !shouldResponse && r.StatusCode != 200 {
|
||||||
log.Println("upstream return not 200 and should not response", r.StatusCode)
|
log.Println("upstream return not 200 and should not response", r.StatusCode)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type Record struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
IP string
|
IP string
|
||||||
Body string `gorm:"serializer:json"`
|
Body string `gorm:"serializer:json"`
|
||||||
|
Model string
|
||||||
Response string
|
Response string
|
||||||
ElapsedTime time.Duration
|
ElapsedTime time.Duration
|
||||||
Status int
|
Status int
|
||||||
|
|||||||
Reference in New Issue
Block a user