From 90011aa0c97abea7cc62170a9546b017a968e38b Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Tue, 22 Jul 2025 01:21:56 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(kling):=20send=20both=20`model?= =?UTF-8?q?=5Fname`=20and=20`model`=20fields=20for=20upstream=20compatibil?= =?UTF-8?q?ity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some upstream Kling deployments still expect the legacy `model` key instead of `model_name`. This change adds the `model` field to `requestPayload` and populates it with the same value as `model_name`, ensuring the generated JSON works with both old and new versions. Changes: • Added `Model string "json:\"model,omitempty\""` to `requestPayload` • Set `Model` alongside `ModelName` in `convertToRequestPayload` • Updated comments to clarify compatibility purpose Result: Kling task requests now contain both `model_name` and `model`, removing integration issues with upstreams that only recognize one of the keys. --- middleware/kling_adapter.go | 2 +- relay/channel/task/kling/adaptor.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/middleware/kling_adapter.go b/middleware/kling_adapter.go index 5e6d1fbb..20973c9f 100644 --- a/middleware/kling_adapter.go +++ b/middleware/kling_adapter.go @@ -18,7 +18,7 @@ func KlingRequestConvert() func(c *gin.Context) { return } - // 支持 model_name 和 model 两个字段 + // Support both model_name and model fields model, _ := originalReq["model_name"].(string) if model == "" { model, _ = originalReq["model"].(string) diff --git a/relay/channel/task/kling/adaptor.go b/relay/channel/task/kling/adaptor.go index 4ebb485f..b7b9a5ff 100644 --- a/relay/channel/task/kling/adaptor.go +++ b/relay/channel/task/kling/adaptor.go @@ -44,6 +44,7 @@ type requestPayload struct { Duration string `json:"duration,omitempty"` AspectRatio string `json:"aspect_ratio,omitempty"` ModelName string `json:"model_name,omitempty"` + Model string `json:"model,omitempty"` // Compatible with upstreams that only recognize "model" CfgScale float64 `json:"cfg_scale,omitempty"` } @@ -227,6 +228,7 @@ func (a *TaskAdaptor) convertToRequestPayload(req *SubmitReq) (*requestPayload, Duration: fmt.Sprintf("%d", defaultInt(req.Duration, 5)), AspectRatio: a.getAspectRatio(req.Size), ModelName: req.Model, + Model: req.Model, // Keep consistent with model_name, double writing improves compatibility CfgScale: 0.5, } if r.ModelName == "" {