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.
- dashscope/__init__.py +61 -14
- dashscope/aigc/__init__.py +10 -3
- dashscope/aigc/chat_completion.py +282 -0
- dashscope/aigc/code_generation.py +145 -0
- dashscope/aigc/conversation.py +71 -12
- dashscope/aigc/generation.py +288 -16
- dashscope/aigc/image_synthesis.py +473 -31
- dashscope/aigc/multimodal_conversation.py +299 -14
- dashscope/aigc/video_synthesis.py +610 -0
- dashscope/api_entities/aiohttp_request.py +8 -5
- dashscope/api_entities/api_request_data.py +4 -2
- dashscope/api_entities/api_request_factory.py +68 -20
- dashscope/api_entities/base_request.py +20 -3
- dashscope/api_entities/chat_completion_types.py +344 -0
- dashscope/api_entities/dashscope_response.py +243 -15
- dashscope/api_entities/encryption.py +179 -0
- dashscope/api_entities/http_request.py +216 -62
- dashscope/api_entities/websocket_request.py +43 -34
- dashscope/app/__init__.py +5 -0
- dashscope/app/application.py +203 -0
- dashscope/app/application_response.py +246 -0
- dashscope/assistants/__init__.py +16 -0
- dashscope/assistants/assistant_types.py +175 -0
- dashscope/assistants/assistants.py +311 -0
- dashscope/assistants/files.py +197 -0
- dashscope/audio/__init__.py +4 -2
- dashscope/audio/asr/__init__.py +17 -1
- dashscope/audio/asr/asr_phrase_manager.py +203 -0
- dashscope/audio/asr/recognition.py +167 -27
- dashscope/audio/asr/transcription.py +107 -14
- dashscope/audio/asr/translation_recognizer.py +1006 -0
- dashscope/audio/asr/vocabulary.py +177 -0
- dashscope/audio/qwen_asr/__init__.py +7 -0
- dashscope/audio/qwen_asr/qwen_transcription.py +189 -0
- dashscope/audio/qwen_omni/__init__.py +11 -0
- dashscope/audio/qwen_omni/omni_realtime.py +524 -0
- dashscope/audio/qwen_tts/__init__.py +5 -0
- dashscope/audio/qwen_tts/speech_synthesizer.py +77 -0
- dashscope/audio/qwen_tts_realtime/__init__.py +10 -0
- dashscope/audio/qwen_tts_realtime/qwen_tts_realtime.py +355 -0
- dashscope/audio/tts/__init__.py +2 -0
- dashscope/audio/tts/speech_synthesizer.py +5 -0
- dashscope/audio/tts_v2/__init__.py +12 -0
- dashscope/audio/tts_v2/enrollment.py +179 -0
- dashscope/audio/tts_v2/speech_synthesizer.py +886 -0
- dashscope/cli.py +157 -37
- dashscope/client/base_api.py +652 -87
- dashscope/common/api_key.py +2 -0
- dashscope/common/base_type.py +135 -0
- dashscope/common/constants.py +13 -16
- dashscope/common/env.py +2 -0
- dashscope/common/error.py +58 -22
- dashscope/common/logging.py +2 -0
- dashscope/common/message_manager.py +2 -0
- dashscope/common/utils.py +276 -46
- dashscope/customize/__init__.py +0 -0
- dashscope/customize/customize_types.py +192 -0
- dashscope/customize/deployments.py +146 -0
- dashscope/customize/finetunes.py +234 -0
- dashscope/embeddings/__init__.py +5 -1
- dashscope/embeddings/batch_text_embedding.py +208 -0
- dashscope/embeddings/batch_text_embedding_response.py +65 -0
- dashscope/embeddings/multimodal_embedding.py +118 -10
- dashscope/embeddings/text_embedding.py +13 -1
- dashscope/{file.py → files.py} +19 -4
- dashscope/io/input_output.py +2 -0
- dashscope/model.py +11 -2
- dashscope/models.py +43 -0
- dashscope/multimodal/__init__.py +20 -0
- dashscope/multimodal/dialog_state.py +56 -0
- dashscope/multimodal/multimodal_constants.py +28 -0
- dashscope/multimodal/multimodal_dialog.py +648 -0
- dashscope/multimodal/multimodal_request_params.py +313 -0
- dashscope/multimodal/tingwu/__init__.py +10 -0
- dashscope/multimodal/tingwu/tingwu.py +80 -0
- dashscope/multimodal/tingwu/tingwu_realtime.py +579 -0
- dashscope/nlp/__init__.py +0 -0
- dashscope/nlp/understanding.py +64 -0
- dashscope/protocol/websocket.py +3 -0
- dashscope/rerank/__init__.py +0 -0
- dashscope/rerank/text_rerank.py +69 -0
- dashscope/resources/qwen.tiktoken +151643 -0
- dashscope/threads/__init__.py +26 -0
- dashscope/threads/messages/__init__.py +0 -0
- dashscope/threads/messages/files.py +113 -0
- dashscope/threads/messages/messages.py +220 -0
- dashscope/threads/runs/__init__.py +0 -0
- dashscope/threads/runs/runs.py +501 -0
- dashscope/threads/runs/steps.py +112 -0
- dashscope/threads/thread_types.py +665 -0
- dashscope/threads/threads.py +212 -0
- dashscope/tokenizers/__init__.py +7 -0
- dashscope/tokenizers/qwen_tokenizer.py +111 -0
- dashscope/tokenizers/tokenization.py +125 -0
- dashscope/tokenizers/tokenizer.py +45 -0
- dashscope/tokenizers/tokenizer_base.py +32 -0
- dashscope/utils/__init__.py +0 -0
- dashscope/utils/message_utils.py +838 -0
- dashscope/utils/oss_utils.py +243 -0
- dashscope/utils/param_utils.py +29 -0
- dashscope/version.py +3 -1
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/METADATA +53 -50
- dashscope-1.25.6.dist-info/RECORD +112 -0
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/WHEEL +1 -1
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/entry_points.txt +0 -1
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info/licenses}/LICENSE +2 -4
- dashscope/deployment.py +0 -129
- dashscope/finetune.py +0 -149
- dashscope-1.8.0.dist-info/RECORD +0 -49
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/top_level.txt +0 -0
dashscope/common/api_key.py
CHANGED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
|
|
3
|
+
import dataclasses
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any, List
|
|
6
|
+
|
|
7
|
+
import dashscope
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_object_type(name: str):
|
|
11
|
+
dashscope_objects = {
|
|
12
|
+
'assistant': dashscope.Assistant,
|
|
13
|
+
'assistant.deleted': dashscope.DeleteResponse,
|
|
14
|
+
'thread.message': dashscope.ThreadMessage,
|
|
15
|
+
'thread.run': dashscope.Run,
|
|
16
|
+
'thread.run.step': dashscope.RunStep,
|
|
17
|
+
'thread.message.file': dashscope.MessageFile,
|
|
18
|
+
'assistant.file': dashscope.AssistantFile,
|
|
19
|
+
'thread': dashscope.Thread,
|
|
20
|
+
}
|
|
21
|
+
return dashscope_objects.get(name, None)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(init=False)
|
|
25
|
+
class BaseObjectMixin(object):
|
|
26
|
+
__slots__ = ()
|
|
27
|
+
|
|
28
|
+
def __init__(self, **kwargs):
|
|
29
|
+
field_type_map = self._get_fields_type()
|
|
30
|
+
for k, v in kwargs.items():
|
|
31
|
+
field = field_type_map.get(k, None)
|
|
32
|
+
if field and v is not None:
|
|
33
|
+
if dataclasses.is_dataclass(field.type): # process dataclasses
|
|
34
|
+
self.__setattr__(k, field.type(**v))
|
|
35
|
+
continue
|
|
36
|
+
|
|
37
|
+
if isinstance(v, dict):
|
|
38
|
+
object_name = v.get('object', None)
|
|
39
|
+
if object_name:
|
|
40
|
+
object_type = get_object_type(object_name)
|
|
41
|
+
if object_type:
|
|
42
|
+
self.__setattr__(k, object_type(**v))
|
|
43
|
+
else:
|
|
44
|
+
self.__setattr__(k, v)
|
|
45
|
+
else:
|
|
46
|
+
self.__setattr__(k, v)
|
|
47
|
+
elif isinstance(v, list):
|
|
48
|
+
obj_list = self._init_list_element_recursive(field, v)
|
|
49
|
+
self.__setattr__(k, obj_list)
|
|
50
|
+
else:
|
|
51
|
+
self.__setattr__(k, v)
|
|
52
|
+
|
|
53
|
+
def _init_list_element_recursive(self, field, items: list) -> List[Any]:
|
|
54
|
+
obj_list = []
|
|
55
|
+
for item in items:
|
|
56
|
+
if field:
|
|
57
|
+
# current only support List[cls_name],
|
|
58
|
+
# not support List[cls_nam1, cls_name2]
|
|
59
|
+
element_type = field.type.__args__[0]
|
|
60
|
+
if dataclasses.is_dataclass(element_type):
|
|
61
|
+
obj_list.append(element_type(**item))
|
|
62
|
+
continue
|
|
63
|
+
|
|
64
|
+
if isinstance(item, dict):
|
|
65
|
+
object_name = item.get('object', None)
|
|
66
|
+
if object_name:
|
|
67
|
+
object_type = get_object_type(object_name)
|
|
68
|
+
if object_type:
|
|
69
|
+
obj_list.append(object_type(**item))
|
|
70
|
+
else:
|
|
71
|
+
obj_list.append(item)
|
|
72
|
+
else:
|
|
73
|
+
obj_list.append(item)
|
|
74
|
+
elif isinstance(item, list):
|
|
75
|
+
obj_list.append(self._init_list_element_recursive(item))
|
|
76
|
+
else:
|
|
77
|
+
obj_list.append(item)
|
|
78
|
+
return obj_list
|
|
79
|
+
|
|
80
|
+
def _get_fields_type(self):
|
|
81
|
+
field_type_map = {}
|
|
82
|
+
if dataclasses.is_dataclass(self):
|
|
83
|
+
for field in dataclasses.fields(self):
|
|
84
|
+
field_type_map[field.name] = field
|
|
85
|
+
return field_type_map
|
|
86
|
+
|
|
87
|
+
def __setitem__(self, __key: Any, __value: Any) -> None:
|
|
88
|
+
return self.__setattr__(__key, __value)
|
|
89
|
+
|
|
90
|
+
def __getitem__(self, __key: Any) -> Any:
|
|
91
|
+
return self.__getattribute__(__key)
|
|
92
|
+
|
|
93
|
+
def __contains__(self, item):
|
|
94
|
+
return hasattr(self, item)
|
|
95
|
+
|
|
96
|
+
def __delitem__(self, key):
|
|
97
|
+
self.__delattr__(key)
|
|
98
|
+
|
|
99
|
+
def _recursive_to_str__(self, input_object) -> Any:
|
|
100
|
+
if isinstance(input_object, list):
|
|
101
|
+
output_object = []
|
|
102
|
+
for item in input_object:
|
|
103
|
+
output_object.append(self._recursive_to_str__(item))
|
|
104
|
+
return output_object
|
|
105
|
+
elif dataclasses.is_dataclass(input_object):
|
|
106
|
+
output_object = {}
|
|
107
|
+
for field in dataclasses.fields(input_object):
|
|
108
|
+
if hasattr(input_object, field.name):
|
|
109
|
+
output_object[field.name] = self._recursive_to_str__(
|
|
110
|
+
getattr(input_object, field.name))
|
|
111
|
+
return output_object
|
|
112
|
+
else:
|
|
113
|
+
return input_object
|
|
114
|
+
|
|
115
|
+
def __str__(self) -> str:
|
|
116
|
+
real_dict = self.__dict__
|
|
117
|
+
self_fields = dataclasses.fields(self)
|
|
118
|
+
for field in self_fields:
|
|
119
|
+
if hasattr(self, field.name):
|
|
120
|
+
real_dict[field.name] = getattr(self, field.name)
|
|
121
|
+
output_object = {}
|
|
122
|
+
for key, value in real_dict.items():
|
|
123
|
+
output_object[key] = self._recursive_to_str__(value)
|
|
124
|
+
return str(output_object)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@dataclass(init=False)
|
|
128
|
+
class BaseList(BaseObjectMixin):
|
|
129
|
+
status_code: int
|
|
130
|
+
has_more: bool
|
|
131
|
+
last_id: str
|
|
132
|
+
first_id: str
|
|
133
|
+
|
|
134
|
+
def __init__(self, **kwargs):
|
|
135
|
+
super().__init__(**kwargs)
|
dashscope/common/constants.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
|
|
1
3
|
from http import HTTPStatus
|
|
2
4
|
from pathlib import Path
|
|
3
5
|
|
|
@@ -23,11 +25,21 @@ NEGATIVE_PROMPT = 'negative_prompt'
|
|
|
23
25
|
HISTORY = 'history'
|
|
24
26
|
CUSTOMIZED_MODEL_ID = 'customized_model_id'
|
|
25
27
|
IMAGES = 'images'
|
|
28
|
+
REFERENCE_VIDEO_URLS = 'reference_video_urls'
|
|
26
29
|
TEXT_EMBEDDING_INPUT_KEY = 'texts'
|
|
27
30
|
SERVICE_503_MESSAGE = 'Service temporarily unavailable, possibly overloaded or not ready.' # noqa E501
|
|
28
31
|
WEBSOCKET_ERROR_CODE = 44
|
|
29
32
|
SSE_CONTENT_TYPE = 'text/event-stream'
|
|
30
33
|
DEPRECATED_MESSAGE = 'history and auto_history are deprecated for qwen serial models and will be remove in future, use messages' # noqa E501
|
|
34
|
+
SCENE = 'scene'
|
|
35
|
+
MESSAGE = 'message'
|
|
36
|
+
REQUEST_CONTENT_TEXT = 'text'
|
|
37
|
+
REQUEST_CONTENT_IMAGE = 'image'
|
|
38
|
+
REQUEST_CONTENT_AUDIO = 'audio'
|
|
39
|
+
FILE_PATH_SCHEMA = 'file://'
|
|
40
|
+
|
|
41
|
+
ENCRYPTION_AES_SECRET_KEY_BYTES = 32
|
|
42
|
+
ENCRYPTION_AES_IV_LENGTH = 12
|
|
31
43
|
|
|
32
44
|
REPEATABLE_STATUS = [
|
|
33
45
|
HTTPStatus.SERVICE_UNAVAILABLE, HTTPStatus.GATEWAY_TIMEOUT
|
|
@@ -36,22 +48,7 @@ REPEATABLE_STATUS = [
|
|
|
36
48
|
|
|
37
49
|
class FilePurpose:
|
|
38
50
|
fine_tune = 'fine_tune'
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class StreamResultMode:
|
|
42
|
-
"""Stream result mode.
|
|
43
|
-
examples(I like apple)
|
|
44
|
-
accumulate: will output
|
|
45
|
-
I
|
|
46
|
-
I like
|
|
47
|
-
I like apple
|
|
48
|
-
divide: will output
|
|
49
|
-
I
|
|
50
|
-
like
|
|
51
|
-
apple
|
|
52
|
-
"""
|
|
53
|
-
ACCUMULATE = 'accumulate'
|
|
54
|
-
DIVIDE = 'divide'
|
|
51
|
+
assistants = 'assistants'
|
|
55
52
|
|
|
56
53
|
|
|
57
54
|
class DeploymentStatus:
|
dashscope/common/env.py
CHANGED
dashscope/common/error.py
CHANGED
|
@@ -1,61 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DashScopeException(Exception):
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AuthenticationError(DashScopeException):
|
|
2
9
|
pass
|
|
3
10
|
|
|
4
11
|
|
|
5
|
-
class InvalidParameter(
|
|
12
|
+
class InvalidParameter(DashScopeException):
|
|
6
13
|
pass
|
|
7
14
|
|
|
8
15
|
|
|
9
|
-
class InvalidTask(
|
|
16
|
+
class InvalidTask(DashScopeException):
|
|
10
17
|
pass
|
|
11
18
|
|
|
12
19
|
|
|
13
|
-
class UnsupportedModel(
|
|
20
|
+
class UnsupportedModel(DashScopeException):
|
|
14
21
|
pass
|
|
15
22
|
|
|
16
23
|
|
|
17
|
-
class UnsupportedTask(
|
|
24
|
+
class UnsupportedTask(DashScopeException):
|
|
18
25
|
pass
|
|
19
26
|
|
|
20
27
|
|
|
21
|
-
class ModelRequired(
|
|
28
|
+
class ModelRequired(DashScopeException):
|
|
22
29
|
pass
|
|
23
30
|
|
|
24
31
|
|
|
25
|
-
class InvalidModel(
|
|
32
|
+
class InvalidModel(DashScopeException):
|
|
26
33
|
pass
|
|
27
34
|
|
|
28
35
|
|
|
29
|
-
class InvalidInput(
|
|
36
|
+
class InvalidInput(DashScopeException):
|
|
30
37
|
pass
|
|
31
38
|
|
|
32
39
|
|
|
33
|
-
class InvalidFileFormat(
|
|
40
|
+
class InvalidFileFormat(DashScopeException):
|
|
34
41
|
pass
|
|
35
42
|
|
|
36
43
|
|
|
37
|
-
class UnsupportedApiProtocol(
|
|
44
|
+
class UnsupportedApiProtocol(DashScopeException):
|
|
38
45
|
pass
|
|
39
46
|
|
|
40
47
|
|
|
41
|
-
class NotImplemented(
|
|
48
|
+
class NotImplemented(DashScopeException):
|
|
42
49
|
pass
|
|
43
50
|
|
|
44
51
|
|
|
45
|
-
class MultiInputsWithBinaryNotSupported(
|
|
52
|
+
class MultiInputsWithBinaryNotSupported(DashScopeException):
|
|
46
53
|
pass
|
|
47
54
|
|
|
48
55
|
|
|
49
|
-
class UnexpectedMessageReceived(
|
|
56
|
+
class UnexpectedMessageReceived(DashScopeException):
|
|
50
57
|
pass
|
|
51
58
|
|
|
52
59
|
|
|
53
|
-
class UnsupportedData(
|
|
60
|
+
class UnsupportedData(DashScopeException):
|
|
54
61
|
pass
|
|
55
62
|
|
|
56
63
|
|
|
64
|
+
class AssistantError(DashScopeException):
|
|
65
|
+
def __init__(self, **kwargs):
|
|
66
|
+
self.message = None
|
|
67
|
+
self.code = None
|
|
68
|
+
self.request_id = None
|
|
69
|
+
if 'message' in kwargs:
|
|
70
|
+
import json
|
|
71
|
+
msg = json.loads(kwargs['message'])
|
|
72
|
+
if 'request_id' in msg:
|
|
73
|
+
self.request_id = msg['request_id']
|
|
74
|
+
if 'code' in msg:
|
|
75
|
+
self.code = msg['code']
|
|
76
|
+
if 'message' in msg:
|
|
77
|
+
self.message = msg['message']
|
|
78
|
+
|
|
79
|
+
def __str__(self):
|
|
80
|
+
msg = 'Request failed, request_id: %s, code: %s, message: %s' % ( # noqa E501
|
|
81
|
+
self.request_id, self.code, self.message)
|
|
82
|
+
return msg
|
|
83
|
+
|
|
84
|
+
|
|
57
85
|
# for server send generation or inference error.
|
|
58
|
-
class RequestFailure(
|
|
86
|
+
class RequestFailure(DashScopeException):
|
|
59
87
|
def __init__(self,
|
|
60
88
|
request_id=None,
|
|
61
89
|
message=None,
|
|
@@ -72,29 +100,37 @@ class RequestFailure(Exception):
|
|
|
72
100
|
return msg
|
|
73
101
|
|
|
74
102
|
|
|
75
|
-
class UnknownMessageReceived(
|
|
103
|
+
class UnknownMessageReceived(DashScopeException):
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class InputDataRequired(DashScopeException):
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class InputRequired(DashScopeException):
|
|
76
112
|
pass
|
|
77
113
|
|
|
78
114
|
|
|
79
|
-
class
|
|
115
|
+
class UnsupportedDataType(DashScopeException):
|
|
80
116
|
pass
|
|
81
117
|
|
|
82
118
|
|
|
83
|
-
class
|
|
119
|
+
class ServiceUnavailableError(DashScopeException):
|
|
84
120
|
pass
|
|
85
121
|
|
|
86
122
|
|
|
87
|
-
class
|
|
123
|
+
class UnsupportedHTTPMethod(DashScopeException):
|
|
88
124
|
pass
|
|
89
125
|
|
|
90
126
|
|
|
91
|
-
class
|
|
127
|
+
class AsyncTaskCreateFailed(DashScopeException):
|
|
92
128
|
pass
|
|
93
129
|
|
|
94
130
|
|
|
95
|
-
class
|
|
131
|
+
class UploadFileException(DashScopeException):
|
|
96
132
|
pass
|
|
97
133
|
|
|
98
134
|
|
|
99
|
-
class
|
|
135
|
+
class TimeoutException(DashScopeException):
|
|
100
136
|
pass
|
dashscope/common/logging.py
CHANGED