agentscope-runtime 0.2.0b2__py3-none-any.whl → 1.0.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. agentscope_runtime/adapters/__init__.py +0 -0
  2. agentscope_runtime/adapters/agentscope/__init__.py +0 -0
  3. agentscope_runtime/adapters/agentscope/long_term_memory/__init__.py +6 -0
  4. agentscope_runtime/adapters/agentscope/long_term_memory/_long_term_memory_adapter.py +258 -0
  5. agentscope_runtime/adapters/agentscope/memory/__init__.py +6 -0
  6. agentscope_runtime/adapters/agentscope/memory/_memory_adapter.py +152 -0
  7. agentscope_runtime/adapters/agentscope/message.py +535 -0
  8. agentscope_runtime/adapters/agentscope/stream.py +474 -0
  9. agentscope_runtime/adapters/agentscope/tool/__init__.py +9 -0
  10. agentscope_runtime/adapters/agentscope/tool/sandbox_tool.py +69 -0
  11. agentscope_runtime/adapters/agentscope/tool/tool.py +233 -0
  12. agentscope_runtime/adapters/autogen/__init__.py +0 -0
  13. agentscope_runtime/adapters/autogen/tool/__init__.py +7 -0
  14. agentscope_runtime/adapters/autogen/tool/tool.py +211 -0
  15. agentscope_runtime/adapters/text/__init__.py +0 -0
  16. agentscope_runtime/adapters/text/stream.py +29 -0
  17. agentscope_runtime/common/collections/redis_mapping.py +4 -1
  18. agentscope_runtime/common/container_clients/fc_client.py +855 -0
  19. agentscope_runtime/common/utils/__init__.py +0 -0
  20. agentscope_runtime/common/utils/lazy_loader.py +57 -0
  21. agentscope_runtime/engine/__init__.py +25 -18
  22. agentscope_runtime/engine/app/agent_app.py +161 -91
  23. agentscope_runtime/engine/app/base_app.py +4 -118
  24. agentscope_runtime/engine/constant.py +8 -0
  25. agentscope_runtime/engine/deployers/__init__.py +8 -0
  26. agentscope_runtime/engine/deployers/adapter/__init__.py +2 -0
  27. agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +0 -21
  28. agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +28 -9
  29. agentscope_runtime/engine/deployers/adapter/responses/__init__.py +2 -0
  30. agentscope_runtime/engine/deployers/adapter/responses/response_api_adapter_utils.py +5 -2
  31. agentscope_runtime/engine/deployers/adapter/responses/response_api_protocol_adapter.py +1 -1
  32. agentscope_runtime/engine/deployers/agentrun_deployer.py +2541 -0
  33. agentscope_runtime/engine/deployers/cli_fc_deploy.py +1 -1
  34. agentscope_runtime/engine/deployers/kubernetes_deployer.py +9 -21
  35. agentscope_runtime/engine/deployers/local_deployer.py +47 -74
  36. agentscope_runtime/engine/deployers/modelstudio_deployer.py +216 -50
  37. agentscope_runtime/engine/deployers/utils/app_runner_utils.py +29 -0
  38. agentscope_runtime/engine/deployers/utils/detached_app.py +510 -0
  39. agentscope_runtime/engine/deployers/utils/docker_image_utils/__init__.py +1 -1
  40. agentscope_runtime/engine/deployers/utils/docker_image_utils/dockerfile_generator.py +1 -1
  41. agentscope_runtime/engine/deployers/utils/docker_image_utils/{runner_image_factory.py → image_factory.py} +121 -61
  42. agentscope_runtime/engine/deployers/utils/package.py +693 -0
  43. agentscope_runtime/engine/deployers/utils/service_utils/__init__.py +0 -5
  44. agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +256 -282
  45. agentscope_runtime/engine/deployers/utils/service_utils/fastapi_templates.py +2 -4
  46. agentscope_runtime/engine/deployers/utils/service_utils/process_manager.py +23 -1
  47. agentscope_runtime/engine/deployers/utils/templates/app_main.py.j2 +84 -0
  48. agentscope_runtime/engine/deployers/utils/templates/runner_main.py.j2 +95 -0
  49. agentscope_runtime/engine/deployers/utils/{service_utils → templates}/standalone_main.py.j2 +0 -45
  50. agentscope_runtime/engine/deployers/utils/wheel_packager.py +119 -18
  51. agentscope_runtime/engine/helpers/runner.py +40 -0
  52. agentscope_runtime/engine/runner.py +170 -130
  53. agentscope_runtime/engine/schemas/agent_schemas.py +114 -3
  54. agentscope_runtime/engine/schemas/modelstudio_llm.py +4 -2
  55. agentscope_runtime/engine/schemas/oai_llm.py +23 -23
  56. agentscope_runtime/engine/schemas/response_api.py +65 -0
  57. agentscope_runtime/engine/schemas/session.py +24 -0
  58. agentscope_runtime/engine/services/__init__.py +0 -9
  59. agentscope_runtime/engine/services/agent_state/__init__.py +16 -0
  60. agentscope_runtime/engine/services/agent_state/redis_state_service.py +113 -0
  61. agentscope_runtime/engine/services/agent_state/state_service.py +179 -0
  62. agentscope_runtime/engine/services/memory/__init__.py +24 -0
  63. agentscope_runtime/engine/services/{mem0_memory_service.py → memory/mem0_memory_service.py} +17 -13
  64. agentscope_runtime/engine/services/{memory_service.py → memory/memory_service.py} +28 -7
  65. agentscope_runtime/engine/services/{redis_memory_service.py → memory/redis_memory_service.py} +1 -1
  66. agentscope_runtime/engine/services/{reme_personal_memory_service.py → memory/reme_personal_memory_service.py} +9 -6
  67. agentscope_runtime/engine/services/{reme_task_memory_service.py → memory/reme_task_memory_service.py} +2 -2
  68. agentscope_runtime/engine/services/{tablestore_memory_service.py → memory/tablestore_memory_service.py} +12 -18
  69. agentscope_runtime/engine/services/sandbox/__init__.py +13 -0
  70. agentscope_runtime/engine/services/{sandbox_service.py → sandbox/sandbox_service.py} +86 -71
  71. agentscope_runtime/engine/services/session_history/__init__.py +23 -0
  72. agentscope_runtime/engine/services/{redis_session_history_service.py → session_history/redis_session_history_service.py} +3 -2
  73. agentscope_runtime/engine/services/{session_history_service.py → session_history/session_history_service.py} +44 -34
  74. agentscope_runtime/engine/services/{tablestore_session_history_service.py → session_history/tablestore_session_history_service.py} +14 -19
  75. agentscope_runtime/engine/services/utils/tablestore_service_utils.py +2 -2
  76. agentscope_runtime/engine/tracing/base.py +10 -9
  77. agentscope_runtime/engine/tracing/message_util.py +1 -1
  78. agentscope_runtime/engine/tracing/tracing_util.py +7 -2
  79. agentscope_runtime/sandbox/__init__.py +10 -2
  80. agentscope_runtime/sandbox/box/agentbay/__init__.py +4 -0
  81. agentscope_runtime/sandbox/box/agentbay/agentbay_sandbox.py +559 -0
  82. agentscope_runtime/sandbox/box/base/base_sandbox.py +12 -0
  83. agentscope_runtime/sandbox/box/browser/browser_sandbox.py +115 -11
  84. agentscope_runtime/sandbox/box/cloud/__init__.py +4 -0
  85. agentscope_runtime/sandbox/box/cloud/cloud_sandbox.py +254 -0
  86. agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +66 -0
  87. agentscope_runtime/sandbox/box/gui/gui_sandbox.py +42 -0
  88. agentscope_runtime/sandbox/box/mobile/__init__.py +4 -0
  89. agentscope_runtime/sandbox/box/mobile/box/__init__.py +0 -0
  90. agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +216 -0
  91. agentscope_runtime/sandbox/box/training_box/training_box.py +2 -2
  92. agentscope_runtime/sandbox/client/http_client.py +1 -0
  93. agentscope_runtime/sandbox/enums.py +2 -0
  94. agentscope_runtime/sandbox/manager/sandbox_manager.py +18 -2
  95. agentscope_runtime/sandbox/manager/server/app.py +12 -0
  96. agentscope_runtime/sandbox/manager/server/config.py +19 -0
  97. agentscope_runtime/sandbox/model/manager_config.py +79 -2
  98. agentscope_runtime/sandbox/utils.py +0 -18
  99. agentscope_runtime/tools/RAGs/__init__.py +0 -0
  100. agentscope_runtime/tools/RAGs/modelstudio_rag.py +377 -0
  101. agentscope_runtime/tools/RAGs/modelstudio_rag_lite.py +219 -0
  102. agentscope_runtime/tools/__init__.py +119 -0
  103. agentscope_runtime/tools/_constants.py +18 -0
  104. agentscope_runtime/tools/alipay/__init__.py +4 -0
  105. agentscope_runtime/tools/alipay/base.py +334 -0
  106. agentscope_runtime/tools/alipay/payment.py +835 -0
  107. agentscope_runtime/tools/alipay/subscribe.py +551 -0
  108. agentscope_runtime/tools/base.py +264 -0
  109. agentscope_runtime/tools/cli/__init__.py +0 -0
  110. agentscope_runtime/tools/cli/modelstudio_mcp_server.py +78 -0
  111. agentscope_runtime/tools/generations/__init__.py +75 -0
  112. agentscope_runtime/tools/generations/async_image_to_video.py +350 -0
  113. agentscope_runtime/tools/generations/async_image_to_video_wan25.py +366 -0
  114. agentscope_runtime/tools/generations/async_speech_to_video.py +422 -0
  115. agentscope_runtime/tools/generations/async_text_to_video.py +320 -0
  116. agentscope_runtime/tools/generations/async_text_to_video_wan25.py +334 -0
  117. agentscope_runtime/tools/generations/image_edit.py +208 -0
  118. agentscope_runtime/tools/generations/image_edit_wan25.py +193 -0
  119. agentscope_runtime/tools/generations/image_generation.py +202 -0
  120. agentscope_runtime/tools/generations/image_generation_wan25.py +201 -0
  121. agentscope_runtime/tools/generations/image_style_repaint.py +208 -0
  122. agentscope_runtime/tools/generations/image_to_video.py +233 -0
  123. agentscope_runtime/tools/generations/qwen_image_edit.py +205 -0
  124. agentscope_runtime/tools/generations/qwen_image_generation.py +214 -0
  125. agentscope_runtime/tools/generations/qwen_text_to_speech.py +154 -0
  126. agentscope_runtime/tools/generations/speech_to_text.py +260 -0
  127. agentscope_runtime/tools/generations/speech_to_video.py +314 -0
  128. agentscope_runtime/tools/generations/text_to_video.py +221 -0
  129. agentscope_runtime/tools/mcp_wrapper.py +215 -0
  130. agentscope_runtime/tools/realtime_clients/__init__.py +13 -0
  131. agentscope_runtime/tools/realtime_clients/asr_client.py +27 -0
  132. agentscope_runtime/tools/realtime_clients/azure_asr_client.py +195 -0
  133. agentscope_runtime/tools/realtime_clients/azure_tts_client.py +383 -0
  134. agentscope_runtime/tools/realtime_clients/modelstudio_asr_client.py +151 -0
  135. agentscope_runtime/tools/realtime_clients/modelstudio_tts_client.py +199 -0
  136. agentscope_runtime/tools/realtime_clients/realtime_tool.py +55 -0
  137. agentscope_runtime/tools/realtime_clients/tts_client.py +33 -0
  138. agentscope_runtime/tools/searches/__init__.py +3 -0
  139. agentscope_runtime/tools/searches/modelstudio_search.py +877 -0
  140. agentscope_runtime/tools/searches/modelstudio_search_lite.py +310 -0
  141. agentscope_runtime/tools/utils/__init__.py +0 -0
  142. agentscope_runtime/tools/utils/api_key_util.py +45 -0
  143. agentscope_runtime/tools/utils/crypto_utils.py +99 -0
  144. agentscope_runtime/tools/utils/mcp_util.py +35 -0
  145. agentscope_runtime/version.py +1 -1
  146. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/METADATA +234 -165
  147. agentscope_runtime-1.0.0b1.dist-info/RECORD +240 -0
  148. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/entry_points.txt +1 -0
  149. agentscope_runtime/engine/agents/__init__.py +0 -2
  150. agentscope_runtime/engine/agents/agentscope_agent.py +0 -488
  151. agentscope_runtime/engine/agents/agno_agent.py +0 -220
  152. agentscope_runtime/engine/agents/autogen_agent.py +0 -250
  153. agentscope_runtime/engine/agents/base_agent.py +0 -29
  154. agentscope_runtime/engine/agents/langgraph_agent.py +0 -59
  155. agentscope_runtime/engine/agents/utils.py +0 -53
  156. agentscope_runtime/engine/deployers/utils/package_project_utils.py +0 -1163
  157. agentscope_runtime/engine/deployers/utils/service_utils/service_config.py +0 -75
  158. agentscope_runtime/engine/deployers/utils/service_utils/service_factory.py +0 -220
  159. agentscope_runtime/engine/helpers/helper.py +0 -179
  160. agentscope_runtime/engine/schemas/context.py +0 -54
  161. agentscope_runtime/engine/services/context_manager.py +0 -164
  162. agentscope_runtime/engine/services/environment_manager.py +0 -50
  163. agentscope_runtime/engine/services/manager.py +0 -174
  164. agentscope_runtime/engine/services/rag_service.py +0 -195
  165. agentscope_runtime/engine/services/tablestore_rag_service.py +0 -143
  166. agentscope_runtime/sandbox/tools/__init__.py +0 -12
  167. agentscope_runtime/sandbox/tools/base/__init__.py +0 -8
  168. agentscope_runtime/sandbox/tools/base/tool.py +0 -52
  169. agentscope_runtime/sandbox/tools/browser/__init__.py +0 -57
  170. agentscope_runtime/sandbox/tools/browser/tool.py +0 -597
  171. agentscope_runtime/sandbox/tools/filesystem/__init__.py +0 -32
  172. agentscope_runtime/sandbox/tools/filesystem/tool.py +0 -319
  173. agentscope_runtime/sandbox/tools/function_tool.py +0 -321
  174. agentscope_runtime/sandbox/tools/gui/__init__.py +0 -7
  175. agentscope_runtime/sandbox/tools/gui/tool.py +0 -77
  176. agentscope_runtime/sandbox/tools/mcp_tool.py +0 -195
  177. agentscope_runtime/sandbox/tools/sandbox_tool.py +0 -104
  178. agentscope_runtime/sandbox/tools/tool.py +0 -238
  179. agentscope_runtime/sandbox/tools/utils.py +0 -68
  180. agentscope_runtime-0.2.0b2.dist-info/RECORD +0 -183
  181. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/WHEEL +0 -0
  182. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/licenses/LICENSE +0 -0
  183. {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,366 @@
1
+ # -*- coding: utf-8 -*-
2
+ # pylint:disable=abstract-method, deprecated-module, wrong-import-order
3
+
4
+ import os
5
+ import uuid
6
+ from http import HTTPStatus
7
+ from typing import Any, Optional
8
+
9
+ from dashscope.aigc.video_synthesis import AioVideoSynthesis
10
+ from mcp.server.fastmcp import Context
11
+ from pydantic import BaseModel, Field
12
+
13
+ from ..base import Tool
14
+ from ..utils.api_key_util import get_api_key, ApiNames
15
+ from ...engine.tracing import trace, TracingUtil
16
+
17
+
18
+ class ImageToVideoWan25SubmitInput(BaseModel):
19
+ """
20
+ Input model for image-to-video generation submission.
21
+
22
+ This model defines the input parameters required for submitting an
23
+ image-to-video generation task to the DashScope API.
24
+ """
25
+
26
+ image_url: str = Field(
27
+ ...,
28
+ description="输入图像,支持公网URL、Base64编码或本地文件路径",
29
+ )
30
+ prompt: Optional[str] = Field(
31
+ default=None,
32
+ description="正向提示词,用来描述生成视频中期望包含的元素和视觉特点",
33
+ )
34
+ negative_prompt: Optional[str] = Field(
35
+ default=None,
36
+ description="反向提示词,用来描述不希望在视频画面中看到的内容",
37
+ )
38
+ audio_url: Optional[str] = Field(
39
+ default=None,
40
+ description="自定义音频文件URL,模型将使用该音频生成视频。"
41
+ "参数优先级:audio_url > audio,仅在 audio_url 为空时audio生效。",
42
+ )
43
+ audio: Optional[bool] = Field(
44
+ default=None,
45
+ description="是否自动生成音频。"
46
+ "参数优先级:audio_url > audio,仅在 audio_url 为空时audio生效。",
47
+ )
48
+ template: Optional[str] = Field(
49
+ default=None,
50
+ description="视频特效模板,可选值:squish(解压捏捏)、flying(魔法悬浮)、carousel(时光木马)等",
51
+ )
52
+ resolution: Optional[str] = Field(
53
+ default=None,
54
+ description="视频分辨率,默认不设置",
55
+ )
56
+ duration: Optional[int] = Field(
57
+ default=None,
58
+ description="视频生成时长,单位为秒,通常为5秒",
59
+ )
60
+ prompt_extend: Optional[bool] = Field(
61
+ default=None,
62
+ description="是否开启prompt智能改写,开启后使用大模型对输入prompt进行智能改写",
63
+ )
64
+ watermark: Optional[bool] = Field(
65
+ default=None,
66
+ description="是否添加水印,默认不设置",
67
+ )
68
+ ctx: Optional[Context] = Field(
69
+ default=None,
70
+ description="HTTP request context containing headers for mcp only, "
71
+ "don't generate it",
72
+ )
73
+
74
+
75
+ class ImageToVideoWan25SubmitOutput(BaseModel):
76
+ """
77
+ Output model for image-to-video generation submission.
78
+
79
+ This model contains the response data after successfully submitting
80
+ an image-to-video generation task.
81
+ """
82
+
83
+ task_id: str = Field(
84
+ title="Task ID",
85
+ description="视频生成的任务ID",
86
+ )
87
+
88
+ task_status: str = Field(
89
+ title="Task Status",
90
+ description="视频生成的任务状态,PENDING:任务排队中,RUNNING:任务处理中,SUCCEEDED:任务执行成功,"
91
+ "FAILED:任务执行失败,CANCELED:任务取消成功,UNKNOWN:任务不存在或状态未知",
92
+ )
93
+
94
+ request_id: Optional[str] = Field(
95
+ default=None,
96
+ title="Request ID",
97
+ description="请求ID",
98
+ )
99
+
100
+
101
+ class ImageToVideoWan25Submit(
102
+ Tool[ImageToVideoWan25SubmitInput, ImageToVideoWan25SubmitOutput],
103
+ ):
104
+ """
105
+ Service for submitting image-to-video generation tasks.
106
+
107
+ This Tool provides functionality to submit asynchronous
108
+ image-to-video generation tasks using DashScope's VideoSynthesis API.
109
+ It supports various video effects and customization options.
110
+ """
111
+
112
+ name: str = "modelstudio_image_to_video_wan25_submit_task"
113
+ description: str = (
114
+ "通义万相-图生视频模型的异步任务提交工具。根据首帧图像和文本提示词,生成时长为5秒的无声视频。"
115
+ "同时支持特效模板,可添加“魔法悬浮”、“气球膨胀”等效果,适用于创意视频制作、娱乐特效展示等场景。"
116
+ )
117
+
118
+ @trace(trace_type="AIGC", trace_name="image_to_video_wan25_submit")
119
+ async def arun(
120
+ self,
121
+ args: ImageToVideoWan25SubmitInput,
122
+ **kwargs: Any,
123
+ ) -> ImageToVideoWan25SubmitOutput:
124
+ """
125
+ Submit an image-to-video generation task using DashScope API.
126
+
127
+ This method asynchronously submits an image-to-video generation task
128
+ to DashScope's VideoSynthesis service. It supports various video
129
+ effects, resolution settings, and prompt enhancements.
130
+
131
+ Args:
132
+ args: ImageToVideoWan25SubmitInput containing required image_url
133
+ and optional parameters for video generation
134
+ **kwargs: Additional keyword arguments including:
135
+ - request_id: Optional request ID for tracking
136
+ - model_name: Model name (defaults to wan2.2-i2v-flash)
137
+ - api_key: DashScope API key for authentication
138
+
139
+ Returns:
140
+ ImageToVideoWan25SubmitOutput containing the task ID, current
141
+ status, and request ID for tracking the submission
142
+
143
+ Raises:
144
+ ValueError: If DASHSCOPE_API_KEY is not set or invalid
145
+ RuntimeError: If video generation submission fails
146
+ """
147
+ trace_event = kwargs.pop("trace_event", None)
148
+ request_id = TracingUtil.get_request_id()
149
+
150
+ try:
151
+ api_key = get_api_key(ApiNames.dashscope_api_key, **kwargs)
152
+ except AssertionError as e:
153
+ raise ValueError("Please set valid DASHSCOPE_API_KEY!") from e
154
+
155
+ model_name = kwargs.get(
156
+ "model_name",
157
+ os.getenv("IMAGE_TO_VIDEO_MODEL_NAME", "wan2.5-i2v-preview"),
158
+ )
159
+
160
+ parameters = {}
161
+ if args.audio is not None:
162
+ parameters["audio"] = args.audio
163
+ if args.resolution:
164
+ parameters["resolution"] = args.resolution
165
+ if args.duration is not None:
166
+ parameters["duration"] = args.duration
167
+ if args.prompt_extend is not None:
168
+ parameters["prompt_extend"] = args.prompt_extend
169
+ if args.watermark is not None:
170
+ parameters["watermark"] = args.watermark
171
+
172
+ # Create AioVideoSynthesis instance
173
+ aio_video_synthesis = AioVideoSynthesis()
174
+
175
+ # Submit async task
176
+ response = await aio_video_synthesis.async_call(
177
+ model=model_name,
178
+ api_key=api_key,
179
+ img_url=args.image_url,
180
+ prompt=args.prompt,
181
+ negative_prompt=args.negative_prompt,
182
+ audio_url=args.audio_url,
183
+ template=args.template,
184
+ **parameters,
185
+ )
186
+
187
+ # Log trace event if provided
188
+ if trace_event:
189
+ trace_event.on_log(
190
+ "",
191
+ **{
192
+ "step_suffix": "results",
193
+ "payload": {
194
+ "request_id": request_id,
195
+ "submit_task": response,
196
+ },
197
+ },
198
+ )
199
+
200
+ if (
201
+ response.status_code != HTTPStatus.OK
202
+ or not response.output
203
+ or response.output.task_status in ["FAILED", "CANCELED"]
204
+ ):
205
+ raise RuntimeError(f"Failed to submit task: {response}")
206
+
207
+ if not request_id:
208
+ request_id = (
209
+ response.request_id
210
+ if response.request_id
211
+ else str(uuid.uuid4())
212
+ )
213
+
214
+ result = ImageToVideoWan25SubmitOutput(
215
+ request_id=request_id,
216
+ task_id=response.output.task_id,
217
+ task_status=response.output.task_status,
218
+ )
219
+ return result
220
+
221
+
222
+ class ImageToVideoWan25FetchInput(BaseModel):
223
+ """
224
+ Input model for fetching image-to-video generation results.
225
+
226
+ This model defines the input parameters required for retrieving
227
+ the status and results of a previously submitted video generation task.
228
+ """
229
+
230
+ task_id: str = Field(
231
+ title="Task ID",
232
+ description="视频生成的任务ID",
233
+ )
234
+ ctx: Optional[Context] = Field(
235
+ default=None,
236
+ description="HTTP request context containing headers for mcp only, "
237
+ "don't generate it",
238
+ )
239
+
240
+
241
+ class ImageToVideoWan25FetchOutput(BaseModel):
242
+ """
243
+ Output model for fetching image-to-video generation results.
244
+
245
+ This model contains the response data including video URL, task status,
246
+ and other metadata after fetching a video generation task result.
247
+ """
248
+
249
+ video_url: str = Field(
250
+ title="Video URL",
251
+ description="输出的视频url",
252
+ )
253
+
254
+ task_id: str = Field(
255
+ title="Task ID",
256
+ description="视频生成的任务ID",
257
+ )
258
+
259
+ task_status: str = Field(
260
+ title="Task Status",
261
+ description="视频生成的任务状态,PENDING:任务排队中,"
262
+ "RUNNING:任务处理中,SUCCEEDED:任务执行成功,"
263
+ "FAILED:任务执行失败,CANCELED:任务取消成功,"
264
+ "UNKNOWN:任务不存在或状态未知",
265
+ )
266
+
267
+ request_id: Optional[str] = Field(
268
+ default=None,
269
+ title="Request ID",
270
+ description="请求ID",
271
+ )
272
+
273
+
274
+ class ImageToVideoWan25Fetch(
275
+ Tool[ImageToVideoWan25FetchInput, ImageToVideoWan25FetchOutput],
276
+ ):
277
+ """
278
+ Service for fetching image-to-video generation results.
279
+
280
+ This Tool provides functionality to retrieve the status and
281
+ results of asynchronous image-to-video generation tasks using
282
+ DashScope's VideoSynthesis API.
283
+ """
284
+
285
+ name: str = "modelstudio_image_to_video_wan25_fetch_result"
286
+ description: str = "通义万相-图生视频模型的异步任务结果查询工具,根据Task ID查询任务结果。"
287
+
288
+ @trace(trace_type="AIGC", trace_name="image_to_video_wan25_fetch")
289
+ async def arun(
290
+ self,
291
+ args: ImageToVideoWan25FetchInput,
292
+ **kwargs: Any,
293
+ ) -> ImageToVideoWan25FetchOutput:
294
+ """
295
+ Fetch the results of an image-to-video generation task.
296
+
297
+ This method asynchronously retrieves the status and results of a
298
+ previously submitted image-to-video generation task using the
299
+ task ID returned from the submission.
300
+
301
+ Args:
302
+ args: ImageToVideoWan25FetchInput containing the task_id
303
+ parameter
304
+ **kwargs: Additional keyword arguments including:
305
+ - api_key: DashScope API key for authentication
306
+
307
+ Returns:
308
+ ImageToVideoWan25FetchOutput containing the video URL, current
309
+ task status, and request ID
310
+
311
+ Raises:
312
+ ValueError: If DASHSCOPE_API_KEY is not set or invalid
313
+ RuntimeError: If video fetch fails or response status is not OK
314
+ """
315
+ trace_event = kwargs.pop("trace_event", None)
316
+ request_id = TracingUtil.get_request_id()
317
+
318
+ try:
319
+ api_key = get_api_key(ApiNames.dashscope_api_key, **kwargs)
320
+ except AssertionError as e:
321
+ raise ValueError("Please set valid DASHSCOPE_API_KEY!") from e
322
+
323
+ # Create AioVideoSynthesis instance
324
+ aio_video_synthesis = AioVideoSynthesis()
325
+
326
+ response = await aio_video_synthesis.fetch(
327
+ api_key=api_key,
328
+ task=args.task_id,
329
+ )
330
+
331
+ # Log trace event if provided
332
+ if trace_event:
333
+ trace_event.on_log(
334
+ "",
335
+ **{
336
+ "step_suffix": "results",
337
+ "payload": {
338
+ "request_id": response.request_id,
339
+ "fetch_result": response,
340
+ },
341
+ },
342
+ )
343
+
344
+ if (
345
+ response.status_code != HTTPStatus.OK
346
+ or not response.output
347
+ or response.output.task_status in ["FAILED", "CANCELED"]
348
+ ):
349
+ raise RuntimeError(f"Failed to fetch result: {response}")
350
+
351
+ # Handle request ID
352
+ if not request_id:
353
+ request_id = (
354
+ response.request_id
355
+ if response.request_id
356
+ else str(uuid.uuid4())
357
+ )
358
+
359
+ result = ImageToVideoWan25FetchOutput(
360
+ video_url=response.output.video_url,
361
+ task_id=response.output.task_id,
362
+ task_status=response.output.task_status,
363
+ request_id=request_id,
364
+ )
365
+
366
+ return result