feat: publish sanitized custom.97 source

This commit is contained in:
cneicy committed 2026-10-27 20:43:39 +08:00
1 parent 8e6ed0317b
commit 86c0276156
1022 files changed
+69903 -19207

No files matched your search

+24 -6
View File
@@ -16,7 +16,6 @@ import (
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/middleware"
"github.com/QuantumNous/new-api/model"
benchmark "github.com/QuantumNous/new-api/pkg/model_benchmark"
fingerprint "github.com/QuantumNous/new-api/pkg/model_fingerprint"
"github.com/QuantumNous/new-api/relay"
relaycommon "github.com/QuantumNous/new-api/relay/common"
@@ -42,7 +41,7 @@ func detectionInput(c *gin.Context) (detectionRequest, *model.User, service.Dete
if err := c.ShouldBindJSON(&input); err != nil {
return input, nil, service.DetectionPrice{}, 0, errors.New("invalid detection request")
}
if input.Kind != "benchmark" && input.Kind != "fingerprint" {
if input.Kind != "fingerprint" && input.Kind != "vision" {
return input, nil, service.DetectionPrice{}, 0, errors.New("invalid detection type")
}
user, err := model.GetUserById(c.GetInt("id"), false)
@@ -63,7 +62,7 @@ func EstimateDetection(c *gin.Context) {
return
}
encoded, _ := common.Marshal(price)
calls := benchmark.ProbeCount
calls := 1
if input.Kind == "fingerprint" {
calls = fingerprint.ProbeCount
}
@@ -136,6 +135,7 @@ func GetUserDetection(c *gin.Context) {
}
return
}
run = service.NormalizeVisionRun(run)
var calls []model.DetectionCall
if err := model.DB.Where("run_id = ?", run.ID).Find(&calls).Error; err != nil {
common.ApiError(c, err)
@@ -343,6 +343,14 @@ func DetectionProxy(c *gin.Context) {
}
}
}
if success {
if html := detectionHTML(raw, contentType); html != "" {
if saveErr := model.DB.Model(&model.DetectionRun{}).Where("id = ?", run.ID).Update("html", html).Error; saveErr != nil {
call.Error = "artwork_save_failed"
success = false
}
}
}
if err = model.FinishDetectionCall(call); err != nil {
success = false
}
@@ -456,7 +464,14 @@ func detectionResponseUsage(raw []byte, contentType string) (gjson.Result, bool)
// Apply billing and safety limits AFTER channel parameter overrides. Never let
// an administrative override turn a bounded paid test into unbounded tool work.
func boundDetectionBody(body common.ReplayableBody, request *dto.OpenAIResponsesRequest) (common.ReplayableBody, io.Closer, error) {
raw, err := io.ReadAll(io.LimitReader(body, 128<<10))
limit := int64(128 << 10)
if bytes.Contains(request.Input, []byte(service.VisionImageURL)) {
limit = 4 << 20
}
raw, err := io.ReadAll(io.LimitReader(body, limit+1))
if int64(len(raw)) > limit {
return nil, nil, errors.New("detection request too large")
}
if err != nil {
return nil, nil, err
}
@@ -473,11 +488,14 @@ func boundDetectionBody(body common.ReplayableBody, request *dto.OpenAIResponses
_ = common.Unmarshal(request.Instructions, &instructions)
prepared["instructions"] = instructions
prepared["max_output_tokens"] = *request.MaxOutputTokens
if request.Reasoning != nil {
prepared["reasoning"] = request.Reasoning
}
if *request.MaxOutputTokens == 16384 {
prepared["reasoning"] = map[string]string{"effort": "medium"}
}
if *request.MaxOutputTokens == fingerprint.OutputTokens || *request.MaxOutputTokens == benchmark.OutputTokens {
prepared["reasoning"] = map[string]string{"effort": "low"}
if *request.MaxOutputTokens == fingerprint.OutputTokens {
prepared["reasoning"] = map[string]string{"effort": request.Reasoning.Effort}
delete(prepared, "instructions")
delete(prepared, "temperature")
delete(prepared, "top_p")