Skip to content

feat: add kling video text2Video when image is empty - #1399

Merged
creamlike1024 merged 1 commit into
QuantumNous:alphafrom
feitianbubu:pr/fix-kling-text2image
Aug 29, 2025
Merged

creamlike1024 merged 1 commit into
QuantumNous:alphafrom
feitianbubu:pr/fix-kling-text2image

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jul 19, 2025 •

Copy link
Copy Markdown
Member

修复可灵视频参数没有图片时报错问题
当首图和尾图都为空时改调文生图接口

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of requests without image fields to ensure correct action type is set automatically.

@coderabbitai

coderabbitai Bot commented Jul 19, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A conditional check was added to the BuildRequestBody method in the TaskAdaptor struct. If both Image and ImageTail fields in the request payload are empty, the Gin context key "action" is set to TaskActionTextGenerate before marshalling the payload to JSON, affecting the request's action type.

Changes

File(s) Change Summary
relay/channel/task/kling/adaptor.go Added logic in BuildRequestBody to set Gin context "action" to TaskActionTextGenerate when both Image and ImageTail are empty.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TaskAdaptor
    participant GinContext

    Client->>TaskAdaptor: BuildRequestBody(request, ctx)
    TaskAdaptor->>TaskAdaptor: Convert request to requestPayload
    TaskAdaptor->>TaskAdaptor: Check if Image and ImageTail are empty
    alt Both are empty
        TaskAdaptor->>GinContext: Set "action" = TaskActionTextGenerate
    end
    TaskAdaptor->>TaskAdaptor: Marshal payload to JSON
    TaskAdaptor-->>Client: Return marshalled payload
Loading

Possibly related PRs

  • fix: KlingText2VideoRequest image and model_name #1349: Modifies "action" setting logic in KlingRequestConvert middleware based on the presence or absence of the "image" key, similar to the logic introduced in this PR for distinguishing text-to-video and image-based requests.

Poem

A hop and a skip through adaptor's code,
If images are missing, a new action's bestowed.
The context now knows when it's text to create,
With clever conditionals, requests navigate.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 952b679 and f3b7ac5.

📒 Files selected for processing (1)
  • relay/channel/task/kling/adaptor.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
relay/channel/task/kling/adaptor.go (1)
constant/task.go (1)
  • TaskActionTextGenerate (17-17)

Comment on lines +146 to +148
if body.Image == "" && body.ImageTail == "" {
c.Set("action", constant.TaskActionTextGenerate)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Critical: Reference to undefined field ImageTail

The condition checks body.ImageTail but the requestPayload struct (lines 40-48) doesn't define an ImageTail field. This will cause a compilation error.

The logic to switch to text generation when no images are provided is sound, but the implementation references a non-existent field. Apply this fix:

-	if body.Image == "" && body.ImageTail == "" {
+	if body.Image == "" {
		c.Set("action", constant.TaskActionTextGenerate)
	}

Alternatively, if ImageTail is a required field for the functionality, add it to the requestPayload struct:

type requestPayload struct {
	Prompt      string  `json:"prompt,omitempty"`
	Image       string  `json:"image,omitempty"`
+	ImageTail   string  `json:"image_tail,omitempty"`
	Mode        string  `json:"mode,omitempty"`
	Duration    string  `json:"duration,omitempty"`
	AspectRatio string  `json:"aspect_ratio,omitempty"`
	ModelName   string  `json:"model_name,omitempty"`
	CfgScale    float64 `json:"cfg_scale,omitempty"`
}

Let me verify if ImageTail is used elsewhere in the codebase:


🏁 Script executed:

#!/bin/bash
# Search for ImageTail usage in the codebase
rg -i "imagetail" --type go -A 2 -B 2

Length of output: 339


🏁 Script executed:

#!/bin/bash
# Show definition of requestPayload to verify fields
rg -n "type requestPayload" -A 5 -B 5 relay/channel/task/kling/adaptor.go

Length of output: 559


Critical: Undefined ImageTail Field in Conditional

The check at relay/channel/task/kling/adaptor.go (lines 146–148)

if body.Image == "" && body.ImageTail == "" {
    c.Set("action", constant.TaskActionTextGenerate)
}

references body.ImageTail, but the requestPayload struct has no ImageTail field—this will break compilation.

• To fix, remove the nonexistent field from the condition:

- if body.Image == "" && body.ImageTail == "" {
+ if body.Image == "" {
     c.Set("action", constant.TaskActionTextGenerate)
 }

• If ImageTail is genuinely required, add it to requestPayload:

 type requestPayload struct {
     Prompt      string                 `json:"prompt,omitempty"`
     Image       string                 `json:"image,omitempty"`
+    ImageTail   string                 `json:"image_tail,omitempty"`
     Mode        string                 `json:"mode,omitempty"`
     Duration    string                 `json:"duration,omitempty"`
     AspectRatio string                 `json:"aspect_ratio,omitempty"`
 }
🤖 Prompt for AI Agents
In relay/channel/task/kling/adaptor.go around lines 146 to 148, the condition
references body.ImageTail, which does not exist in the requestPayload struct and
causes a compilation error. To fix this, either remove the check for
body.ImageTail from the if condition or, if the field is needed, add ImageTail
to the requestPayload struct definition before using it here.

@creamlike1024
creamlike1024 merged commit 9c798dc into QuantumNous:alpha Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants