dashscope 1.23.9__py3-none-any.whl → 1.24.1__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/app/application_response.py +48 -1
- dashscope/assistants/assistant_types.py +9 -0
- dashscope/assistants/assistants.py +31 -2
- dashscope/assistants/files.py +7 -1
- dashscope/audio/tts_v2/speech_synthesizer.py +38 -22
- dashscope/cli.py +54 -0
- dashscope/multimodal/multimodal_request_params.py +1 -0
- dashscope/multimodal/tingwu/__init__.py +0 -0
- dashscope/multimodal/tingwu/tingwu.py +80 -0
- dashscope/threads/runs/runs.py +21 -0
- dashscope/threads/thread_types.py +12 -0
- dashscope/utils/oss_utils.py +3 -0
- dashscope/version.py +1 -1
- {dashscope-1.23.9.dist-info → dashscope-1.24.1.dist-info}/METADATA +1 -1
- {dashscope-1.23.9.dist-info → dashscope-1.24.1.dist-info}/RECORD +19 -17
- {dashscope-1.23.9.dist-info → dashscope-1.24.1.dist-info}/WHEEL +0 -0
- {dashscope-1.23.9.dist-info → dashscope-1.24.1.dist-info}/entry_points.txt +0 -0
- {dashscope-1.23.9.dist-info → dashscope-1.24.1.dist-info}/licenses/LICENSE +0 -0
- {dashscope-1.23.9.dist-info → dashscope-1.24.1.dist-info}/top_level.txt +0 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"""
|
|
7
7
|
from dataclasses import dataclass
|
|
8
8
|
from http import HTTPStatus
|
|
9
|
-
from typing import Dict, List
|
|
9
|
+
from typing import Dict, List, Optional
|
|
10
10
|
|
|
11
11
|
from dashscope.api_entities.dashscope_response import (DashScopeAPIResponse,
|
|
12
12
|
DictMixin)
|
|
@@ -105,6 +105,50 @@ class ApplicationDocReference(DictMixin):
|
|
|
105
105
|
page_number=page_number,
|
|
106
106
|
**kwargs)
|
|
107
107
|
|
|
108
|
+
@dataclass(init=False)
|
|
109
|
+
class WorkflowMessage(DictMixin):
|
|
110
|
+
node_id: str
|
|
111
|
+
node_name: str
|
|
112
|
+
node_type: str
|
|
113
|
+
node_status: str
|
|
114
|
+
node_is_completed: str
|
|
115
|
+
node_msg_seq_id: int
|
|
116
|
+
message: str
|
|
117
|
+
|
|
118
|
+
class Message(DictMixin):
|
|
119
|
+
role: str
|
|
120
|
+
content: str
|
|
121
|
+
|
|
122
|
+
def __init__(self,
|
|
123
|
+
node_id: str = None,
|
|
124
|
+
node_name: str = None,
|
|
125
|
+
node_type: str = None,
|
|
126
|
+
node_status: str = None,
|
|
127
|
+
node_is_completed: str = None,
|
|
128
|
+
node_msg_seq_id: int = None,
|
|
129
|
+
message: Message = None,
|
|
130
|
+
**kwargs):
|
|
131
|
+
""" Workflow message.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
node_id (str, optional): .
|
|
135
|
+
node_name (str, optional): .
|
|
136
|
+
node_type (str, optional): .
|
|
137
|
+
node_status (str, optional): .
|
|
138
|
+
node_is_completed (str, optional): .
|
|
139
|
+
node_msg_seq_id (int, optional): .
|
|
140
|
+
message (Message, optional): .
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
super().__init__(node_id=node_id,
|
|
144
|
+
node_name=node_name,
|
|
145
|
+
node_type=node_type,
|
|
146
|
+
node_status=node_status,
|
|
147
|
+
node_is_completed=node_is_completed,
|
|
148
|
+
node_msg_seq_id=node_msg_seq_id,
|
|
149
|
+
message=message,
|
|
150
|
+
**kwargs)
|
|
151
|
+
|
|
108
152
|
|
|
109
153
|
@dataclass(init=False)
|
|
110
154
|
class ApplicationOutput(DictMixin):
|
|
@@ -113,6 +157,7 @@ class ApplicationOutput(DictMixin):
|
|
|
113
157
|
session_id: str
|
|
114
158
|
thoughts: List[ApplicationThought]
|
|
115
159
|
doc_references: List[ApplicationDocReference]
|
|
160
|
+
workflow_message: WorkflowMessage
|
|
116
161
|
|
|
117
162
|
def __init__(self,
|
|
118
163
|
text: str = None,
|
|
@@ -120,6 +165,7 @@ class ApplicationOutput(DictMixin):
|
|
|
120
165
|
session_id: str = None,
|
|
121
166
|
thoughts: List[ApplicationThought] = None,
|
|
122
167
|
doc_references: List[ApplicationDocReference] = None,
|
|
168
|
+
workflow_message: WorkflowMessage = None,
|
|
123
169
|
**kwargs):
|
|
124
170
|
|
|
125
171
|
ths = None
|
|
@@ -139,6 +185,7 @@ class ApplicationOutput(DictMixin):
|
|
|
139
185
|
session_id=session_id,
|
|
140
186
|
thoughts=ths,
|
|
141
187
|
doc_references=refs,
|
|
188
|
+
workflow_message=workflow_message,
|
|
142
189
|
**kwargs)
|
|
143
190
|
|
|
144
191
|
|
|
@@ -118,6 +118,15 @@ class Assistant(BaseObjectMixin):
|
|
|
118
118
|
metadata: Optional[object] = None
|
|
119
119
|
tools: List[Tool]
|
|
120
120
|
|
|
121
|
+
object: Optional[str] = None
|
|
122
|
+
|
|
123
|
+
top_p: Optional[float] = None
|
|
124
|
+
top_k: Optional[int] = None
|
|
125
|
+
temperature: Optional[float] = None
|
|
126
|
+
max_tokens: Optional[int] = None
|
|
127
|
+
|
|
128
|
+
request_id: Optional[str] = None
|
|
129
|
+
|
|
121
130
|
def __init__(self, **kwargs):
|
|
122
131
|
self.tools = convert_tools_dict_to_objects(kwargs.pop('tools', []))
|
|
123
132
|
super().__init__(**kwargs)
|
|
@@ -26,6 +26,10 @@ class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
|
26
26
|
tools: Optional[List[Dict]] = None,
|
|
27
27
|
file_ids: Optional[List[str]] = [],
|
|
28
28
|
metadata: Dict = {},
|
|
29
|
+
top_p: Optional[float] = None,
|
|
30
|
+
top_k: Optional[int] = None,
|
|
31
|
+
temperature: Optional[float] = None,
|
|
32
|
+
max_tokens: Optional[int] = None,
|
|
29
33
|
):
|
|
30
34
|
obj = {}
|
|
31
35
|
if model:
|
|
@@ -41,6 +45,15 @@ class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
|
41
45
|
obj['file_ids'] = file_ids
|
|
42
46
|
obj['metadata'] = metadata
|
|
43
47
|
|
|
48
|
+
if top_p is not None:
|
|
49
|
+
obj['top_p'] = top_p
|
|
50
|
+
if top_k is not None:
|
|
51
|
+
obj['top_k'] = top_k
|
|
52
|
+
if temperature is not None:
|
|
53
|
+
obj['temperature'] = temperature
|
|
54
|
+
if max_tokens is not None:
|
|
55
|
+
obj['max_tokens'] = max_tokens
|
|
56
|
+
|
|
44
57
|
return obj
|
|
45
58
|
|
|
46
59
|
@classmethod
|
|
@@ -98,6 +111,10 @@ class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
|
98
111
|
metadata: Dict = None,
|
|
99
112
|
workspace: str = None,
|
|
100
113
|
api_key: str = None,
|
|
114
|
+
top_p: Optional[float] = None,
|
|
115
|
+
top_k: Optional[int] = None,
|
|
116
|
+
temperature: Optional[float] = None,
|
|
117
|
+
max_tokens: Optional[int] = None,
|
|
101
118
|
**kwargs) -> Assistant:
|
|
102
119
|
"""Create Assistant.
|
|
103
120
|
|
|
@@ -111,6 +128,10 @@ class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
|
111
128
|
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
|
112
129
|
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
113
130
|
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
131
|
+
top_p (float, optional): top_p parameter for model. Defaults to None.
|
|
132
|
+
top_k (int, optional): top_p parameter for model. Defaults to None.
|
|
133
|
+
temperature (float, optional): temperature parameter for model. Defaults to None.
|
|
134
|
+
max_tokens (int, optional): max_tokens parameter for model. Defaults to None.
|
|
114
135
|
|
|
115
136
|
Raises:
|
|
116
137
|
ModelRequired: The model is required.
|
|
@@ -122,7 +143,7 @@ class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
|
122
143
|
raise ModelRequired('Model is required!')
|
|
123
144
|
data = cls._create_assistant_object(model, name, description,
|
|
124
145
|
instructions, tools, file_ids,
|
|
125
|
-
metadata)
|
|
146
|
+
metadata, top_p, top_k, temperature, max_tokens)
|
|
126
147
|
response = super().call(data=data,
|
|
127
148
|
api_key=api_key,
|
|
128
149
|
flattened_output=True,
|
|
@@ -224,6 +245,10 @@ class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
|
224
245
|
metadata: Dict = None,
|
|
225
246
|
workspace: str = None,
|
|
226
247
|
api_key: str = None,
|
|
248
|
+
top_p: Optional[float] = None,
|
|
249
|
+
top_k: Optional[int] = None,
|
|
250
|
+
temperature: Optional[float] = None,
|
|
251
|
+
max_tokens: Optional[int] = None,
|
|
227
252
|
**kwargs) -> Assistant:
|
|
228
253
|
"""Update an exist assistants
|
|
229
254
|
|
|
@@ -238,6 +263,10 @@ class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
|
238
263
|
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
|
239
264
|
workspace (str): The DashScope workspace id.
|
|
240
265
|
api_key (str, optional): The DashScope workspace id. Defaults to None.
|
|
266
|
+
top_p (float, optional): top_p parameter for model. Defaults to None.
|
|
267
|
+
top_k (int, optional): top_p parameter for model. Defaults to None.
|
|
268
|
+
temperature (float, optional): temperature parameter for model. Defaults to None.
|
|
269
|
+
max_tokens (int, optional): max_tokens parameter for model. Defaults to None.
|
|
241
270
|
|
|
242
271
|
Returns:
|
|
243
272
|
Assistant: The updated assistant.
|
|
@@ -247,7 +276,7 @@ class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
|
247
276
|
response = super().update(assistant_id,
|
|
248
277
|
cls._create_assistant_object(
|
|
249
278
|
model, name, description, instructions,
|
|
250
|
-
tools, file_ids, metadata),
|
|
279
|
+
tools, file_ids, metadata, top_p, top_k, temperature, max_tokens),
|
|
251
280
|
api_key=api_key,
|
|
252
281
|
workspace=workspace,
|
|
253
282
|
flattened_output=True,
|
dashscope/assistants/files.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
from typing import Optional
|
|
2
3
|
|
|
3
4
|
from dashscope.assistants.assistant_types import (AssistantFile,
|
|
4
5
|
AssistantFileList,
|
|
@@ -148,7 +149,7 @@ class Files(CreateMixin, DeleteMixin, ListObjectMixin, GetStatusMixin):
|
|
|
148
149
|
assistant_id: str,
|
|
149
150
|
workspace: str = None,
|
|
150
151
|
api_key: str = None,
|
|
151
|
-
**kwargs) -> AssistantFile:
|
|
152
|
+
**kwargs) -> Optional[AssistantFile]:
|
|
152
153
|
"""Retrieve file information.
|
|
153
154
|
|
|
154
155
|
Args:
|
|
@@ -160,6 +161,11 @@ class Files(CreateMixin, DeleteMixin, ListObjectMixin, GetStatusMixin):
|
|
|
160
161
|
Returns:
|
|
161
162
|
AssistantFile: The `AssistantFile` object.
|
|
162
163
|
"""
|
|
164
|
+
response = super().get(target=assistant_id + '/files/' + file_id, api_key=api_key, workspace=workspace, **kwargs)
|
|
165
|
+
if response.status_code == 200 and response.output:
|
|
166
|
+
return AssistantFile(**response.output)
|
|
167
|
+
else:
|
|
168
|
+
return None
|
|
163
169
|
|
|
164
170
|
@classmethod
|
|
165
171
|
def delete(cls,
|
|
@@ -43,28 +43,39 @@ class ResultCallback:
|
|
|
43
43
|
|
|
44
44
|
@unique
|
|
45
45
|
class AudioFormat(Enum):
|
|
46
|
-
DEFAULT = ('Default', 0, '0',
|
|
47
|
-
WAV_8000HZ_MONO_16BIT = ('wav', 8000, 'mono',
|
|
48
|
-
WAV_16000HZ_MONO_16BIT = ('wav', 16000, 'mono',
|
|
49
|
-
WAV_22050HZ_MONO_16BIT = ('wav', 22050, 'mono',
|
|
50
|
-
WAV_24000HZ_MONO_16BIT = ('wav', 24000, 'mono',
|
|
51
|
-
WAV_44100HZ_MONO_16BIT = ('wav', 44100, 'mono',
|
|
52
|
-
WAV_48000HZ_MONO_16BIT = ('wav', 48000, 'mono',
|
|
53
|
-
|
|
54
|
-
MP3_8000HZ_MONO_128KBPS = ('mp3', 8000, 'mono',
|
|
55
|
-
MP3_16000HZ_MONO_128KBPS = ('mp3', 16000, 'mono',
|
|
56
|
-
MP3_22050HZ_MONO_256KBPS = ('mp3', 22050, 'mono',
|
|
57
|
-
MP3_24000HZ_MONO_256KBPS = ('mp3', 24000, 'mono',
|
|
58
|
-
MP3_44100HZ_MONO_256KBPS = ('mp3', 44100, 'mono',
|
|
59
|
-
MP3_48000HZ_MONO_256KBPS = ('mp3', 48000, 'mono',
|
|
60
|
-
|
|
61
|
-
PCM_8000HZ_MONO_16BIT = ('pcm', 8000, 'mono',
|
|
62
|
-
PCM_16000HZ_MONO_16BIT = ('pcm', 16000, 'mono',
|
|
63
|
-
PCM_22050HZ_MONO_16BIT = ('pcm', 22050, 'mono',
|
|
64
|
-
PCM_24000HZ_MONO_16BIT = ('pcm', 24000, 'mono',
|
|
65
|
-
PCM_44100HZ_MONO_16BIT = ('pcm', 44100, 'mono',
|
|
66
|
-
PCM_48000HZ_MONO_16BIT = ('pcm', 48000, 'mono',
|
|
67
|
-
|
|
46
|
+
DEFAULT = ('Default', 0, '0', 0)
|
|
47
|
+
WAV_8000HZ_MONO_16BIT = ('wav', 8000, 'mono', 0)
|
|
48
|
+
WAV_16000HZ_MONO_16BIT = ('wav', 16000, 'mono', 16)
|
|
49
|
+
WAV_22050HZ_MONO_16BIT = ('wav', 22050, 'mono', 16)
|
|
50
|
+
WAV_24000HZ_MONO_16BIT = ('wav', 24000, 'mono', 16)
|
|
51
|
+
WAV_44100HZ_MONO_16BIT = ('wav', 44100, 'mono', 16)
|
|
52
|
+
WAV_48000HZ_MONO_16BIT = ('wav', 48000, 'mono', 16)
|
|
53
|
+
|
|
54
|
+
MP3_8000HZ_MONO_128KBPS = ('mp3', 8000, 'mono', 128)
|
|
55
|
+
MP3_16000HZ_MONO_128KBPS = ('mp3', 16000, 'mono', 128)
|
|
56
|
+
MP3_22050HZ_MONO_256KBPS = ('mp3', 22050, 'mono', 256)
|
|
57
|
+
MP3_24000HZ_MONO_256KBPS = ('mp3', 24000, 'mono', 256)
|
|
58
|
+
MP3_44100HZ_MONO_256KBPS = ('mp3', 44100, 'mono', 256)
|
|
59
|
+
MP3_48000HZ_MONO_256KBPS = ('mp3', 48000, 'mono', 256)
|
|
60
|
+
|
|
61
|
+
PCM_8000HZ_MONO_16BIT = ('pcm', 8000, 'mono', 16)
|
|
62
|
+
PCM_16000HZ_MONO_16BIT = ('pcm', 16000, 'mono', 16)
|
|
63
|
+
PCM_22050HZ_MONO_16BIT = ('pcm', 22050, 'mono', 16)
|
|
64
|
+
PCM_24000HZ_MONO_16BIT = ('pcm', 24000, 'mono', 16)
|
|
65
|
+
PCM_44100HZ_MONO_16BIT = ('pcm', 44100, 'mono', 16)
|
|
66
|
+
PCM_48000HZ_MONO_16BIT = ('pcm', 48000, 'mono', 16)
|
|
67
|
+
|
|
68
|
+
OGG_OPUS_8KHZ_MONO_32KBPS = ("opus", 8000, "mono", 32)
|
|
69
|
+
OGG_OPUS_8KHZ_MONO_16KBPS = ("opus", 8000, "mono", 16)
|
|
70
|
+
OGG_OPUS_16KHZ_MONO_16KBPS = ("opus", 16000, "mono", 16)
|
|
71
|
+
OGG_OPUS_16KHZ_MONO_32KBPS = ("opus", 16000, "mono", 32)
|
|
72
|
+
OGG_OPUS_16KHZ_MONO_64KBPS = ("opus", 16000, "mono", 64)
|
|
73
|
+
OGG_OPUS_24KHZ_MONO_16KBPS = ("opus", 24000, "mono", 16)
|
|
74
|
+
OGG_OPUS_24KHZ_MONO_32KBPS = ("opus", 24000, "mono", 32)
|
|
75
|
+
OGG_OPUS_24KHZ_MONO_64KBPS = ("opus", 24000, "mono", 64)
|
|
76
|
+
OGG_OPUS_48KHZ_MONO_16KBPS = ("opus", 48000, "mono", 16)
|
|
77
|
+
OGG_OPUS_48KHZ_MONO_32KBPS = ("opus", 48000, "mono", 32)
|
|
78
|
+
OGG_OPUS_48KHZ_MONO_64KBPS = ("opus", 48000, "mono", 64)
|
|
68
79
|
def __init__(self, format, sample_rate, channels, bit_rate):
|
|
69
80
|
self.format = format
|
|
70
81
|
self.sample_rate = sample_rate
|
|
@@ -83,6 +94,7 @@ class Request:
|
|
|
83
94
|
voice,
|
|
84
95
|
format='wav',
|
|
85
96
|
sample_rate=16000,
|
|
97
|
+
bit_rate=64000,
|
|
86
98
|
volume=50,
|
|
87
99
|
speech_rate=1.0,
|
|
88
100
|
pitch_rate=1.0,
|
|
@@ -93,6 +105,7 @@ class Request:
|
|
|
93
105
|
self.model = model
|
|
94
106
|
self.format = format
|
|
95
107
|
self.sample_rate = sample_rate
|
|
108
|
+
self.bit_rate = bit_rate
|
|
96
109
|
self.volume = volume
|
|
97
110
|
self.speech_rate = speech_rate
|
|
98
111
|
self.pitch_rate = pitch_rate
|
|
@@ -146,6 +159,8 @@ class Request:
|
|
|
146
159
|
},
|
|
147
160
|
},
|
|
148
161
|
}
|
|
162
|
+
if self.format == 'opus':
|
|
163
|
+
cmd['payload']['parameters']['bit_rate'] = self.bit_rate
|
|
149
164
|
if additional_params:
|
|
150
165
|
cmd['payload']['parameters'].update(additional_params)
|
|
151
166
|
return json.dumps(cmd)
|
|
@@ -252,6 +267,7 @@ class SpeechSynthesizer:
|
|
|
252
267
|
voice=voice,
|
|
253
268
|
format=format.format,
|
|
254
269
|
sample_rate=format.sample_rate,
|
|
270
|
+
bit_rate = format.bit_rate,
|
|
255
271
|
volume=volume,
|
|
256
272
|
speech_rate=speech_rate,
|
|
257
273
|
pitch_rate=pitch_rate,
|
dashscope/cli.py
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import argparse
|
|
3
3
|
import sys
|
|
4
4
|
import time
|
|
5
|
+
import os
|
|
5
6
|
from http import HTTPStatus
|
|
6
7
|
|
|
7
8
|
import dashscope
|
|
8
9
|
from dashscope.aigc import Generation
|
|
9
10
|
from dashscope.common.constants import (DeploymentStatus, FilePurpose,
|
|
10
11
|
TaskStatus)
|
|
12
|
+
from dashscope.utils.oss_utils import OssUtils
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
def print_failed_message(rsp):
|
|
@@ -193,6 +195,34 @@ class FineTunes:
|
|
|
193
195
|
else:
|
|
194
196
|
print_failed_message(rsp)
|
|
195
197
|
|
|
198
|
+
class Oss:
|
|
199
|
+
@classmethod
|
|
200
|
+
def upload(cls, args):
|
|
201
|
+
print('Start oss.upload: model=%s, file=%s, api_key=%s' % (args.model, args.file, args.api_key))
|
|
202
|
+
if not args.file or not args.model:
|
|
203
|
+
print('Please specify the model and file path')
|
|
204
|
+
return
|
|
205
|
+
|
|
206
|
+
file_path = os.path.expanduser(args.file)
|
|
207
|
+
if not os.path.exists(file_path):
|
|
208
|
+
print('File %s does not exist' % file_path)
|
|
209
|
+
return
|
|
210
|
+
|
|
211
|
+
api_key = os.environ.get('DASHSCOPE_API_KEY', args.api_key)
|
|
212
|
+
if not api_key:
|
|
213
|
+
print('Please set your DashScope API key as environment variable '
|
|
214
|
+
'DASHSCOPE_API_KEY or pass it as argument by -k/--api_key')
|
|
215
|
+
return
|
|
216
|
+
|
|
217
|
+
oss_url = OssUtils.upload(model=args.model,
|
|
218
|
+
file_path=file_path,
|
|
219
|
+
api_key=api_key)
|
|
220
|
+
|
|
221
|
+
if not oss_url:
|
|
222
|
+
print('Failed to upload file: %s' % file_path)
|
|
223
|
+
return
|
|
224
|
+
|
|
225
|
+
print('Uploaded oss url: %s' % oss_url)
|
|
196
226
|
|
|
197
227
|
class Files:
|
|
198
228
|
@classmethod
|
|
@@ -477,6 +507,30 @@ def main():
|
|
|
477
507
|
help='The fine-tune job id.')
|
|
478
508
|
fine_tune_cancel.set_defaults(func=FineTunes.cancel)
|
|
479
509
|
|
|
510
|
+
oss_upload = sub_parsers.add_parser('oss.upload')
|
|
511
|
+
oss_upload.add_argument(
|
|
512
|
+
'-f',
|
|
513
|
+
'--file',
|
|
514
|
+
type=str,
|
|
515
|
+
required=True,
|
|
516
|
+
help='The file path to upload',
|
|
517
|
+
)
|
|
518
|
+
oss_upload.add_argument(
|
|
519
|
+
'-m',
|
|
520
|
+
'--model',
|
|
521
|
+
type=str,
|
|
522
|
+
required=True,
|
|
523
|
+
help='The model name',
|
|
524
|
+
)
|
|
525
|
+
oss_upload.add_argument(
|
|
526
|
+
'-k',
|
|
527
|
+
'--api_key',
|
|
528
|
+
type=str,
|
|
529
|
+
required=False,
|
|
530
|
+
help='The dashscope api key',
|
|
531
|
+
)
|
|
532
|
+
oss_upload.set_defaults(func=Oss.upload)
|
|
533
|
+
|
|
480
534
|
file_upload = sub_parsers.add_parser('files.upload')
|
|
481
535
|
file_upload.add_argument(
|
|
482
536
|
'-f',
|
|
@@ -81,6 +81,7 @@ class Upstream:
|
|
|
81
81
|
type: str = field(default="AudioOnly") # 上行类型:AudioOnly 仅语音通话; AudioAndVideo 上传视频
|
|
82
82
|
mode: str = field(default="tap2talk") # 客户端交互模式 push2talk/tap2talk/duplex
|
|
83
83
|
# sample_rate: int # 合成音频采样率
|
|
84
|
+
pass_through_params: dict = field(default=None)
|
|
84
85
|
|
|
85
86
|
def to_dict(self):
|
|
86
87
|
upstream: dict = {
|
|
File without changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from typing import Dict, Any
|
|
2
|
+
|
|
3
|
+
from dashscope.api_entities.api_request_factory import _build_api_request
|
|
4
|
+
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
5
|
+
from dashscope.client.base_api import BaseApi
|
|
6
|
+
from dashscope.common.error import ModelRequired
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TingWu(BaseApi):
|
|
10
|
+
"""API for TingWu APP.
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
task = None
|
|
15
|
+
task_group = None
|
|
16
|
+
function = None
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def call(
|
|
20
|
+
cls,
|
|
21
|
+
model: str,
|
|
22
|
+
user_defined_input: Dict[str, Any],
|
|
23
|
+
parameters: Dict[str, Any] = None,
|
|
24
|
+
api_key: str = None,
|
|
25
|
+
**kwargs
|
|
26
|
+
) -> DashScopeAPIResponse:
|
|
27
|
+
"""Call generation model service.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
model (str): The requested model, such as qwen-turbo
|
|
31
|
+
api_key (str, optional): The api api_key, can be None,
|
|
32
|
+
if None, will get by default rule(TODO: api key doc).
|
|
33
|
+
user_defined_input: custom input
|
|
34
|
+
parameters: custom parameters
|
|
35
|
+
**kwargs:
|
|
36
|
+
base_address: base address
|
|
37
|
+
additional parameters for request
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
InvalidInput: The history and auto_history are mutually exclusive.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
Union[GenerationResponse,
|
|
44
|
+
Generator[GenerationResponse, None, None]]: If
|
|
45
|
+
stream is True, return Generator, otherwise GenerationResponse.
|
|
46
|
+
"""
|
|
47
|
+
if model is None or not model:
|
|
48
|
+
raise ModelRequired('Model is required!')
|
|
49
|
+
input_config, parameters = cls._build_input_parameters(input_config=user_defined_input,
|
|
50
|
+
params=parameters,
|
|
51
|
+
**kwargs)
|
|
52
|
+
|
|
53
|
+
request = _build_api_request(
|
|
54
|
+
model=model,
|
|
55
|
+
input=input_config,
|
|
56
|
+
api_key=api_key,
|
|
57
|
+
task_group=TingWu.task_group,
|
|
58
|
+
task=TingWu.task,
|
|
59
|
+
function=TingWu.function,
|
|
60
|
+
is_service=False,
|
|
61
|
+
**parameters)
|
|
62
|
+
response = request.call()
|
|
63
|
+
|
|
64
|
+
return response
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def _build_input_parameters(cls,
|
|
68
|
+
input_config,
|
|
69
|
+
params: Dict[str, Any] = None,
|
|
70
|
+
**kwargs):
|
|
71
|
+
parameters = {}
|
|
72
|
+
if params is not None:
|
|
73
|
+
parameters = params
|
|
74
|
+
|
|
75
|
+
input_param = input_config
|
|
76
|
+
|
|
77
|
+
if kwargs.keys() is not None:
|
|
78
|
+
for key in kwargs.keys():
|
|
79
|
+
parameters[key] = kwargs[key]
|
|
80
|
+
return input_param, {**parameters, **kwargs}
|
dashscope/threads/runs/runs.py
CHANGED
|
@@ -82,6 +82,10 @@ class Runs(CreateMixin, CancelMixin, ListObjectMixin, GetStatusMixin,
|
|
|
82
82
|
workspace: str = None,
|
|
83
83
|
extra_body: Optional[Dict] = None,
|
|
84
84
|
api_key: str = None,
|
|
85
|
+
top_p: Optional[float] = None,
|
|
86
|
+
top_k: Optional[int] = None,
|
|
87
|
+
temperature: Optional[float] = None,
|
|
88
|
+
max_tokens: Optional[int] = None,
|
|
85
89
|
**kwargs) -> Run:
|
|
86
90
|
"""Create a run.
|
|
87
91
|
|
|
@@ -122,6 +126,15 @@ class Runs(CreateMixin, CancelMixin, ListObjectMixin, GetStatusMixin,
|
|
|
122
126
|
if extra_body is not None and extra_body:
|
|
123
127
|
data = {**data, **extra_body}
|
|
124
128
|
|
|
129
|
+
if top_p is not None:
|
|
130
|
+
data['top_p'] = top_p
|
|
131
|
+
if top_k is not None:
|
|
132
|
+
data['top_k'] = top_k
|
|
133
|
+
if temperature is not None:
|
|
134
|
+
data['temperature'] = temperature
|
|
135
|
+
if max_tokens is not None:
|
|
136
|
+
data['max_tokens'] = max_tokens
|
|
137
|
+
|
|
125
138
|
response = super().call(data=data,
|
|
126
139
|
path=f'threads/{thread_id}/runs',
|
|
127
140
|
api_key=api_key,
|
|
@@ -180,6 +193,10 @@ class Runs(CreateMixin, CancelMixin, ListObjectMixin, GetStatusMixin,
|
|
|
180
193
|
workspace: str = None,
|
|
181
194
|
extra_body: Optional[Dict] = None,
|
|
182
195
|
api_key: str = None,
|
|
196
|
+
top_p: Optional[float] = None,
|
|
197
|
+
top_k: Optional[int] = None,
|
|
198
|
+
temperature: Optional[float] = None,
|
|
199
|
+
max_tokens: Optional[int] = None,
|
|
183
200
|
**kwargs) -> Run:
|
|
184
201
|
"""Create a run.
|
|
185
202
|
|
|
@@ -214,6 +231,10 @@ class Runs(CreateMixin, CancelMixin, ListObjectMixin, GetStatusMixin,
|
|
|
214
231
|
workspace=workspace,
|
|
215
232
|
extra_body=extra_body,
|
|
216
233
|
api_key=api_key,
|
|
234
|
+
top_p=top_p,
|
|
235
|
+
top_k=top_k,
|
|
236
|
+
temperature=temperature,
|
|
237
|
+
max_tokens=max_tokens,
|
|
217
238
|
**kwargs)
|
|
218
239
|
|
|
219
240
|
@classmethod
|
|
@@ -51,6 +51,13 @@ class Usage(BaseObjectMixin):
|
|
|
51
51
|
|
|
52
52
|
total_tokens: int
|
|
53
53
|
"""Total number of tokens used (prompt + completion)."""
|
|
54
|
+
|
|
55
|
+
input_tokens: int
|
|
56
|
+
"""Input tokens used (prompt)."""
|
|
57
|
+
|
|
58
|
+
output_tokens: int
|
|
59
|
+
"""Output tokens used (completion)."""
|
|
60
|
+
|
|
54
61
|
def __init__(self, **kwargs):
|
|
55
62
|
super().__init__(**kwargs)
|
|
56
63
|
|
|
@@ -302,6 +309,11 @@ class Run(BaseObjectMixin):
|
|
|
302
309
|
|
|
303
310
|
tools: List[Tool]
|
|
304
311
|
|
|
312
|
+
top_p: Optional[float] = None
|
|
313
|
+
top_k: Optional[int] = None
|
|
314
|
+
temperature: Optional[float] = None
|
|
315
|
+
max_tokens: Optional[int] = None
|
|
316
|
+
|
|
305
317
|
usage: Optional[Usage] = None
|
|
306
318
|
|
|
307
319
|
def __init__(self, **kwargs):
|
dashscope/utils/oss_utils.py
CHANGED
|
@@ -154,7 +154,10 @@ def check_and_upload_local(model: str, content: str, api_key: str):
|
|
|
154
154
|
return True, file_url
|
|
155
155
|
else:
|
|
156
156
|
raise InvalidInput('The file: %s is not exists!' % file_path)
|
|
157
|
+
elif content.startswith('oss://'):
|
|
158
|
+
return True, content
|
|
157
159
|
elif not content.startswith('http'):
|
|
160
|
+
content = os.path.expanduser(content)
|
|
158
161
|
if os.path.isfile(content):
|
|
159
162
|
file_url = OssUtils.upload(model=model,
|
|
160
163
|
file_path=content,
|
dashscope/version.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
dashscope/__init__.py,sha256=__BY0dzgFX5Bt50WL-2PJmI8EYOmnpXhABQntdqDtSM,3062
|
|
2
|
-
dashscope/cli.py,sha256=
|
|
2
|
+
dashscope/cli.py,sha256=BfABF8T7uVttfHTSCqGiIcA_XuiYUfCnQ9WLvSUV0Ys,25646
|
|
3
3
|
dashscope/files.py,sha256=vRDQygm3lOqBZR73o7KNHs1iTBVuvLncuwJNxIYjzAU,3981
|
|
4
4
|
dashscope/model.py,sha256=B5v_BtYLPqj6raClejBgdKg6WTGwhH_f-20pvsQqmsk,1491
|
|
5
5
|
dashscope/models.py,sha256=dE4mzXkl85G343qVylSGpURPRdA5pZSqXlx6PcxqC_Q,1275
|
|
6
|
-
dashscope/version.py,sha256=
|
|
6
|
+
dashscope/version.py,sha256=nxaFMFG8XljEkSkDtFtMZoYaJS2vs0B00JCGab12YHI,74
|
|
7
7
|
dashscope/aigc/__init__.py,sha256=AuRhu_vA1K0tbs_C6DgcZYhTvxMuzDgpwHJNHzEPIHg,442
|
|
8
8
|
dashscope/aigc/chat_completion.py,sha256=ONlyyssIbfaKKcFo7cEKhHx5OCF2XX810HFzIExW1ho,14813
|
|
9
9
|
dashscope/aigc/code_generation.py,sha256=p_mxDKJLQMW0IjFD46JRlZuEZCRESSVKEfLlAevBtqw,10936
|
|
@@ -24,11 +24,11 @@ dashscope/api_entities/http_request.py,sha256=p2xfmq79evNON4ctCVXCcrJo8jnKABn0Xz
|
|
|
24
24
|
dashscope/api_entities/websocket_request.py,sha256=PS0FU854-HjTbKa68f4GHa7-noFRMzKySJGfPkrrBjw,16146
|
|
25
25
|
dashscope/app/__init__.py,sha256=xvSvU8O7m5u7vgIvJXTJektJZxmjT2Rpt_YwePH88XE,113
|
|
26
26
|
dashscope/app/application.py,sha256=Whf_ij4RHOaY12_xdS8uj8HVNCwkTp_MRdrFTryF1Kg,9472
|
|
27
|
-
dashscope/app/application_response.py,sha256=
|
|
27
|
+
dashscope/app/application_response.py,sha256=XO6iOZlt7OXulvFS71zwAq_HXYkn3HLJdAimTWPP0B4,8568
|
|
28
28
|
dashscope/assistants/__init__.py,sha256=hjCTuv13yFaXyUqlexAU-RaO0Ahq3P7VK9_LkSbkGVU,434
|
|
29
|
-
dashscope/assistants/assistant_types.py,sha256=
|
|
30
|
-
dashscope/assistants/assistants.py,sha256=
|
|
31
|
-
dashscope/assistants/files.py,sha256=
|
|
29
|
+
dashscope/assistants/assistant_types.py,sha256=qVDSy0xcsMq_sAD7t_ppoGLBN2QDiHqarAAlW_CDDtY,4478
|
|
30
|
+
dashscope/assistants/assistants.py,sha256=X6wUEFkpMwQBkjcBaraux0-gu6nwEWD0BUGfygLAE0A,12531
|
|
31
|
+
dashscope/assistants/files.py,sha256=CaQkZK7TFeMaAxtqMi-1rBVJrlKXdehZG9plNZ6zslo,7060
|
|
32
32
|
dashscope/audio/__init__.py,sha256=7e3ejVsDJxEbMHN-9E0nEDfU-CnnQ4JgtgUxqNs0IG4,192
|
|
33
33
|
dashscope/audio/asr/__init__.py,sha256=JoCenJAUVOQXPmAn1toKeFYCfc8BqNn0NKpqjuJvNJc,1055
|
|
34
34
|
dashscope/audio/asr/asr_phrase_manager.py,sha256=vHOLExaKCtjedkihIu7gyfQyarR9rN5JZn79LvlCpco,7693
|
|
@@ -46,7 +46,7 @@ dashscope/audio/tts/__init__.py,sha256=xYpMFseUZGgqgj_70zcX2VsLv-L7qxJ3d-bbdj_hO
|
|
|
46
46
|
dashscope/audio/tts/speech_synthesizer.py,sha256=vD1xQV-rew8qAsIaAGH5amsNtB0SqdtNhVHhJHGQ-xk,7622
|
|
47
47
|
dashscope/audio/tts_v2/__init__.py,sha256=me9a3_7KsHQxcJ8hx4SeKlY1e_ThHVvGMw7Yn0uoscM,333
|
|
48
48
|
dashscope/audio/tts_v2/enrollment.py,sha256=-nrlywYSOP73Bm9ETTSxNnlp-B8ezJcUmd59mVvyvgk,6361
|
|
49
|
-
dashscope/audio/tts_v2/speech_synthesizer.py,sha256=
|
|
49
|
+
dashscope/audio/tts_v2/speech_synthesizer.py,sha256=jbTwybwJjhbgUa6TgeLUYnkDBkmk-tjzxta1FtYeWAk,20824
|
|
50
50
|
dashscope/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
51
51
|
dashscope/client/base_api.py,sha256=aWNy_xm02GXuLKVgWnYJht2nI4ZHSGfYIcr52SML15A,41239
|
|
52
52
|
dashscope/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -73,7 +73,9 @@ dashscope/multimodal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
|
73
73
|
dashscope/multimodal/dialog_state.py,sha256=CtOdfGWhq0ePG3bc8-7inhespETtPD4QDli1513hd1A,1522
|
|
74
74
|
dashscope/multimodal/multimodal_constants.py,sha256=z_QVq01E43FAqKQnDu9vdf89d1zuYlWyANewWTEXVJM,1282
|
|
75
75
|
dashscope/multimodal/multimodal_dialog.py,sha256=HymlaQYp7SgJdoKbT27SNiviyRRoM91zklNBwTHmm1Q,23939
|
|
76
|
-
dashscope/multimodal/multimodal_request_params.py,sha256=
|
|
76
|
+
dashscope/multimodal/multimodal_request_params.py,sha256=Lbxf_kLnFUkhty8AU9wL7ws9tYbmhHPVmsiXLdynlJg,8402
|
|
77
|
+
dashscope/multimodal/tingwu/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
78
|
+
dashscope/multimodal/tingwu/tingwu.py,sha256=01d-QOeuB1QmRhiZqbXJ8pHoGqT0C-xZTjIs_ZBXOyw,2613
|
|
77
79
|
dashscope/nlp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
78
80
|
dashscope/nlp/understanding.py,sha256=00ado-ibYEzBRT0DgKGd3bohQDNW73xnFhJ_1aa87lw,2880
|
|
79
81
|
dashscope/protocol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -82,13 +84,13 @@ dashscope/rerank/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
|
|
|
82
84
|
dashscope/rerank/text_rerank.py,sha256=NKN3vnWprguhHy2_g0D7znZ7jEGrLX4zMaLE3jBrl94,2449
|
|
83
85
|
dashscope/resources/qwen.tiktoken,sha256=srG437XMXwJLr8NzEhxquj9m-aWgJp4kNHCh3hajMYY,2561218
|
|
84
86
|
dashscope/threads/__init__.py,sha256=3IKX9vZWhT87XrVx1pA_g3MWHEekXoJJSZeE_CTWL08,672
|
|
85
|
-
dashscope/threads/thread_types.py,sha256=
|
|
87
|
+
dashscope/threads/thread_types.py,sha256=brek-eTM9147TAlDxpLKlFcp-JBcSNo6Slg76t0O_dk,18604
|
|
86
88
|
dashscope/threads/threads.py,sha256=J9QGY0vy6MldC4ujQMyiYc9jN4aH9NGj0SkcWZHwkj0,7716
|
|
87
89
|
dashscope/threads/messages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
88
90
|
dashscope/threads/messages/files.py,sha256=WxKVQednISIh2MY8N1B6Y4HjGllFhcLKCsc4QXKZ6AQ,3871
|
|
89
91
|
dashscope/threads/messages/messages.py,sha256=peKqehK8JO0ZwRXACaojg6-61TkBBbqd190xtKIbOZo,8470
|
|
90
92
|
dashscope/threads/runs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
91
|
-
dashscope/threads/runs/runs.py,sha256=
|
|
93
|
+
dashscope/threads/runs/runs.py,sha256=PsUL5IFw-kF8WXEl_CnL1vMGIuP7S7MWzkLhHJCCKDA,19442
|
|
92
94
|
dashscope/threads/runs/steps.py,sha256=579EsCOwsamuJMSNrrrX86h9JfMdXNlErVJ8XakSqSc,3689
|
|
93
95
|
dashscope/tokenizers/__init__.py,sha256=TvVAsDam5S0R4rorxdfyUGIEQQX1q8nQ--RxsWWos3A,251
|
|
94
96
|
dashscope/tokenizers/qwen_tokenizer.py,sha256=tvX7x34Rg_NFFc1XjneXNFfXVkePdqkgHHShce2RJGo,4162
|
|
@@ -96,10 +98,10 @@ dashscope/tokenizers/tokenization.py,sha256=ubQBJ_yw_MoHuHxZcK9NarZSSbyExloeSOLI
|
|
|
96
98
|
dashscope/tokenizers/tokenizer.py,sha256=3FQVDvMNkCW9ccYeJdjrd_PIMMD3Xv7aNZkaYOE4XX4,1205
|
|
97
99
|
dashscope/tokenizers/tokenizer_base.py,sha256=5EJIFuizMWESEmLmbd38yJnfeHmPnzZPwsO4aOGjpl4,707
|
|
98
100
|
dashscope/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
99
|
-
dashscope/utils/oss_utils.py,sha256=
|
|
100
|
-
dashscope-1.
|
|
101
|
-
dashscope-1.
|
|
102
|
-
dashscope-1.
|
|
103
|
-
dashscope-1.
|
|
104
|
-
dashscope-1.
|
|
105
|
-
dashscope-1.
|
|
101
|
+
dashscope/utils/oss_utils.py,sha256=VHdHBVYNmWEWS2Kgz_2xMwCtqJqDVjWb5logIkESBsA,7497
|
|
102
|
+
dashscope-1.24.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
103
|
+
dashscope-1.24.1.dist-info/METADATA,sha256=2bnSvO77hyC19Y8iu_nSz9CB_yocV6f1ksqYMqbdLgE,7123
|
|
104
|
+
dashscope-1.24.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
105
|
+
dashscope-1.24.1.dist-info/entry_points.txt,sha256=e9C3sOf9zDYL0O5ROEGX6FT8w-QK_kaGRWmPZDHAFys,49
|
|
106
|
+
dashscope-1.24.1.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
|
|
107
|
+
dashscope-1.24.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|