dashscope 1.8.0__py3-none-any.whl → 1.25.6__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 (110) hide show
  1. dashscope/__init__.py +61 -14
  2. dashscope/aigc/__init__.py +10 -3
  3. dashscope/aigc/chat_completion.py +282 -0
  4. dashscope/aigc/code_generation.py +145 -0
  5. dashscope/aigc/conversation.py +71 -12
  6. dashscope/aigc/generation.py +288 -16
  7. dashscope/aigc/image_synthesis.py +473 -31
  8. dashscope/aigc/multimodal_conversation.py +299 -14
  9. dashscope/aigc/video_synthesis.py +610 -0
  10. dashscope/api_entities/aiohttp_request.py +8 -5
  11. dashscope/api_entities/api_request_data.py +4 -2
  12. dashscope/api_entities/api_request_factory.py +68 -20
  13. dashscope/api_entities/base_request.py +20 -3
  14. dashscope/api_entities/chat_completion_types.py +344 -0
  15. dashscope/api_entities/dashscope_response.py +243 -15
  16. dashscope/api_entities/encryption.py +179 -0
  17. dashscope/api_entities/http_request.py +216 -62
  18. dashscope/api_entities/websocket_request.py +43 -34
  19. dashscope/app/__init__.py +5 -0
  20. dashscope/app/application.py +203 -0
  21. dashscope/app/application_response.py +246 -0
  22. dashscope/assistants/__init__.py +16 -0
  23. dashscope/assistants/assistant_types.py +175 -0
  24. dashscope/assistants/assistants.py +311 -0
  25. dashscope/assistants/files.py +197 -0
  26. dashscope/audio/__init__.py +4 -2
  27. dashscope/audio/asr/__init__.py +17 -1
  28. dashscope/audio/asr/asr_phrase_manager.py +203 -0
  29. dashscope/audio/asr/recognition.py +167 -27
  30. dashscope/audio/asr/transcription.py +107 -14
  31. dashscope/audio/asr/translation_recognizer.py +1006 -0
  32. dashscope/audio/asr/vocabulary.py +177 -0
  33. dashscope/audio/qwen_asr/__init__.py +7 -0
  34. dashscope/audio/qwen_asr/qwen_transcription.py +189 -0
  35. dashscope/audio/qwen_omni/__init__.py +11 -0
  36. dashscope/audio/qwen_omni/omni_realtime.py +524 -0
  37. dashscope/audio/qwen_tts/__init__.py +5 -0
  38. dashscope/audio/qwen_tts/speech_synthesizer.py +77 -0
  39. dashscope/audio/qwen_tts_realtime/__init__.py +10 -0
  40. dashscope/audio/qwen_tts_realtime/qwen_tts_realtime.py +355 -0
  41. dashscope/audio/tts/__init__.py +2 -0
  42. dashscope/audio/tts/speech_synthesizer.py +5 -0
  43. dashscope/audio/tts_v2/__init__.py +12 -0
  44. dashscope/audio/tts_v2/enrollment.py +179 -0
  45. dashscope/audio/tts_v2/speech_synthesizer.py +886 -0
  46. dashscope/cli.py +157 -37
  47. dashscope/client/base_api.py +652 -87
  48. dashscope/common/api_key.py +2 -0
  49. dashscope/common/base_type.py +135 -0
  50. dashscope/common/constants.py +13 -16
  51. dashscope/common/env.py +2 -0
  52. dashscope/common/error.py +58 -22
  53. dashscope/common/logging.py +2 -0
  54. dashscope/common/message_manager.py +2 -0
  55. dashscope/common/utils.py +276 -46
  56. dashscope/customize/__init__.py +0 -0
  57. dashscope/customize/customize_types.py +192 -0
  58. dashscope/customize/deployments.py +146 -0
  59. dashscope/customize/finetunes.py +234 -0
  60. dashscope/embeddings/__init__.py +5 -1
  61. dashscope/embeddings/batch_text_embedding.py +208 -0
  62. dashscope/embeddings/batch_text_embedding_response.py +65 -0
  63. dashscope/embeddings/multimodal_embedding.py +118 -10
  64. dashscope/embeddings/text_embedding.py +13 -1
  65. dashscope/{file.py → files.py} +19 -4
  66. dashscope/io/input_output.py +2 -0
  67. dashscope/model.py +11 -2
  68. dashscope/models.py +43 -0
  69. dashscope/multimodal/__init__.py +20 -0
  70. dashscope/multimodal/dialog_state.py +56 -0
  71. dashscope/multimodal/multimodal_constants.py +28 -0
  72. dashscope/multimodal/multimodal_dialog.py +648 -0
  73. dashscope/multimodal/multimodal_request_params.py +313 -0
  74. dashscope/multimodal/tingwu/__init__.py +10 -0
  75. dashscope/multimodal/tingwu/tingwu.py +80 -0
  76. dashscope/multimodal/tingwu/tingwu_realtime.py +579 -0
  77. dashscope/nlp/__init__.py +0 -0
  78. dashscope/nlp/understanding.py +64 -0
  79. dashscope/protocol/websocket.py +3 -0
  80. dashscope/rerank/__init__.py +0 -0
  81. dashscope/rerank/text_rerank.py +69 -0
  82. dashscope/resources/qwen.tiktoken +151643 -0
  83. dashscope/threads/__init__.py +26 -0
  84. dashscope/threads/messages/__init__.py +0 -0
  85. dashscope/threads/messages/files.py +113 -0
  86. dashscope/threads/messages/messages.py +220 -0
  87. dashscope/threads/runs/__init__.py +0 -0
  88. dashscope/threads/runs/runs.py +501 -0
  89. dashscope/threads/runs/steps.py +112 -0
  90. dashscope/threads/thread_types.py +665 -0
  91. dashscope/threads/threads.py +212 -0
  92. dashscope/tokenizers/__init__.py +7 -0
  93. dashscope/tokenizers/qwen_tokenizer.py +111 -0
  94. dashscope/tokenizers/tokenization.py +125 -0
  95. dashscope/tokenizers/tokenizer.py +45 -0
  96. dashscope/tokenizers/tokenizer_base.py +32 -0
  97. dashscope/utils/__init__.py +0 -0
  98. dashscope/utils/message_utils.py +838 -0
  99. dashscope/utils/oss_utils.py +243 -0
  100. dashscope/utils/param_utils.py +29 -0
  101. dashscope/version.py +3 -1
  102. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/METADATA +53 -50
  103. dashscope-1.25.6.dist-info/RECORD +112 -0
  104. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/WHEEL +1 -1
  105. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/entry_points.txt +0 -1
  106. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info/licenses}/LICENSE +2 -4
  107. dashscope/deployment.py +0 -129
  108. dashscope/finetune.py +0 -149
  109. dashscope-1.8.0.dist-info/RECORD +0 -49
  110. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/top_level.txt +0 -0
@@ -1,11 +1,14 @@
1
- from typing import Any, List, Union
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
3
+ from typing import Any, Dict, List, Union
2
4
 
3
5
  from dashscope.api_entities.dashscope_response import (DashScopeAPIResponse,
4
6
  ImageSynthesisResponse)
5
- from dashscope.client.base_api import BaseAsyncApi
7
+ from dashscope.client.base_api import BaseAsyncApi, BaseApi, BaseAsyncAioApi, BaseAioApi
6
8
  from dashscope.common.constants import IMAGES, NEGATIVE_PROMPT, PROMPT
7
9
  from dashscope.common.error import InputRequired
8
10
  from dashscope.common.utils import _get_task_group_and_task
11
+ from dashscope.utils.oss_utils import check_and_upload_local
9
12
 
10
13
 
11
14
  class ImageSynthesis(BaseAsyncApi):
@@ -14,6 +17,9 @@ class ImageSynthesis(BaseAsyncApi):
14
17
  """
15
18
  class Models:
16
19
  wanx_v1 = 'wanx-v1'
20
+ wanx_sketch_to_image_v1 = 'wanx-sketch-to-image-v1'
21
+
22
+ wanx_2_1_imageedit = 'wanx2.1-imageedit'
17
23
 
18
24
  @classmethod
19
25
  def call(cls,
@@ -22,6 +28,14 @@ class ImageSynthesis(BaseAsyncApi):
22
28
  negative_prompt: Any = None,
23
29
  images: List[str] = None,
24
30
  api_key: str = None,
31
+ sketch_image_url: str = None,
32
+ ref_img: str = None,
33
+ workspace: str = None,
34
+ extra_input: Dict = None,
35
+ task: str = None,
36
+ function: str = None,
37
+ mask_image_url: str = None,
38
+ base_image_url: str = None,
25
39
  **kwargs) -> ImageSynthesisResponse:
26
40
  """Call image(s) synthesis service and get result.
27
41
 
@@ -29,16 +43,30 @@ class ImageSynthesis(BaseAsyncApi):
29
43
  model (str): The model, reference ``Models``.
30
44
  prompt (Any): The prompt for image(s) synthesis.
31
45
  negative_prompt (Any): The negative_prompt. Defaults to None.
32
- images (List[str]): The input list of images url.
46
+ images (List[str]): The input list of images url,
47
+ currently not supported.
33
48
  api_key (str, optional): The api api_key. Defaults to None.
49
+ sketch_image_url (str, optional): Only for wanx-sketch-to-image-v1,
50
+ can be local file.
51
+ Defaults to None.
52
+ workspace (str): The dashscope workspace id.
53
+ extra_input (Dict): The extra input parameters.
54
+ task (str): The task of api, ref doc.
55
+ function (str): The specific functions to be achieved. like:
56
+ colorization,super_resolution,expand,remove_watermaker,doodle,
57
+ description_edit_with_mask,description_edit,stylization_local,stylization_all
58
+ base_image_url (str): Enter the URL address of the target edited image.
59
+ mask_image_url (str): Provide the URL address of the image of the marked area by the user. It should be consistent with the image resolution of the base_image_url.
34
60
  **kwargs:
35
- n(int, `optional`): Number of images to synthesis,
36
- Currently fixed at 4.
37
- size(str, `optional`): The output image(s) size(width*height),
38
- Currently fixed at 1024*1024. Default 1024*1024
61
+ n(int, `optional`): Number of images to synthesis.
62
+ size(str, `optional`): The output image(s) size(width*height).
39
63
  similarity(float, `optional`): The similarity between the
40
64
  output image and the input image
41
-
65
+ sketch_weight(int, optional): How much the input sketch
66
+ affects the output image[0-10], only for wanx-sketch-to-image-v1. # noqa E501
67
+ Default 10.
68
+ realisticness(int, optional): The realisticness of the output
69
+ image[0-10], only for wanx-sketch-to-image-v1. Default 5
42
70
 
43
71
  Raises:
44
72
  InputRequired: The prompt cannot be empty.
@@ -46,9 +74,136 @@ class ImageSynthesis(BaseAsyncApi):
46
74
  Returns:
47
75
  ImageSynthesisResponse: The image(s) synthesis result.
48
76
  """
49
- return super().call(model, prompt, negative_prompt, images, api_key,
77
+ return super().call(model,
78
+ prompt,
79
+ negative_prompt,
80
+ images,
81
+ api_key=api_key,
82
+ sketch_image_url=sketch_image_url,
83
+ ref_img=ref_img,
84
+ workspace=workspace,
85
+ extra_input=extra_input,
86
+ task=task,
87
+ function=function,
88
+ mask_image_url=mask_image_url,
89
+ base_image_url=base_image_url,
50
90
  **kwargs)
51
91
 
92
+ @classmethod
93
+ def sync_call(cls,
94
+ model: str,
95
+ prompt: Any,
96
+ negative_prompt: Any = None,
97
+ images: List[str] = None,
98
+ api_key: str = None,
99
+ sketch_image_url: str = None,
100
+ ref_img: str = None,
101
+ workspace: str = None,
102
+ extra_input: Dict = None,
103
+ task: str = None,
104
+ function: str = None,
105
+ mask_image_url: str = None,
106
+ base_image_url: str = None,
107
+ **kwargs) -> ImageSynthesisResponse:
108
+ """
109
+ Note: This method currently now only supports wan2.2-t2i-flash and wan2.2-t2i-plus.
110
+ Using other models will result in an error,More raw image models may be added for use later
111
+ """
112
+ task_group, f = _get_task_group_and_task(__name__)
113
+ inputs, kwargs, task = cls._get_input(model, prompt, negative_prompt,
114
+ images, api_key, sketch_image_url,
115
+ ref_img, extra_input, task, function,
116
+ mask_image_url, base_image_url, **kwargs)
117
+ response = BaseApi.call(model, inputs, task_group, task, f, api_key, workspace, **kwargs)
118
+ return ImageSynthesisResponse.from_api_response(response)
119
+
120
+ @classmethod
121
+ def _get_input(cls,
122
+ model: str,
123
+ prompt: Any,
124
+ negative_prompt: Any = None,
125
+ images: List[str] = None,
126
+ api_key: str = None,
127
+ sketch_image_url: str = None,
128
+ ref_img: str = None,
129
+ extra_input: Dict = None,
130
+ task: str = None,
131
+ function: str = None,
132
+ mask_image_url: str = None,
133
+ base_image_url: str = None,
134
+ **kwargs):
135
+ if prompt is None or not prompt:
136
+ raise InputRequired('prompt is required!')
137
+ inputs = {PROMPT: prompt}
138
+ has_upload = False
139
+ upload_certificate = None
140
+
141
+ if negative_prompt is not None:
142
+ inputs[NEGATIVE_PROMPT] = negative_prompt
143
+ if images is not None and images and len(images) > 0:
144
+ new_images = []
145
+ for image in images:
146
+ is_upload, new_image, upload_certificate = check_and_upload_local(
147
+ model, image, api_key, upload_certificate)
148
+ if is_upload:
149
+ has_upload = True
150
+ new_images.append(new_image)
151
+ inputs[IMAGES] = new_images
152
+ if sketch_image_url is not None and sketch_image_url:
153
+ is_upload, sketch_image_url, upload_certificate = check_and_upload_local(
154
+ model, sketch_image_url, api_key, upload_certificate)
155
+ if is_upload:
156
+ has_upload = True
157
+ inputs['sketch_image_url'] = sketch_image_url
158
+ if ref_img is not None and ref_img:
159
+ is_upload, ref_img, upload_certificate = check_and_upload_local(
160
+ model, ref_img, api_key, upload_certificate)
161
+ if is_upload:
162
+ has_upload = True
163
+ inputs['ref_img'] = ref_img
164
+
165
+ if function is not None and function:
166
+ inputs['function'] = function
167
+
168
+ if mask_image_url is not None and mask_image_url:
169
+ is_upload, res_mask_image_url, upload_certificate = check_and_upload_local(
170
+ model, mask_image_url, api_key, upload_certificate)
171
+ if is_upload:
172
+ has_upload = True
173
+ inputs['mask_image_url'] = res_mask_image_url
174
+
175
+ if base_image_url is not None and base_image_url:
176
+ is_upload, res_base_image_url, upload_certificate = check_and_upload_local(
177
+ model, base_image_url, api_key, upload_certificate)
178
+ if is_upload:
179
+ has_upload = True
180
+ inputs['base_image_url'] = res_base_image_url
181
+
182
+ if extra_input is not None and extra_input:
183
+ inputs = {**inputs, **extra_input}
184
+
185
+ if has_upload:
186
+ headers = kwargs.pop('headers', {})
187
+ headers['X-DashScope-OssResourceResolve'] = 'enable'
188
+ kwargs['headers'] = headers
189
+
190
+ def __get_i2i_task(task, model) -> str:
191
+ # 处理task参数:优先使用有效的task值
192
+ if task is not None and task != "":
193
+ return task
194
+
195
+ # 根据model确定任务类型
196
+ if model is not None and model != "":
197
+ if 'imageedit' in model or "wan2.5-i2i" in model:
198
+ return 'image2image'
199
+
200
+ # 默认返回文本到图像任务
201
+ return ImageSynthesis.task
202
+
203
+ task = __get_i2i_task(task, model)
204
+
205
+ return inputs, kwargs, task
206
+
52
207
  @classmethod
53
208
  def async_call(cls,
54
209
  model: str,
@@ -56,6 +211,14 @@ class ImageSynthesis(BaseAsyncApi):
56
211
  negative_prompt: Any = None,
57
212
  images: List[str] = None,
58
213
  api_key: str = None,
214
+ sketch_image_url: str = None,
215
+ ref_img: str = None,
216
+ workspace: str = None,
217
+ extra_input: Dict = None,
218
+ task: str = None,
219
+ function: str = None,
220
+ mask_image_url: str = None,
221
+ base_image_url: str = None,
59
222
  **kwargs) -> ImageSynthesisResponse:
60
223
  """Create a image(s) synthesis task, and return task information.
61
224
 
@@ -65,11 +228,26 @@ class ImageSynthesis(BaseAsyncApi):
65
228
  negative_prompt (Any): The negative_prompt. Defaults to None.
66
229
  images (List[str]): The input list of images url.
67
230
  api_key (str, optional): The api api_key. Defaults to None.
231
+ sketch_image_url (str, optional): Only for wanx-sketch-to-image-v1.
232
+ Defaults to None.
233
+ workspace (str): The dashscope workspace id.
234
+ extra_input (Dict): The extra input parameters.
235
+ task (str): The task of api, ref doc.
236
+ function (str): The specific functions to be achieved. like:
237
+ colorization,super_resolution,expand,remove_watermaker,doodle,
238
+ description_edit_with_mask,description_edit,stylization_local,stylization_all
239
+ base_image_url (str): Enter the URL address of the target edited image.
240
+ mask_image_url (str): Provide the URL address of the image of the marked area by the user. It should be consistent with the image resolution of the base_image_url.
68
241
  **kwargs(wanx-v1):
69
242
  n(int, `optional`): Number of images to synthesis.
70
243
  size: The output image(s) size, Default 1024*1024
71
244
  similarity(float, `optional`): The similarity between the
72
- output image and the input image
245
+ output image and the input image.
246
+ sketch_weight(int, optional): How much the input sketch
247
+ affects the output image[0-10], only for wanx-sketch-to-image-v1. # noqa E501
248
+ Default 10.
249
+ realisticness(int, optional): The realisticness of the output
250
+ image[0-10], only for wanx-sketch-to-image-v1. Default 5
73
251
 
74
252
  Raises:
75
253
  InputRequired: The prompt cannot be empty.
@@ -78,61 +256,65 @@ class ImageSynthesis(BaseAsyncApi):
78
256
  DashScopeAPIResponse: The image synthesis
79
257
  task id in the response.
80
258
  """
81
- if prompt is None or not prompt:
82
- raise InputRequired('prompt is required!')
83
- task_group, function = _get_task_group_and_task(__name__)
84
- input = {PROMPT: prompt}
85
- if negative_prompt is not None:
86
- input[NEGATIVE_PROMPT] = negative_prompt
87
- if images is not None:
88
- input[IMAGES] = images
89
- response = super().async_call(model=model,
90
- task_group=task_group,
91
- task=ImageSynthesis.task,
92
- function=function,
93
- api_key=api_key,
94
- input=input,
95
- **kwargs)
259
+ task_group, f = _get_task_group_and_task(__name__)
260
+ inputs, kwargs, task = cls._get_input(model, prompt, negative_prompt,
261
+ images, api_key, sketch_image_url,
262
+ ref_img, extra_input, task, function,
263
+ mask_image_url, base_image_url, **kwargs)
264
+ response = super().async_call(
265
+ model=model,
266
+ task_group=task_group,
267
+ task=task,
268
+ function=f,
269
+ api_key=api_key,
270
+ input=inputs,
271
+ workspace=workspace,
272
+ **kwargs)
96
273
  return ImageSynthesisResponse.from_api_response(response)
97
274
 
98
275
  @classmethod
99
276
  def fetch(cls,
100
277
  task: Union[str, ImageSynthesisResponse],
101
- api_key: str = None) -> ImageSynthesisResponse:
278
+ api_key: str = None,
279
+ workspace: str = None) -> ImageSynthesisResponse:
102
280
  """Fetch image(s) synthesis task status or result.
103
281
 
104
282
  Args:
105
283
  task (Union[str, ImageSynthesisResponse]): The task_id or
106
284
  ImageSynthesisResponse return by async_call().
107
285
  api_key (str, optional): The api api_key. Defaults to None.
286
+ workspace (str): The dashscope workspace id.
108
287
 
109
288
  Returns:
110
289
  ImageSynthesisResponse: The task status or result.
111
290
  """
112
- response = super().fetch(task, api_key)
291
+ response = super().fetch(task, api_key=api_key, workspace=workspace)
113
292
  return ImageSynthesisResponse.from_api_response(response)
114
293
 
115
294
  @classmethod
116
295
  def wait(cls,
117
296
  task: Union[str, ImageSynthesisResponse],
118
- api_key: str = None) -> ImageSynthesisResponse:
297
+ api_key: str = None,
298
+ workspace: str = None) -> ImageSynthesisResponse:
119
299
  """Wait for image(s) synthesis task to complete, and return the result.
120
300
 
121
301
  Args:
122
302
  task (Union[str, ImageSynthesisResponse]): The task_id or
123
303
  ImageSynthesisResponse return by async_call().
124
304
  api_key (str, optional): The api api_key. Defaults to None.
305
+ workspace (str): The dashscope workspace id.
125
306
 
126
307
  Returns:
127
308
  ImageSynthesisResponse: The task result.
128
309
  """
129
- response = super().wait(task, api_key)
310
+ response = super().wait(task, api_key, workspace=workspace)
130
311
  return ImageSynthesisResponse.from_api_response(response)
131
312
 
132
313
  @classmethod
133
314
  def cancel(cls,
134
315
  task: Union[str, ImageSynthesisResponse],
135
- api_key: str = None) -> DashScopeAPIResponse:
316
+ api_key: str = None,
317
+ workspace: str = None) -> DashScopeAPIResponse:
136
318
  """Cancel image synthesis task.
137
319
  Only tasks whose status is PENDING can be canceled.
138
320
 
@@ -140,11 +322,12 @@ class ImageSynthesis(BaseAsyncApi):
140
322
  task (Union[str, ImageSynthesisResponse]): The task_id or
141
323
  ImageSynthesisResponse return by async_call().
142
324
  api_key (str, optional): The api api_key. Defaults to None.
325
+ workspace (str): The dashscope workspace id.
143
326
 
144
327
  Returns:
145
328
  DashScopeAPIResponse: The response data.
146
329
  """
147
- return super().cancel(task, api_key)
330
+ return super().cancel(task, api_key, workspace=workspace)
148
331
 
149
332
  @classmethod
150
333
  def list(cls,
@@ -157,6 +340,7 @@ class ImageSynthesis(BaseAsyncApi):
157
340
  page_no: int = 1,
158
341
  page_size: int = 10,
159
342
  api_key: str = None,
343
+ workspace: str = None,
160
344
  **kwargs) -> DashScopeAPIResponse:
161
345
  """List async tasks.
162
346
 
@@ -174,6 +358,7 @@ class ImageSynthesis(BaseAsyncApi):
174
358
  page_no (int, optional): The page number. Defaults to 1.
175
359
  page_size (int, optional): The page size. Defaults to 10.
176
360
  api_key (str, optional): The user api-key. Defaults to None.
361
+ workspace (str): The dashscope workspace id.
177
362
 
178
363
  Returns:
179
364
  DashScopeAPIResponse: The response data.
@@ -187,4 +372,261 @@ class ImageSynthesis(BaseAsyncApi):
187
372
  page_no=page_no,
188
373
  page_size=page_size,
189
374
  api_key=api_key,
375
+ workspace=workspace,
190
376
  **kwargs)
377
+
378
+ class AioImageSynthesis(BaseAsyncAioApi):
379
+ @classmethod
380
+ async def call(cls,
381
+ model: str,
382
+ prompt: Any,
383
+ negative_prompt: Any = None,
384
+ images: List[str] = None,
385
+ api_key: str = None,
386
+ sketch_image_url: str = None,
387
+ ref_img: str = None,
388
+ workspace: str = None,
389
+ extra_input: Dict = None,
390
+ task: str = None,
391
+ function: str = None,
392
+ mask_image_url: str = None,
393
+ base_image_url: str = None,
394
+ **kwargs) -> ImageSynthesisResponse:
395
+ """Call image(s) synthesis service and get result.
396
+
397
+ Args:
398
+ model (str): The model, reference ``Models``.
399
+ prompt (Any): The prompt for image(s) synthesis.
400
+ negative_prompt (Any): The negative_prompt. Defaults to None.
401
+ images (List[str]): The input list of images url,
402
+ currently not supported.
403
+ api_key (str, optional): The api api_key. Defaults to None.
404
+ sketch_image_url (str, optional): Only for wanx-sketch-to-image-v1,
405
+ can be local file.
406
+ Defaults to None.
407
+ workspace (str): The dashscope workspace id.
408
+ extra_input (Dict): The extra input parameters.
409
+ task (str): The task of api, ref doc.
410
+ function (str): The specific functions to be achieved. like:
411
+ colorization,super_resolution,expand,remove_watermaker,doodle,
412
+ description_edit_with_mask,description_edit,stylization_local,stylization_all
413
+ base_image_url (str): Enter the URL address of the target edited image.
414
+ mask_image_url (str): Provide the URL address of the image of the marked area by the user. It should be consistent with the image resolution of the base_image_url.
415
+ **kwargs:
416
+ n(int, `optional`): Number of images to synthesis.
417
+ size(str, `optional`): The output image(s) size(width*height).
418
+ similarity(float, `optional`): The similarity between the
419
+ output image and the input image
420
+ sketch_weight(int, optional): How much the input sketch
421
+ affects the output image[0-10], only for wanx-sketch-to-image-v1. # noqa E501
422
+ Default 10.
423
+ realisticness(int, optional): The realisticness of the output
424
+ image[0-10], only for wanx-sketch-to-image-v1. Default 5
425
+
426
+ Raises:
427
+ InputRequired: The prompt cannot be empty.
428
+
429
+ Returns:
430
+ ImageSynthesisResponse: The image(s) synthesis result.
431
+ """
432
+ task_group, f = _get_task_group_and_task(__name__)
433
+ inputs, kwargs, task = ImageSynthesis._get_input(model, prompt, negative_prompt,
434
+ images, api_key, sketch_image_url,
435
+ ref_img, extra_input, task, function,
436
+ mask_image_url, base_image_url, **kwargs)
437
+ response = await super().call(model, inputs, task_group, task, f, api_key, workspace, **kwargs)
438
+ return ImageSynthesisResponse.from_api_response(response)
439
+
440
+ @classmethod
441
+ async def sync_call(cls,
442
+ model: str,
443
+ prompt: Any,
444
+ negative_prompt: Any = None,
445
+ images: List[str] = None,
446
+ api_key: str = None,
447
+ sketch_image_url: str = None,
448
+ ref_img: str = None,
449
+ workspace: str = None,
450
+ extra_input: Dict = None,
451
+ task: str = None,
452
+ function: str = None,
453
+ mask_image_url: str = None,
454
+ base_image_url: str = None,
455
+ **kwargs) -> ImageSynthesisResponse:
456
+ """
457
+ Note: This method currently now only supports wan2.2-t2i-flash and wan2.2-t2i-plus.
458
+ Using other models will result in an error,More raw image models may be added for use later
459
+ """
460
+ task_group, f = _get_task_group_and_task(__name__)
461
+ inputs, kwargs, task = ImageSynthesis._get_input(model, prompt, negative_prompt,
462
+ images, api_key, sketch_image_url,
463
+ ref_img, extra_input, task, function,
464
+ mask_image_url, base_image_url, **kwargs)
465
+ response = await BaseAioApi.call(model, inputs, task_group, task, f, api_key, workspace, **kwargs)
466
+ return ImageSynthesisResponse.from_api_response(response)
467
+
468
+ @classmethod
469
+ async def async_call(cls,
470
+ model: str,
471
+ prompt: Any,
472
+ negative_prompt: Any = None,
473
+ images: List[str] = None,
474
+ api_key: str = None,
475
+ sketch_image_url: str = None,
476
+ ref_img: str = None,
477
+ workspace: str = None,
478
+ extra_input: Dict = None,
479
+ task: str = None,
480
+ function: str = None,
481
+ mask_image_url: str = None,
482
+ base_image_url: str = None,
483
+ **kwargs) -> ImageSynthesisResponse:
484
+ """Create a image(s) synthesis task, and return task information.
485
+
486
+ Args:
487
+ model (str): The model, reference ``Models``.
488
+ prompt (Any): The prompt for image(s) synthesis.
489
+ negative_prompt (Any): The negative_prompt. Defaults to None.
490
+ images (List[str]): The input list of images url.
491
+ api_key (str, optional): The api api_key. Defaults to None.
492
+ sketch_image_url (str, optional): Only for wanx-sketch-to-image-v1.
493
+ Defaults to None.
494
+ workspace (str): The dashscope workspace id.
495
+ extra_input (Dict): The extra input parameters.
496
+ task (str): The task of api, ref doc.
497
+ function (str): The specific functions to be achieved. like:
498
+ colorization,super_resolution,expand,remove_watermaker,doodle,
499
+ description_edit_with_mask,description_edit,stylization_local,stylization_all
500
+ base_image_url (str): Enter the URL address of the target edited image.
501
+ mask_image_url (str): Provide the URL address of the image of the marked area by the user. It should be consistent with the image resolution of the base_image_url.
502
+ **kwargs(wanx-v1):
503
+ n(int, `optional`): Number of images to synthesis.
504
+ size: The output image(s) size, Default 1024*1024
505
+ similarity(float, `optional`): The similarity between the
506
+ output image and the input image.
507
+ sketch_weight(int, optional): How much the input sketch
508
+ affects the output image[0-10], only for wanx-sketch-to-image-v1. # noqa E501
509
+ Default 10.
510
+ realisticness(int, optional): The realisticness of the output
511
+ image[0-10], only for wanx-sketch-to-image-v1. Default 5
512
+
513
+ Raises:
514
+ InputRequired: The prompt cannot be empty.
515
+
516
+ Returns:
517
+ DashScopeAPIResponse: The image synthesis
518
+ task id in the response.
519
+ """
520
+ task_group, f = _get_task_group_and_task(__name__)
521
+ inputs, kwargs, task = ImageSynthesis._get_input(model, prompt, negative_prompt,
522
+ images, api_key, sketch_image_url,
523
+ ref_img, extra_input, task, function,
524
+ mask_image_url, base_image_url, **kwargs)
525
+ response = await super().async_call(model, inputs, task_group, task, f, api_key, workspace, **kwargs)
526
+ return ImageSynthesisResponse.from_api_response(response)
527
+
528
+ @classmethod
529
+ async def fetch(cls,
530
+ task: Union[str, ImageSynthesisResponse],
531
+ api_key: str = None,
532
+ workspace: str = None,
533
+ **kwargs,) -> ImageSynthesisResponse:
534
+ """Fetch image(s) synthesis task status or result.
535
+
536
+ Args:
537
+ task (Union[str, ImageSynthesisResponse]): The task_id or
538
+ ImageSynthesisResponse return by async_call().
539
+ api_key (str, optional): The api api_key. Defaults to None.
540
+ workspace (str): The dashscope workspace id.
541
+
542
+ Returns:
543
+ ImageSynthesisResponse: The task status or result.
544
+ """
545
+ response = await super().fetch(task, api_key=api_key, workspace=workspace)
546
+ return ImageSynthesisResponse.from_api_response(response)
547
+
548
+ @classmethod
549
+ async def wait(cls,
550
+ task: Union[str, ImageSynthesisResponse],
551
+ api_key: str = None,
552
+ workspace: str = None,
553
+ **kwargs) -> ImageSynthesisResponse:
554
+ """Wait for image(s) synthesis task to complete, and return the result.
555
+
556
+ Args:
557
+ task (Union[str, ImageSynthesisResponse]): The task_id or
558
+ ImageSynthesisResponse return by async_call().
559
+ api_key (str, optional): The api api_key. Defaults to None.
560
+ workspace (str): The dashscope workspace id.
561
+
562
+ Returns:
563
+ ImageSynthesisResponse: The task result.
564
+ """
565
+ response = await super().wait(task, api_key, workspace=workspace)
566
+ return ImageSynthesisResponse.from_api_response(response)
567
+
568
+ @classmethod
569
+ async def cancel(cls,
570
+ task: Union[str, ImageSynthesisResponse],
571
+ api_key: str = None,
572
+ workspace: str = None,
573
+ **kwargs,) -> DashScopeAPIResponse:
574
+ """Cancel image synthesis task.
575
+ Only tasks whose status is PENDING can be canceled.
576
+
577
+ Args:
578
+ task (Union[str, ImageSynthesisResponse]): The task_id or
579
+ ImageSynthesisResponse return by async_call().
580
+ api_key (str, optional): The api api_key. Defaults to None.
581
+ workspace (str): The dashscope workspace id.
582
+
583
+ Returns:
584
+ DashScopeAPIResponse: The response data.
585
+ """
586
+ return await super().cancel(task, api_key, workspace=workspace)
587
+
588
+ @classmethod
589
+ async def list(cls,
590
+ start_time: str = None,
591
+ end_time: str = None,
592
+ model_name: str = None,
593
+ api_key_id: str = None,
594
+ region: str = None,
595
+ status: str = None,
596
+ page_no: int = 1,
597
+ page_size: int = 10,
598
+ api_key: str = None,
599
+ workspace: str = None,
600
+ **kwargs) -> DashScopeAPIResponse:
601
+ """List async tasks.
602
+
603
+ Args:
604
+ start_time (str, optional): The tasks start time,
605
+ for example: 20230420000000. Defaults to None.
606
+ end_time (str, optional): The tasks end time,
607
+ for example: 20230420000000. Defaults to None.
608
+ model_name (str, optional): The tasks model name. Defaults to None.
609
+ api_key_id (str, optional): The tasks api-key-id. Defaults to None.
610
+ region (str, optional): The service region,
611
+ for example: cn-beijing. Defaults to None.
612
+ status (str, optional): The status of tasks[PENDING,
613
+ RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None.
614
+ page_no (int, optional): The page number. Defaults to 1.
615
+ page_size (int, optional): The page size. Defaults to 10.
616
+ api_key (str, optional): The user api-key. Defaults to None.
617
+ workspace (str): The dashscope workspace id.
618
+
619
+ Returns:
620
+ DashScopeAPIResponse: The response data.
621
+ """
622
+ return await super().list(start_time=start_time,
623
+ end_time=end_time,
624
+ model_name=model_name,
625
+ api_key_id=api_key_id,
626
+ region=region,
627
+ status=status,
628
+ page_no=page_no,
629
+ page_size=page_size,
630
+ api_key=api_key,
631
+ workspace=workspace,
632
+ **kwargs)