dashscope 1.20.14__py3-none-any.whl → 1.21.0__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.

Potentially problematic release.


This version of dashscope might be problematic. Click here for more details.

dashscope/__init__.py CHANGED
@@ -5,6 +5,7 @@ from dashscope.aigc.code_generation import CodeGeneration
5
5
  from dashscope.aigc.conversation import Conversation, History, HistoryItem
6
6
  from dashscope.aigc.generation import AioGeneration, Generation
7
7
  from dashscope.aigc.image_synthesis import ImageSynthesis
8
+ from dashscope.aigc.video_synthesis import VideoSynthesis
8
9
  from dashscope.aigc.multimodal_conversation import MultiModalConversation
9
10
  from dashscope.app.application import Application
10
11
  from dashscope.assistants import Assistant, AssistantList, Assistants
@@ -84,6 +85,7 @@ __all__ = [
84
85
  RunStep,
85
86
  MessageFile,
86
87
  AssistantFile,
88
+ VideoSynthesis,
87
89
  ]
88
90
 
89
91
  logging.getLogger(__name__).addHandler(NullHandler())
@@ -2,6 +2,7 @@ from .conversation import Conversation, History, HistoryItem
2
2
  from .generation import Generation
3
3
  from .image_synthesis import ImageSynthesis
4
4
  from .multimodal_conversation import MultiModalConversation
5
+ from .video_synthesis import VideoSynthesis
5
6
 
6
7
  __all__ = [
7
8
  Generation,
@@ -10,4 +11,5 @@ __all__ = [
10
11
  History,
11
12
  ImageSynthesis,
12
13
  MultiModalConversation,
14
+ VideoSynthesis,
13
15
  ]
@@ -0,0 +1,242 @@
1
+ from typing import Any, Dict, Union
2
+
3
+ from dashscope.api_entities.dashscope_response import (DashScopeAPIResponse,
4
+ VideoSynthesisResponse)
5
+ from dashscope.client.base_api import BaseAsyncApi
6
+ from dashscope.common.constants import PROMPT
7
+ from dashscope.common.error import InputRequired
8
+ from dashscope.common.utils import _get_task_group_and_task
9
+ from dashscope.utils.oss_utils import check_and_upload_local
10
+
11
+
12
+ class VideoSynthesis(BaseAsyncApi):
13
+ task = 'video-generation'
14
+ """API for video synthesis.
15
+ """
16
+ class Models:
17
+ wanx_txt2video_pro = 'wanx-txt2video-pro'
18
+ wanx_img2video_pro = 'wanx-img2video-pro'
19
+ wanx_2_1_t2v_turbo = 'wanx2.1-t2v-turbo'
20
+ wanx_2_1_t2v_plus = 'wanx2.1-t2v-plus'
21
+
22
+ @classmethod
23
+ def call(cls,
24
+ model: str,
25
+ prompt: Any,
26
+ extend_prompt: bool = True,
27
+ negative_prompt: str = None,
28
+ template: str = None,
29
+ img_url: str = None,
30
+ api_key: str = None,
31
+ extra_input: Dict = None,
32
+ workspace: str = None,
33
+ task: str = None,
34
+ **kwargs) -> VideoSynthesisResponse:
35
+ """Call video synthesis service and get result.
36
+
37
+ Args:
38
+ model (str): The model, reference ``Models``.
39
+ prompt (Any): The prompt for video synthesis.
40
+ extend_prompt (bool): The extend_prompt. Whether to enable write expansion. The default value is True.
41
+ negative_prompt (str): The negative prompt is the opposite of the prompt meaning.
42
+ template (str): LoRa input, such as gufeng, katong, etc.
43
+ img_url (str): The input image url, Generate the URL of the image referenced by the video.
44
+ api_key (str, optional): The api api_key. Defaults to None.
45
+ workspace (str): The dashscope workspace id.
46
+ extra_input (Dict): The extra input parameters.
47
+ task (str): The task of api, ref doc.
48
+ **kwargs:
49
+ size(str, `optional`): The output video size(width*height).
50
+ duration(int, optional): The duration. Duration of video generation. The default value is 5, in seconds.
51
+ seed(int, optional): The seed. The random seed for video generation. The default value is 5.
52
+
53
+ Raises:
54
+ InputRequired: The prompt cannot be empty.
55
+
56
+ Returns:
57
+ VideoSynthesisResponse: The video synthesis result.
58
+ """
59
+ return super().call(model,
60
+ prompt,
61
+ img_url=img_url,
62
+ api_key=api_key,
63
+ extend_prompt=extend_prompt,
64
+ negative_prompt=negative_prompt,
65
+ template=template,
66
+ workspace=workspace,
67
+ extra_input=extra_input,
68
+ task=task,
69
+ **kwargs)
70
+
71
+ @classmethod
72
+ def async_call(cls,
73
+ model: str,
74
+ prompt: Any,
75
+ img_url: str = None,
76
+ extend_prompt: bool = True,
77
+ negative_prompt: str = None,
78
+ template: str = None,
79
+ api_key: str = None,
80
+ extra_input: Dict = None,
81
+ workspace: str = None,
82
+ task: str = None,
83
+ **kwargs) -> VideoSynthesisResponse:
84
+ """Create a video synthesis task, and return task information.
85
+
86
+ Args:
87
+ model (str): The model, reference ``Models``.
88
+ prompt (Any): The prompt for video synthesis.
89
+ extend_prompt (bool): The extend_prompt. Whether to enable write expansion. The default value is True.
90
+ negative_prompt (str): The negative prompt is the opposite of the prompt meaning.
91
+ template (str): LoRa input, such as gufeng, katong, etc.
92
+ img_url (str): The input image url, Generate the URL of the image referenced by the video.
93
+ api_key (str, optional): The api api_key. Defaults to None.
94
+ workspace (str): The dashscope workspace id.
95
+ extra_input (Dict): The extra input parameters.
96
+ task (str): The task of api, ref doc.
97
+ **kwargs:
98
+ size(str, `optional`): The output video size(width*height).
99
+ duration(int, optional): The duration. Duration of video generation. The default value is 5, in seconds.
100
+ seed(int, optional): The seed. The random seed for video generation. The default value is 5.
101
+
102
+ Raises:
103
+ InputRequired: The prompt cannot be empty.
104
+
105
+ Returns:
106
+ DashScopeAPIResponse: The video synthesis
107
+ task id in the response.
108
+ """
109
+ if prompt is None or not prompt:
110
+ raise InputRequired('prompt is required!')
111
+ task_group, function = _get_task_group_and_task(__name__)
112
+ inputs = {PROMPT: prompt, 'extend_prompt': extend_prompt}
113
+ if negative_prompt:
114
+ inputs['negative_prompt'] = negative_prompt
115
+ if template:
116
+ inputs['template'] = template
117
+ has_upload = False
118
+ if img_url is not None and img_url:
119
+ is_upload, res_img_url = check_and_upload_local(
120
+ model, img_url, api_key)
121
+ if is_upload:
122
+ has_upload = True
123
+ inputs['img_url'] = res_img_url
124
+ if extra_input is not None and extra_input:
125
+ inputs = {**inputs, **extra_input}
126
+ if has_upload:
127
+ headers = kwargs.pop('headers', {})
128
+ headers['X-DashScope-OssResourceResolve'] = 'enable'
129
+ kwargs['headers'] = headers
130
+ response = super().async_call(
131
+ model=model,
132
+ task_group=task_group,
133
+ task=VideoSynthesis.task if task is None else task,
134
+ function=function,
135
+ api_key=api_key,
136
+ input=inputs,
137
+ workspace=workspace,
138
+ **kwargs)
139
+ return VideoSynthesisResponse.from_api_response(response)
140
+
141
+ @classmethod
142
+ def fetch(cls,
143
+ task: Union[str, VideoSynthesisResponse],
144
+ api_key: str = None,
145
+ workspace: str = None) -> VideoSynthesisResponse:
146
+ """Fetch video synthesis task status or result.
147
+
148
+ Args:
149
+ task (Union[str, VideoSynthesisResponse]): The task_id or
150
+ VideoSynthesisResponse return by async_call().
151
+ api_key (str, optional): The api api_key. Defaults to None.
152
+ workspace (str): The dashscope workspace id.
153
+
154
+ Returns:
155
+ VideoSynthesisResponse: The task status or result.
156
+ """
157
+ response = super().fetch(task, api_key=api_key, workspace=workspace)
158
+ return VideoSynthesisResponse.from_api_response(response)
159
+
160
+ @classmethod
161
+ def wait(cls,
162
+ task: Union[str, VideoSynthesisResponse],
163
+ api_key: str = None,
164
+ workspace: str = None) -> VideoSynthesisResponse:
165
+ """Wait for video synthesis task to complete, and return the result.
166
+
167
+ Args:
168
+ task (Union[str, VideoSynthesisResponse]): The task_id or
169
+ VideoSynthesisResponse return by async_call().
170
+ api_key (str, optional): The api api_key. Defaults to None.
171
+ workspace (str): The dashscope workspace id.
172
+
173
+ Returns:
174
+ VideoSynthesisResponse: The task result.
175
+ """
176
+ response = super().wait(task, api_key, workspace=workspace)
177
+ return VideoSynthesisResponse.from_api_response(response)
178
+
179
+ @classmethod
180
+ def cancel(cls,
181
+ task: Union[str, VideoSynthesisResponse],
182
+ api_key: str = None,
183
+ workspace: str = None) -> DashScopeAPIResponse:
184
+ """Cancel video synthesis task.
185
+ Only tasks whose status is PENDING can be canceled.
186
+
187
+ Args:
188
+ task (Union[str, VideoSynthesisResponse]): The task_id or
189
+ VideoSynthesisResponse return by async_call().
190
+ api_key (str, optional): The api api_key. Defaults to None.
191
+ workspace (str): The dashscope workspace id.
192
+
193
+ Returns:
194
+ DashScopeAPIResponse: The response data.
195
+ """
196
+ return super().cancel(task, api_key, workspace=workspace)
197
+
198
+ @classmethod
199
+ def list(cls,
200
+ start_time: str = None,
201
+ end_time: str = None,
202
+ model_name: str = None,
203
+ api_key_id: str = None,
204
+ region: str = None,
205
+ status: str = None,
206
+ page_no: int = 1,
207
+ page_size: int = 10,
208
+ api_key: str = None,
209
+ workspace: str = None,
210
+ **kwargs) -> DashScopeAPIResponse:
211
+ """List async tasks.
212
+
213
+ Args:
214
+ start_time (str, optional): The tasks start time,
215
+ for example: 20230420000000. Defaults to None.
216
+ end_time (str, optional): The tasks end time,
217
+ for example: 20230420000000. Defaults to None.
218
+ model_name (str, optional): The tasks model name. Defaults to None.
219
+ api_key_id (str, optional): The tasks api-key-id. Defaults to None.
220
+ region (str, optional): The service region,
221
+ for example: cn-beijing. Defaults to None.
222
+ status (str, optional): The status of tasks[PENDING,
223
+ RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None.
224
+ page_no (int, optional): The page number. Defaults to 1.
225
+ page_size (int, optional): The page size. Defaults to 10.
226
+ api_key (str, optional): The user api-key. Defaults to None.
227
+ workspace (str): The dashscope workspace id.
228
+
229
+ Returns:
230
+ DashScopeAPIResponse: The response data.
231
+ """
232
+ return super().list(start_time=start_time,
233
+ end_time=end_time,
234
+ model_name=model_name,
235
+ api_key_id=api_key_id,
236
+ region=region,
237
+ status=status,
238
+ page_no=page_no,
239
+ page_size=page_size,
240
+ api_key=api_key,
241
+ workspace=workspace,
242
+ **kwargs)
@@ -458,6 +458,24 @@ class ImageSynthesisOutput(DictMixin):
458
458
  **kwargs)
459
459
 
460
460
 
461
+ @dataclass(init=False)
462
+ class VideoSynthesisOutput(DictMixin):
463
+ task_id: str
464
+ task_status: str
465
+ video_url: str
466
+
467
+ def __init__(self,
468
+ task_id: str,
469
+ task_status: str,
470
+ video_url: str = '',
471
+ **kwargs):
472
+ super().__init__(self,
473
+ task_id=task_id,
474
+ task_status=task_status,
475
+ video_url=video_url,
476
+ **kwargs)
477
+
478
+
461
479
  @dataclass(init=False)
462
480
  class ImageSynthesisUsage(DictMixin):
463
481
  image_count: int
@@ -466,6 +484,14 @@ class ImageSynthesisUsage(DictMixin):
466
484
  super().__init__(image_count=image_count, **kwargs)
467
485
 
468
486
 
487
+ @dataclass(init=False)
488
+ class VideoSynthesisUsage(DictMixin):
489
+ video_count: int
490
+
491
+ def __init__(self, video_count: int = 1, **kwargs):
492
+ super().__init__(video_count=video_count, **kwargs)
493
+
494
+
469
495
  @dataclass(init=False)
470
496
  class ImageSynthesisResponse(DashScopeAPIResponse):
471
497
  output: ImageSynthesisOutput
@@ -495,6 +521,35 @@ class ImageSynthesisResponse(DashScopeAPIResponse):
495
521
  message=api_response.message)
496
522
 
497
523
 
524
+ @dataclass(init=False)
525
+ class VideoSynthesisResponse(DashScopeAPIResponse):
526
+ output: VideoSynthesisOutput
527
+ usage: VideoSynthesisUsage
528
+
529
+ @staticmethod
530
+ def from_api_response(api_response: DashScopeAPIResponse):
531
+ if api_response.status_code == HTTPStatus.OK:
532
+ output = None
533
+ usage = None
534
+ if api_response.output is not None:
535
+ output = VideoSynthesisOutput(**api_response.output)
536
+ if api_response.usage is not None:
537
+ usage = VideoSynthesisUsage(**api_response.usage)
538
+
539
+ return VideoSynthesisResponse(status_code=api_response.status_code,
540
+ request_id=api_response.request_id,
541
+ code=api_response.code,
542
+ message=api_response.message,
543
+ output=output,
544
+ usage=usage)
545
+
546
+ else:
547
+ return VideoSynthesisResponse(status_code=api_response.status_code,
548
+ request_id=api_response.request_id,
549
+ code=api_response.code,
550
+ message=api_response.message)
551
+
552
+
498
553
  @dataclass(init=False)
499
554
  class ReRankResult(DictMixin):
500
555
  index: int
@@ -142,7 +142,7 @@ def check_and_upload_local(model: str, content: str, api_key: str):
142
142
  file_path = parse_result.netloc + unquote_plus(parse_result.path)
143
143
  else:
144
144
  file_path = unquote_plus(parse_result.path)
145
- if os.path.exists(file_path):
145
+ if os.path.isfile(file_path):
146
146
  file_url = OssUtils.upload(model=model,
147
147
  file_path=file_path,
148
148
  api_key=api_key)
@@ -153,7 +153,7 @@ def check_and_upload_local(model: str, content: str, api_key: str):
153
153
  else:
154
154
  raise InvalidInput('The file: %s is not exists!' % file_path)
155
155
  elif not content.startswith('http'):
156
- if os.path.exists(content):
156
+ if os.path.isfile(content):
157
157
  file_url = OssUtils.upload(model=model,
158
158
  file_path=content,
159
159
  api_key=api_key)
dashscope/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '1.20.14'
1
+ __version__ = '1.21.0'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dashscope
3
- Version: 1.20.14
3
+ Version: 1.21.0
4
4
  Summary: dashscope client sdk library
5
5
  Home-page: https://dashscope.aliyun.com/
6
6
  Author: Alibaba Cloud
@@ -1,4 +1,4 @@
1
- dashscope/__init__.py,sha256=lIBZR5fWUiO1L62J_17Gri7Dwk9kCf2xhWl8eRw8bkQ,2933
1
+ dashscope/__init__.py,sha256=_9PaKXKpYc6PXO35BjcH3R0As9sTsXGOW2iQ6R5HAVc,3011
2
2
  dashscope/cli.py,sha256=amegoTkGOs6TlHMdoo4JVOqBePo3lGs745rc7leEyrE,24020
3
3
  dashscope/deployment.py,sha256=ljmVi-ny6SjEs8v4oIGNWIw8UQTorE7dl5QJv7dEPIQ,5728
4
4
  dashscope/file.py,sha256=Dv2Fz3DLbcye2uuQxyQwRM7ky27OthouLXIpSQagQy4,3324
@@ -6,19 +6,20 @@ dashscope/files.py,sha256=QgJjwhtn9F548nCA8jD8OvE6aQEj-20hZqJgYXsUdQU,3930
6
6
  dashscope/finetune.py,sha256=_tflDUvu0KagSoCzLaf0hofpG_P8NU6PylL8CPjVhrA,6243
7
7
  dashscope/model.py,sha256=UPOn1qMYFhX-ovXi3BMxZEBk8qOK7WLJOYHMbPZwYBo,1440
8
8
  dashscope/models.py,sha256=1-bc-Ue68zurgu_y6RhfFr9uzeQMF5AZq-C32lJGMGU,1224
9
- dashscope/version.py,sha256=f2v96-65Z-gg0WsfONkq43TxOuOMUup-4S2fb1hhRjA,24
10
- dashscope/aigc/__init__.py,sha256=s-MCA87KYiVumYtKtJi5IMN7xelSF6TqEU3s3_7RF-Y,327
9
+ dashscope/version.py,sha256=sYFfnMKW3_pCoUqTSWWoBwqO-qPtJaDtBAgvBJqMx4I,23
10
+ dashscope/aigc/__init__.py,sha256=xmdalVw7wS0cLIuU8Q0qk0q8XGw-iGk8NnQwAQZ3jAc,391
11
11
  dashscope/aigc/code_generation.py,sha256=KAJVrGp6tiNFBBg64Ovs9RfcP5SrIhrbW3wdA89NKso,10885
12
12
  dashscope/aigc/conversation.py,sha256=xRoJlCR-IXHjSdkDrK74a9ut1FJg0FZhTNXZAJC18MA,14231
13
13
  dashscope/aigc/generation.py,sha256=53oMCmN5ZbqeqAsKxmdunXlRh-XP8ZtnA7hB2id4Koo,17897
14
14
  dashscope/aigc/image_synthesis.py,sha256=UWHW-nvf7_aDZKr4uZDusVHjqWr9TSZjCsZI8YSWaek,11052
15
15
  dashscope/aigc/multimodal_conversation.py,sha256=SlNnnsUPV19gdx8fYJAtsMFWPNGY6vhk5IGHZ5ZczpI,5369
16
+ dashscope/aigc/video_synthesis.py,sha256=gbp5XG_DMVN0JnBOgxftdwsCIyrV7nM2gVnlyO8X-ek,10400
16
17
  dashscope/api_entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
18
  dashscope/api_entities/aiohttp_request.py,sha256=aE3AeWba8Ig_xHMYjrAdkq0N61l_L2VFTG6HYh912X0,10229
18
19
  dashscope/api_entities/api_request_data.py,sha256=JUMcfpJjKXEZLCBSFIDpgoaeQYk5uK9-CwhM4OHIHFQ,5463
19
20
  dashscope/api_entities/api_request_factory.py,sha256=j4VOA1qKzvsK6-BOHGyA35oqsMkNoc4xZe9GHefV0fU,4947
20
21
  dashscope/api_entities/base_request.py,sha256=cXUL7xqSV8wBr5d-1kx65AO3IsRR9A_ps6Lok-v-MKM,926
21
- dashscope/api_entities/dashscope_response.py,sha256=Bp1T7HwVlkOvpMNg-AEjz-BScxhLUXMXlE8ApXTtfhQ,17872
22
+ dashscope/api_entities/dashscope_response.py,sha256=4a8Iya8RBUnVdzGmzoj6NvaaEeEnodGAD7evBrqEXfU,19832
22
23
  dashscope/api_entities/http_request.py,sha256=pYE8qRMu9CaQDiugPlXeYoaj_diBv-ZDExCD3WNhehI,13259
23
24
  dashscope/api_entities/websocket_request.py,sha256=Xr6IJ9WqrIw5ouBQLpgoRSwL1C09jkb4u1EZdxhVQy0,15039
24
25
  dashscope/app/__init__.py,sha256=UiN_9i--z84Dw5wUehOh_Tkk_9Gq_td_Kbz1dobBEKg,62
@@ -84,10 +85,10 @@ dashscope/tokenizers/tokenization.py,sha256=G6cSEmVLr3pjXUC3EOU9ot8MYxNnOQ4wOB2m
84
85
  dashscope/tokenizers/tokenizer.py,sha256=y6P91qTCYo__pEx_0VHAcj9YECfbUdRqZU1fdGTjF4o,1154
85
86
  dashscope/tokenizers/tokenizer_base.py,sha256=REDhzRyDT13iequ61-a6_KcTy0GFKlihQve5HkyoyRs,656
86
87
  dashscope/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
87
- dashscope/utils/oss_utils.py,sha256=7vZ2Lypxwiit8VcAqAvr3cCyhVfaLapDiNuF-H3ZCD4,7332
88
- dashscope-1.20.14.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
89
- dashscope-1.20.14.dist-info/METADATA,sha256=BjqLaIu_UNVWxAYRXU8wsrrr4I8qsr08dUtKcm-LGyY,6642
90
- dashscope-1.20.14.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
91
- dashscope-1.20.14.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
92
- dashscope-1.20.14.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
93
- dashscope-1.20.14.dist-info/RECORD,,
88
+ dashscope/utils/oss_utils.py,sha256=Ci_3gkvVGq_2kWzDA90lM7VoMoewAvCkoFcQTbPj8bI,7332
89
+ dashscope-1.21.0.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
90
+ dashscope-1.21.0.dist-info/METADATA,sha256=vIJ9LChy9z3oLteT9IifLTqwTceHE8SMO7_ymLMJU3A,6641
91
+ dashscope-1.21.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
92
+ dashscope-1.21.0.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
93
+ dashscope-1.21.0.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
94
+ dashscope-1.21.0.dist-info/RECORD,,