feat(mcp): new tool modelstudio_video_to_video_wan26_submit_task in w…#64
feat(mcp): new tool modelstudio_video_to_video_wan26_submit_task in w…#64lether wants to merge 1 commit intoagentscope-ai:mainfrom
Conversation
Summary of ChangesHello @lether, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the system's capabilities by introducing a new asynchronous video-to-video generation tool. This tool allows for the submission of video synthesis tasks to an external AI service, specifically Alibaba Cloud's Tongyi Wanxiang, to generate new video content using reference video characters. The integration provides a structured interface for defining video generation parameters and returns a unique identifier for tracking the progress of each submitted task. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new component modelstudio_video_to_video_wan26_submit_task for submitting video-to-video generation tasks to the Wanxiang 2.6 model. The changes include adding the new component file, registering it in the __init__.py, and updating the component list for modelstudio_wan26_media.
The implementation of the new component is well-structured. I've provided a few suggestions to improve the code's robustness and maintainability, such as making the API response parsing safer and simplifying the construction of the request payload. I also pointed out a minor issue with an unused import.
| response_json = await resp.json() | ||
| task_id = response_json["output"]["task_id"] |
There was a problem hiding this comment.
Direct dictionary access like response_json["output"]["task_id"] is not robust. If the API returns an unexpected JSON structure (e.g., an error message), this will raise a KeyError. It's also possible that resp.json() fails if the response is not valid JSON. It's better to wrap this logic in a try...except block to handle potential KeyError and json.JSONDecodeError gracefully.
try:
response_json = await resp.json()
task_id = response_json["output"]["task_id"]
except (KeyError, json.JSONDecodeError):
text = await resp.text()
raise RuntimeError(
f"Failed to parse task_id from API response: {text}",
)| import uuid | ||
| import json | ||
| from http import HTTPStatus | ||
| from typing import Any, Optional, Dict |
| input_data = { | ||
| "prompt": args.prompt, | ||
| "reference_video_urls": args.reference_video_urls, | ||
| } | ||
| if args.negative_prompt is not None: | ||
| input_data["negative_prompt"] = args.negative_prompt | ||
| parameters = { | ||
| "size": args.size, | ||
| "duration": args.duration, | ||
| "shot_type": args.shot_type, | ||
| "watermark": args.watermark, | ||
| } | ||
| if args.seed is not None: | ||
| parameters["seed"] = args.seed |
There was a problem hiding this comment.
The construction of input_data and parameters can be simplified and made more maintainable by using pydantic's model_dump method. This avoids manually listing each parameter and will automatically handle new parameters added to the input model, reducing the chance of errors.
all_args = args.model_dump(exclude={"ctx"}, exclude_none=True)
input_fields = {"prompt", "reference_video_urls", "negative_prompt"}
input_data = {k: v for k, v in all_args.items() if k in input_fields}
parameters = {k: v for k, v in all_args.items() if k not in input_fields}
No description provided.