dashscope 1.20.13__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 +2 -0
- dashscope/aigc/__init__.py +2 -0
- dashscope/aigc/video_synthesis.py +242 -0
- dashscope/api_entities/dashscope_response.py +55 -0
- dashscope/app/application.py +35 -16
- dashscope/app/application_response.py +3 -0
- dashscope/audio/asr/vocabulary.py +2 -2
- dashscope/audio/tts_v2/enrollment.py +1 -1
- dashscope/client/base_api.py +3 -3
- dashscope/utils/oss_utils.py +2 -2
- dashscope/version.py +1 -1
- {dashscope-1.20.13.dist-info → dashscope-1.21.0.dist-info}/METADATA +1 -1
- {dashscope-1.20.13.dist-info → dashscope-1.21.0.dist-info}/RECORD +17 -16
- {dashscope-1.20.13.dist-info → dashscope-1.21.0.dist-info}/LICENSE +0 -0
- {dashscope-1.20.13.dist-info → dashscope-1.21.0.dist-info}/WHEEL +0 -0
- {dashscope-1.20.13.dist-info → dashscope-1.21.0.dist-info}/entry_points.txt +0 -0
- {dashscope-1.20.13.dist-info → dashscope-1.21.0.dist-info}/top_level.txt +0 -0
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())
|
dashscope/aigc/__init__.py
CHANGED
|
@@ -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
|
dashscope/app/application.py
CHANGED
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
@Date : 2024-02-24
|
|
5
5
|
@Desc : Application calls for both http and http sse
|
|
6
6
|
"""
|
|
7
|
-
|
|
7
|
+
import copy
|
|
8
|
+
from typing import Generator, Union, List
|
|
8
9
|
|
|
9
10
|
from dashscope.api_entities.api_request_factory import _build_api_request
|
|
10
11
|
from dashscope.app.application_response import ApplicationResponse
|
|
11
12
|
from dashscope.client.base_api import BaseApi
|
|
12
13
|
from dashscope.common.api_key import get_default_api_key
|
|
13
|
-
from dashscope.common.constants import HISTORY, PROMPT
|
|
14
|
+
from dashscope.common.constants import HISTORY, PROMPT, DEPRECATED_MESSAGE, MESSAGES
|
|
14
15
|
from dashscope.common.error import InputRequired, InvalidInput
|
|
16
|
+
from dashscope.api_entities.dashscope_response import Message, Role
|
|
17
|
+
from dashscope.common.logging import logger
|
|
15
18
|
|
|
16
19
|
|
|
17
20
|
class Application(BaseApi):
|
|
@@ -20,6 +23,7 @@ class Application(BaseApi):
|
|
|
20
23
|
"""API for app completion calls.
|
|
21
24
|
|
|
22
25
|
"""
|
|
26
|
+
|
|
23
27
|
class DocReferenceType:
|
|
24
28
|
""" doc reference type for rag completion """
|
|
25
29
|
|
|
@@ -31,21 +35,23 @@ class Application(BaseApi):
|
|
|
31
35
|
def _validate_params(cls, api_key, app_id):
|
|
32
36
|
if api_key is None:
|
|
33
37
|
api_key = get_default_api_key()
|
|
38
|
+
|
|
34
39
|
if app_id is None or not app_id:
|
|
35
40
|
raise InputRequired('App id is required!')
|
|
41
|
+
|
|
36
42
|
return api_key, app_id
|
|
37
43
|
|
|
38
44
|
@classmethod
|
|
39
45
|
def call(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
cls,
|
|
47
|
+
app_id: str,
|
|
48
|
+
prompt: str = None,
|
|
49
|
+
history: list = None,
|
|
50
|
+
workspace: str = None,
|
|
51
|
+
api_key: str = None,
|
|
52
|
+
messages: List[Message] = None,
|
|
53
|
+
**kwargs
|
|
54
|
+
) -> Union[ApplicationResponse, Generator[ApplicationResponse, None, None]]:
|
|
49
55
|
"""Call app completion service.
|
|
50
56
|
|
|
51
57
|
Args:
|
|
@@ -59,6 +65,7 @@ class Application(BaseApi):
|
|
|
59
65
|
workspace(str, `optional`): Workspace for app completion call
|
|
60
66
|
api_key (str, optional): The api api_key, can be None,
|
|
61
67
|
if None, will get by default rule(TODO: api key doc).
|
|
68
|
+
messages(list): The generation messages.
|
|
62
69
|
|
|
63
70
|
**kwargs:
|
|
64
71
|
stream(bool, `optional`): Enable server-sent events
|
|
@@ -112,8 +119,8 @@ class Application(BaseApi):
|
|
|
112
119
|
|
|
113
120
|
api_key, app_id = Application._validate_params(api_key, app_id)
|
|
114
121
|
|
|
115
|
-
if prompt is None or not prompt:
|
|
116
|
-
raise InputRequired('prompt is required!')
|
|
122
|
+
if (prompt is None or not prompt) and (messages is None or len(messages) == 0):
|
|
123
|
+
raise InputRequired('prompt or messages is required!')
|
|
117
124
|
|
|
118
125
|
if workspace is not None and workspace:
|
|
119
126
|
headers = kwargs.pop('headers', {})
|
|
@@ -121,7 +128,7 @@ class Application(BaseApi):
|
|
|
121
128
|
kwargs['headers'] = headers
|
|
122
129
|
|
|
123
130
|
input, parameters = cls._build_input_parameters(
|
|
124
|
-
prompt, history, **kwargs)
|
|
131
|
+
prompt, history, messages, **kwargs)
|
|
125
132
|
request = _build_api_request(model='',
|
|
126
133
|
input=input,
|
|
127
134
|
task_group=Application.task_group,
|
|
@@ -142,10 +149,22 @@ class Application(BaseApi):
|
|
|
142
149
|
return ApplicationResponse.from_api_response(response)
|
|
143
150
|
|
|
144
151
|
@classmethod
|
|
145
|
-
def _build_input_parameters(cls, prompt, history, **kwargs):
|
|
152
|
+
def _build_input_parameters(cls, prompt, history, messages, **kwargs):
|
|
146
153
|
parameters = {}
|
|
147
154
|
|
|
148
|
-
input_param = {
|
|
155
|
+
input_param = {}
|
|
156
|
+
if messages is not None:
|
|
157
|
+
msgs = copy.deepcopy(messages)
|
|
158
|
+
if prompt is not None and prompt:
|
|
159
|
+
msgs.append({'role': Role.USER, 'content': prompt})
|
|
160
|
+
input_param = {MESSAGES: msgs}
|
|
161
|
+
elif history is not None and history:
|
|
162
|
+
logger.warning(DEPRECATED_MESSAGE)
|
|
163
|
+
input_param[HISTORY] = history
|
|
164
|
+
if prompt is not None and prompt:
|
|
165
|
+
input_param[PROMPT] = prompt
|
|
166
|
+
else:
|
|
167
|
+
input_param[PROMPT] = prompt
|
|
149
168
|
|
|
150
169
|
session_id = kwargs.pop('session_id', None)
|
|
151
170
|
if session_id is not None and session_id:
|
|
@@ -68,6 +68,7 @@ class ApplicationDocReference(DictMixin):
|
|
|
68
68
|
text: str
|
|
69
69
|
biz_id: str
|
|
70
70
|
images: List[str]
|
|
71
|
+
page_number: List[int]
|
|
71
72
|
|
|
72
73
|
def __init__(self,
|
|
73
74
|
index_id: str = None,
|
|
@@ -78,6 +79,7 @@ class ApplicationDocReference(DictMixin):
|
|
|
78
79
|
text: str = None,
|
|
79
80
|
biz_id: str = None,
|
|
80
81
|
images: List[str] = None,
|
|
82
|
+
page_number: List[int] = None,
|
|
81
83
|
**kwargs):
|
|
82
84
|
""" Doc references for retrieval result.
|
|
83
85
|
|
|
@@ -100,6 +102,7 @@ class ApplicationDocReference(DictMixin):
|
|
|
100
102
|
text=text,
|
|
101
103
|
biz_id=biz_id,
|
|
102
104
|
images=images,
|
|
105
|
+
page_number=page_number,
|
|
103
106
|
**kwargs)
|
|
104
107
|
|
|
105
108
|
|
|
@@ -36,11 +36,11 @@ class VocabularyService(BaseApi):
|
|
|
36
36
|
self._kwargs = kwargs
|
|
37
37
|
self._last_request_id = None
|
|
38
38
|
self.model = model
|
|
39
|
-
if self.model
|
|
39
|
+
if self.model is None:
|
|
40
40
|
self.model = 'speech-biasing'
|
|
41
41
|
|
|
42
42
|
def __call_with_input(self, input):
|
|
43
|
-
try_count = 0
|
|
43
|
+
try_count = 0
|
|
44
44
|
while True:
|
|
45
45
|
try:
|
|
46
46
|
response = super().call(model=self.model,
|
dashscope/client/base_api.py
CHANGED
|
@@ -178,9 +178,9 @@ class AsyncTaskGetMixin():
|
|
|
178
178
|
}
|
|
179
179
|
if custom_headers:
|
|
180
180
|
headers = {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
**custom_headers,
|
|
182
|
+
**headers,
|
|
183
|
+
}
|
|
184
184
|
with requests.Session() as session:
|
|
185
185
|
logger.debug('Starting request: %s' % status_url)
|
|
186
186
|
response = session.get(status_url,
|
dashscope/utils/oss_utils.py
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
1
|
+
__version__ = '1.21.0'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
dashscope/__init__.py,sha256=
|
|
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,24 +6,25 @@ 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=
|
|
10
|
-
dashscope/aigc/__init__.py,sha256=
|
|
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=
|
|
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
|
|
25
|
-
dashscope/app/application.py,sha256=
|
|
26
|
-
dashscope/app/application_response.py,sha256=
|
|
26
|
+
dashscope/app/application.py,sha256=Cnd62LFpG70XJUo4Oibry9KzXPhPNmNkKFD4R5YuGTA,9343
|
|
27
|
+
dashscope/app/application_response.py,sha256=0pulI3O3z4R4h_YaDwzVimamo3XwTXGy5TiHCzysTBg,7011
|
|
27
28
|
dashscope/assistants/__init__.py,sha256=i9N5OxHgY7edlOhTdPyC0N5Uc0uMCkB2vbMPDCD1zX0,383
|
|
28
29
|
dashscope/assistants/assistant_types.py,sha256=1jNL30TOlrkiYhvCaB3E8jkPLG8CnQ6I3tHpYXZCsD0,4211
|
|
29
30
|
dashscope/assistants/assistants.py,sha256=NYahIDqhtnOcQOmnhZsjc5F5jvBUQcce8-fbrJXHVnQ,10833
|
|
@@ -34,14 +35,14 @@ dashscope/audio/asr/asr_phrase_manager.py,sha256=EjtbI3zz9UQGS1qv6Yb4zzEMj4OJJVX
|
|
|
34
35
|
dashscope/audio/asr/recognition.py,sha256=a4zIkIMiWwOEApP9k9ZC9jGDr7CP7BqB6Cy1dBVTN4g,18978
|
|
35
36
|
dashscope/audio/asr/transcribe.py,sha256=HfZYpvpVfvGRAIIIzX65Af33E6vsIFGd_qqhQ8LaNcM,9651
|
|
36
37
|
dashscope/audio/asr/transcription.py,sha256=D8CW0XDqJuEJVmNFJ6qczTysSV3Sz_rzk2C6NIKTtVc,9042
|
|
37
|
-
dashscope/audio/asr/vocabulary.py,sha256=
|
|
38
|
+
dashscope/audio/asr/vocabulary.py,sha256=2MHxeaL0ANWk-TILrHhArKSdj0d5M_YHw0cnjB-E4dY,6476
|
|
38
39
|
dashscope/audio/tts/__init__.py,sha256=fbnieZX9yNFNh5BsxLpLXb63jlxzxrdCJakV3ignjlQ,194
|
|
39
40
|
dashscope/audio/tts/speech_synthesizer.py,sha256=dnKx9FDDdO_ETHAjhK8zaMVaH6SfoTtN5YxXXqgY1JA,7571
|
|
40
41
|
dashscope/audio/tts_v2/__init__.py,sha256=5UfyDBYnuGgOy9KMxEIXA2U2ihcXutdZc1cqJudy-8M,282
|
|
41
|
-
dashscope/audio/tts_v2/enrollment.py,sha256=
|
|
42
|
+
dashscope/audio/tts_v2/enrollment.py,sha256=mvkYMj9WzqEztZb8zc56fm8Obw7ON9USrEYhATU6rcs,6140
|
|
42
43
|
dashscope/audio/tts_v2/speech_synthesizer.py,sha256=lATasQJB8HlB_yYm90qqW6zIAE1CQFxBxhnch6xdg9s,19285
|
|
43
44
|
dashscope/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
44
|
-
dashscope/client/base_api.py,sha256=
|
|
45
|
+
dashscope/client/base_api.py,sha256=D1lRDr_k58Vwd3jvmsMx4UtTjwdngx182LPYvmtXZjQ,41212
|
|
45
46
|
dashscope/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
46
47
|
dashscope/common/api_key.py,sha256=5Stp0odL5JSuIO3qJBp23QNppuGbqhhvKPS66qbMs0I,1986
|
|
47
48
|
dashscope/common/base_type.py,sha256=C9xP6WuN5pOzviZ2g3X2EPcigldtFE0VlaUmjyNnUUk,4619
|
|
@@ -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=
|
|
88
|
-
dashscope-1.
|
|
89
|
-
dashscope-1.
|
|
90
|
-
dashscope-1.
|
|
91
|
-
dashscope-1.
|
|
92
|
-
dashscope-1.
|
|
93
|
-
dashscope-1.
|
|
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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|