dashscope 1.16.0__py3-none-any.whl → 1.17.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 +25 -3
- dashscope/aigc/code_generation.py +12 -9
- dashscope/aigc/conversation.py +3 -0
- dashscope/aigc/generation.py +3 -0
- dashscope/aigc/image_synthesis.py +21 -6
- dashscope/aigc/multimodal_conversation.py +3 -0
- dashscope/api_entities/aiohttp_request.py +1 -0
- dashscope/api_entities/api_request_factory.py +28 -12
- dashscope/api_entities/http_request.py +18 -9
- dashscope/api_entities/websocket_request.py +3 -0
- dashscope/app/application.py +16 -23
- dashscope/assistants/__init__.py +14 -0
- dashscope/assistants/assistant_types.py +164 -0
- dashscope/assistants/assistants.py +280 -0
- dashscope/assistants/files.py +189 -0
- dashscope/audio/asr/asr_phrase_manager.py +27 -5
- dashscope/audio/asr/recognition.py +10 -2
- dashscope/audio/asr/transcription.py +21 -3
- dashscope/audio/tts/speech_synthesizer.py +3 -0
- dashscope/cli.py +7 -7
- dashscope/client/base_api.py +303 -68
- dashscope/common/base_type.py +130 -0
- dashscope/common/constants.py +1 -0
- dashscope/common/error.py +4 -0
- dashscope/common/utils.py +22 -6
- dashscope/deployment.py +40 -6
- dashscope/embeddings/batch_text_embedding.py +24 -7
- dashscope/embeddings/multimodal_embedding.py +3 -0
- dashscope/embeddings/text_embedding.py +8 -1
- dashscope/files.py +107 -0
- dashscope/finetune.py +31 -7
- dashscope/model.py +9 -2
- dashscope/models.py +47 -0
- dashscope/nlp/understanding.py +2 -2
- dashscope/threads/__init__.py +24 -0
- dashscope/threads/messages/__init__.py +0 -0
- dashscope/threads/messages/files.py +111 -0
- dashscope/threads/messages/messages.py +218 -0
- dashscope/threads/runs/__init__.py +0 -0
- dashscope/threads/runs/runs.py +408 -0
- dashscope/threads/runs/steps.py +110 -0
- dashscope/threads/thread_types.py +571 -0
- dashscope/threads/threads.py +210 -0
- dashscope/tokenizers/tokenization.py +3 -0
- dashscope/utils/oss_utils.py +11 -0
- dashscope/version.py +1 -1
- {dashscope-1.16.0.dist-info → dashscope-1.17.0.dist-info}/METADATA +2 -3
- dashscope-1.17.0.dist-info/RECORD +84 -0
- dashscope-1.16.0.dist-info/RECORD +0 -68
- {dashscope-1.16.0.dist-info → dashscope-1.17.0.dist-info}/LICENSE +0 -0
- {dashscope-1.16.0.dist-info → dashscope-1.17.0.dist-info}/WHEEL +0 -0
- {dashscope-1.16.0.dist-info → dashscope-1.17.0.dist-info}/entry_points.txt +0 -0
- {dashscope-1.16.0.dist-info → dashscope-1.17.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# adapter from openai sdk
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Dict, List, Optional, Union
|
|
4
|
+
|
|
5
|
+
from dashscope.common.base_type import BaseList, BaseObjectMixin
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'Assistant', 'AssistantFile', 'ToolCodeInterpreter', 'ToolSearch',
|
|
9
|
+
'ToolWanX', 'FunctionDefinition', 'ToolFunction', 'AssistantFileList',
|
|
10
|
+
'AssistantList', 'DeleteResponse'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(init=False)
|
|
15
|
+
class AssistantFile(BaseObjectMixin):
|
|
16
|
+
id: str
|
|
17
|
+
assistant_id: str
|
|
18
|
+
created_at: int
|
|
19
|
+
object: str
|
|
20
|
+
|
|
21
|
+
def __init__(self, **kwargs):
|
|
22
|
+
super().__init__(**kwargs)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(init=False)
|
|
26
|
+
class ToolCodeInterpreter(BaseObjectMixin):
|
|
27
|
+
type: str = 'code_interpreter'
|
|
28
|
+
|
|
29
|
+
def __init__(self, **kwargs):
|
|
30
|
+
super().__init__(**kwargs)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(init=False)
|
|
34
|
+
class ToolSearch(BaseObjectMixin):
|
|
35
|
+
type: str = 'search'
|
|
36
|
+
|
|
37
|
+
def __init__(self, **kwargs):
|
|
38
|
+
super().__init__(**kwargs)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(init=False)
|
|
42
|
+
class ToolWanX(BaseObjectMixin):
|
|
43
|
+
type: str = 'wanx'
|
|
44
|
+
|
|
45
|
+
def __init__(self, **kwargs):
|
|
46
|
+
super().__init__(**kwargs)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(init=False)
|
|
50
|
+
class FunctionDefinition(BaseObjectMixin):
|
|
51
|
+
name: str
|
|
52
|
+
description: Optional[str] = None
|
|
53
|
+
parameters: Optional[Dict[str, object]] = None
|
|
54
|
+
|
|
55
|
+
def __init__(self, **kwargs):
|
|
56
|
+
super().__init__(**kwargs)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(init=False)
|
|
60
|
+
class ToolFunction(BaseObjectMixin):
|
|
61
|
+
function: FunctionDefinition
|
|
62
|
+
type: str = 'function'
|
|
63
|
+
|
|
64
|
+
def __init__(self, **kwargs):
|
|
65
|
+
self.function = FunctionDefinition(**kwargs.pop('function', {}))
|
|
66
|
+
super().__init__(**kwargs)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Tool = Union[ToolCodeInterpreter, ToolSearch, ToolFunction, ToolWanX]
|
|
70
|
+
ASSISTANT_SUPPORT_TOOL = {
|
|
71
|
+
'code_interpreter': ToolCodeInterpreter,
|
|
72
|
+
'search': ToolSearch,
|
|
73
|
+
'wanx': ToolWanX,
|
|
74
|
+
'function': ToolFunction
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def convert_tools_dict_to_objects(tools):
|
|
79
|
+
tools_object = []
|
|
80
|
+
for tool in tools:
|
|
81
|
+
if 'type' in tool:
|
|
82
|
+
tool_type = ASSISTANT_SUPPORT_TOOL.get(tool['type'], None)
|
|
83
|
+
if tool_type:
|
|
84
|
+
tools_object.append(tool_type(**tool))
|
|
85
|
+
else:
|
|
86
|
+
tools_object.append(tool)
|
|
87
|
+
else:
|
|
88
|
+
tools_object.append(tool)
|
|
89
|
+
return tools_object
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass(init=False)
|
|
93
|
+
class Assistant(BaseObjectMixin):
|
|
94
|
+
status_code: int
|
|
95
|
+
"""The call response status_code, 200 indicate create success.
|
|
96
|
+
"""
|
|
97
|
+
code: str
|
|
98
|
+
"""The request failed, this is the error code.
|
|
99
|
+
"""
|
|
100
|
+
message: str
|
|
101
|
+
"""The request failed, this is the error message.
|
|
102
|
+
"""
|
|
103
|
+
id: str
|
|
104
|
+
"""ID of the assistant.
|
|
105
|
+
"""
|
|
106
|
+
model: str
|
|
107
|
+
name: Optional[str] = None
|
|
108
|
+
created_at: int
|
|
109
|
+
"""The Unix timestamp (in seconds) for when the assistant was created.
|
|
110
|
+
"""
|
|
111
|
+
description: Optional[str] = None
|
|
112
|
+
|
|
113
|
+
file_ids: List[str]
|
|
114
|
+
|
|
115
|
+
instructions: Optional[str] = None
|
|
116
|
+
metadata: Optional[object] = None
|
|
117
|
+
tools: List[Tool]
|
|
118
|
+
|
|
119
|
+
def __init__(self, **kwargs):
|
|
120
|
+
self.tools = convert_tools_dict_to_objects(kwargs.pop('tools', []))
|
|
121
|
+
super().__init__(**kwargs)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@dataclass(init=False)
|
|
125
|
+
class AssistantList(BaseList):
|
|
126
|
+
data: List[Assistant]
|
|
127
|
+
|
|
128
|
+
def __init__(self,
|
|
129
|
+
has_more: bool = None,
|
|
130
|
+
last_id: Optional[str] = None,
|
|
131
|
+
first_id: Optional[str] = None,
|
|
132
|
+
data: List[Assistant] = [],
|
|
133
|
+
**kwargs):
|
|
134
|
+
super().__init__(has_more=has_more,
|
|
135
|
+
last_id=last_id,
|
|
136
|
+
first_id=first_id,
|
|
137
|
+
data=data,
|
|
138
|
+
**kwargs)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@dataclass(init=False)
|
|
142
|
+
class AssistantFileList(BaseList):
|
|
143
|
+
data: List[AssistantFile]
|
|
144
|
+
|
|
145
|
+
def __init__(self,
|
|
146
|
+
has_more: bool = None,
|
|
147
|
+
last_id: Optional[str] = None,
|
|
148
|
+
first_id: Optional[str] = None,
|
|
149
|
+
data: List[AssistantFile] = [],
|
|
150
|
+
**kwargs):
|
|
151
|
+
super().__init__(has_more=has_more,
|
|
152
|
+
last_id=last_id,
|
|
153
|
+
first_id=first_id,
|
|
154
|
+
data=data,
|
|
155
|
+
**kwargs)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@dataclass(init=False)
|
|
159
|
+
class DeleteResponse(BaseObjectMixin):
|
|
160
|
+
id: str
|
|
161
|
+
deleted: bool
|
|
162
|
+
|
|
163
|
+
def __init__(self, **kwargs):
|
|
164
|
+
super().__init__(**kwargs)
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
from typing import Dict, List, Optional
|
|
2
|
+
|
|
3
|
+
from dashscope.assistants.assistant_types import (Assistant, AssistantList,
|
|
4
|
+
DeleteResponse)
|
|
5
|
+
from dashscope.client.base_api import (CancelMixin, CreateMixin, DeleteMixin,
|
|
6
|
+
GetStatusMixin, ListObjectMixin,
|
|
7
|
+
UpdateMixin)
|
|
8
|
+
from dashscope.common.error import ModelRequired
|
|
9
|
+
|
|
10
|
+
__all__ = ['Assistants']
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
14
|
+
GetStatusMixin, UpdateMixin):
|
|
15
|
+
SUB_PATH = 'assistants'
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def _create_assistant_object(
|
|
19
|
+
cls,
|
|
20
|
+
model: str = None,
|
|
21
|
+
name: str = None,
|
|
22
|
+
description: str = None,
|
|
23
|
+
instructions: str = None,
|
|
24
|
+
tools: Optional[str] = [],
|
|
25
|
+
file_ids: Optional[str] = [],
|
|
26
|
+
metadata: Dict = {},
|
|
27
|
+
):
|
|
28
|
+
obj = {}
|
|
29
|
+
if model:
|
|
30
|
+
obj['model'] = model
|
|
31
|
+
if name:
|
|
32
|
+
obj['name'] = name
|
|
33
|
+
if description:
|
|
34
|
+
obj['description'] = description
|
|
35
|
+
if instructions:
|
|
36
|
+
obj['instructions'] = instructions
|
|
37
|
+
if tools:
|
|
38
|
+
obj['tools'] = tools
|
|
39
|
+
obj['file_ids'] = file_ids
|
|
40
|
+
obj['metadata'] = metadata
|
|
41
|
+
|
|
42
|
+
return obj
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def call(cls,
|
|
46
|
+
*,
|
|
47
|
+
model: str,
|
|
48
|
+
name: str = None,
|
|
49
|
+
description: str = None,
|
|
50
|
+
instructions: str = None,
|
|
51
|
+
tools: Optional[List[Dict]] = [],
|
|
52
|
+
file_ids: Optional[List[str]] = [],
|
|
53
|
+
metadata: Dict = None,
|
|
54
|
+
workspace: str = None,
|
|
55
|
+
api_key: str = None,
|
|
56
|
+
**kwargs) -> Assistant:
|
|
57
|
+
"""Create Assistant.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
model (str): The model to use.
|
|
61
|
+
name (str, optional): The assistant name. Defaults to None.
|
|
62
|
+
description (str, optional): The assistant description. Defaults to None.
|
|
63
|
+
instructions (str, optional): The system instructions this assistant uses. Defaults to None.
|
|
64
|
+
tools (Optional[List[Dict]], optional): List of tools to use. Defaults to [].
|
|
65
|
+
file_ids (Optional[List[str]], optional): : The files to use. Defaults to [].
|
|
66
|
+
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
|
67
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
68
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
69
|
+
|
|
70
|
+
Raises:
|
|
71
|
+
ModelRequired: The model is required.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
Assistant: The `Assistant` object.
|
|
75
|
+
"""
|
|
76
|
+
return cls.create(model=model,
|
|
77
|
+
name=name,
|
|
78
|
+
description=description,
|
|
79
|
+
instructions=instructions,
|
|
80
|
+
tools=tools,
|
|
81
|
+
file_ids=file_ids,
|
|
82
|
+
metadata=metadata,
|
|
83
|
+
workspace=workspace,
|
|
84
|
+
api_key=api_key,
|
|
85
|
+
**kwargs)
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def create(cls,
|
|
89
|
+
*,
|
|
90
|
+
model: str,
|
|
91
|
+
name: str = None,
|
|
92
|
+
description: str = None,
|
|
93
|
+
instructions: str = None,
|
|
94
|
+
tools: Optional[List[Dict]] = [],
|
|
95
|
+
file_ids: Optional[List[str]] = [],
|
|
96
|
+
metadata: Dict = None,
|
|
97
|
+
workspace: str = None,
|
|
98
|
+
api_key: str = None,
|
|
99
|
+
**kwargs) -> Assistant:
|
|
100
|
+
"""Create Assistant.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
model (str): The model to use.
|
|
104
|
+
name (str, optional): The assistant name. Defaults to None.
|
|
105
|
+
description (str, optional): The assistant description. Defaults to None.
|
|
106
|
+
instructions (str, optional): The system instructions this assistant uses. Defaults to None.
|
|
107
|
+
tools (Optional[List[Dict]], optional): List of tools to use. Defaults to [].
|
|
108
|
+
file_ids (Optional[List[str]], optional): : The files to use. Defaults to [].
|
|
109
|
+
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
|
110
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
111
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
112
|
+
|
|
113
|
+
Raises:
|
|
114
|
+
ModelRequired: The model is required.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
Assistant: The `Assistant` object.
|
|
118
|
+
"""
|
|
119
|
+
if not model:
|
|
120
|
+
raise ModelRequired('Model is required!')
|
|
121
|
+
data = cls._create_assistant_object(model, name, description,
|
|
122
|
+
instructions, tools, file_ids,
|
|
123
|
+
metadata)
|
|
124
|
+
response = super().call(data=data,
|
|
125
|
+
api_key=api_key,
|
|
126
|
+
flattened_output=True,
|
|
127
|
+
workspace=workspace,
|
|
128
|
+
**kwargs)
|
|
129
|
+
return Assistant(**response)
|
|
130
|
+
|
|
131
|
+
@classmethod
|
|
132
|
+
def retrieve(cls,
|
|
133
|
+
assistant_id: str,
|
|
134
|
+
*,
|
|
135
|
+
workspace: str = None,
|
|
136
|
+
api_key: str = None,
|
|
137
|
+
**kwargs) -> Assistant:
|
|
138
|
+
"""Get the `Assistant`.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
assistant_id (str): The assistant id.
|
|
142
|
+
workspace (str): The dashscope workspace id.
|
|
143
|
+
api_key (str, optional): The api key. Defaults to None.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
Assistant: The `Assistant` object.
|
|
147
|
+
"""
|
|
148
|
+
return cls.get(assistant_id,
|
|
149
|
+
workspace=workspace,
|
|
150
|
+
api_key=api_key,
|
|
151
|
+
**kwargs)
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def get(cls,
|
|
155
|
+
assistant_id: str,
|
|
156
|
+
*,
|
|
157
|
+
workspace: str = None,
|
|
158
|
+
api_key: str = None,
|
|
159
|
+
**kwargs) -> Assistant:
|
|
160
|
+
"""Get the `Assistant`.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
assistant_id (str): The assistant id.
|
|
164
|
+
workspace (str): The dashscope workspace id.
|
|
165
|
+
api_key (str, optional): The api key. Defaults to None.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
Assistant: The `Assistant` object.
|
|
169
|
+
"""
|
|
170
|
+
if not assistant_id:
|
|
171
|
+
raise ModelRequired('assistant_id is required!')
|
|
172
|
+
response = super().get(assistant_id,
|
|
173
|
+
workspace=workspace,
|
|
174
|
+
api_key=api_key,
|
|
175
|
+
flattened_output=True,
|
|
176
|
+
**kwargs)
|
|
177
|
+
return Assistant(**response)
|
|
178
|
+
|
|
179
|
+
@classmethod
|
|
180
|
+
def list(cls,
|
|
181
|
+
*,
|
|
182
|
+
limit: int = None,
|
|
183
|
+
order: str = None,
|
|
184
|
+
after: str = None,
|
|
185
|
+
before: str = None,
|
|
186
|
+
workspace: str = None,
|
|
187
|
+
api_key: str = None,
|
|
188
|
+
**kwargs) -> AssistantList:
|
|
189
|
+
"""List assistants
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
limit (int, optional): How many assistant to retrieve. Defaults to None.
|
|
193
|
+
order (str, optional): Sort order by created_at. Defaults to None.
|
|
194
|
+
after (str, optional): Assistant id after. Defaults to None.
|
|
195
|
+
before (str, optional): Assistant id before. Defaults to None.
|
|
196
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
197
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
AssistantList: The list of assistants.
|
|
201
|
+
"""
|
|
202
|
+
response = super().list(limit=limit,
|
|
203
|
+
order=order,
|
|
204
|
+
after=after,
|
|
205
|
+
before=before,
|
|
206
|
+
workspace=workspace,
|
|
207
|
+
api_key=api_key,
|
|
208
|
+
flattened_output=True,
|
|
209
|
+
**kwargs)
|
|
210
|
+
return AssistantList(**response)
|
|
211
|
+
|
|
212
|
+
@classmethod
|
|
213
|
+
def update(cls,
|
|
214
|
+
assistant_id: str,
|
|
215
|
+
*,
|
|
216
|
+
model: str = None,
|
|
217
|
+
name: str = None,
|
|
218
|
+
description: str = None,
|
|
219
|
+
instructions: str = None,
|
|
220
|
+
tools: Optional[str] = [],
|
|
221
|
+
file_ids: Optional[str] = [],
|
|
222
|
+
metadata: Dict = None,
|
|
223
|
+
workspace: str = None,
|
|
224
|
+
api_key: str = None,
|
|
225
|
+
**kwargs) -> Assistant:
|
|
226
|
+
"""Update an exist assistants
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
assistant_id (str): The target assistant id.
|
|
230
|
+
model (str): The model to use.
|
|
231
|
+
name (str, optional): The assistant name. Defaults to None.
|
|
232
|
+
description (str, optional): The assistant description . Defaults to None.
|
|
233
|
+
instructions (str, optional): The system instructions this assistant uses.. Defaults to None.
|
|
234
|
+
tools (Optional[str], optional): List of tools to use.. Defaults to [].
|
|
235
|
+
file_ids (Optional[str], optional): The files to use in assistants.. Defaults to [].
|
|
236
|
+
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
|
237
|
+
workspace (str): The DashScope workspace id.
|
|
238
|
+
api_key (str, optional): The DashScope workspace id. Defaults to None.
|
|
239
|
+
|
|
240
|
+
Returns:
|
|
241
|
+
Assistant: The updated assistant.
|
|
242
|
+
"""
|
|
243
|
+
if not assistant_id:
|
|
244
|
+
raise ModelRequired('assistant_id is required!')
|
|
245
|
+
response = super().update(assistant_id,
|
|
246
|
+
cls._create_assistant_object(
|
|
247
|
+
model, name, description, instructions,
|
|
248
|
+
tools, file_ids, metadata),
|
|
249
|
+
api_key=api_key,
|
|
250
|
+
workspace=workspace,
|
|
251
|
+
flattened_output=True,
|
|
252
|
+
method='post',
|
|
253
|
+
**kwargs)
|
|
254
|
+
return Assistant(**response)
|
|
255
|
+
|
|
256
|
+
@classmethod
|
|
257
|
+
def delete(cls,
|
|
258
|
+
assistant_id: str,
|
|
259
|
+
*,
|
|
260
|
+
workspace: str = None,
|
|
261
|
+
api_key: str = None,
|
|
262
|
+
**kwargs) -> DeleteResponse:
|
|
263
|
+
"""Delete uploaded file.
|
|
264
|
+
|
|
265
|
+
Args:
|
|
266
|
+
assistant_id (str): The assistant id want to delete.
|
|
267
|
+
workspace (str): The DashScope workspace id.
|
|
268
|
+
api_key (str, optional): The api key. Defaults to None.
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
AssistantsDeleteResponse: Delete result.
|
|
272
|
+
"""
|
|
273
|
+
if not assistant_id:
|
|
274
|
+
raise ModelRequired('assistant_id is required!')
|
|
275
|
+
response = super().delete(assistant_id,
|
|
276
|
+
api_key=api_key,
|
|
277
|
+
workspace=workspace,
|
|
278
|
+
flattened_output=True,
|
|
279
|
+
**kwargs)
|
|
280
|
+
return DeleteResponse(**response)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
from dashscope.assistants.assistant_types import (AssistantFile,
|
|
2
|
+
AssistantFileList,
|
|
3
|
+
DeleteResponse)
|
|
4
|
+
from dashscope.client.base_api import (CreateMixin, DeleteMixin,
|
|
5
|
+
GetStatusMixin, ListObjectMixin)
|
|
6
|
+
from dashscope.common.error import InputRequired
|
|
7
|
+
|
|
8
|
+
__all__ = ['Files']
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Files(CreateMixin, DeleteMixin, ListObjectMixin, GetStatusMixin):
|
|
12
|
+
SUB_PATH = 'assistants'
|
|
13
|
+
|
|
14
|
+
@classmethod
|
|
15
|
+
def call(cls,
|
|
16
|
+
assistant_id: str,
|
|
17
|
+
*,
|
|
18
|
+
file_id: str,
|
|
19
|
+
workspace: str = None,
|
|
20
|
+
api_key: str = None,
|
|
21
|
+
**kwargs) -> AssistantFile:
|
|
22
|
+
"""Create assistant file.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
assistant_id (str): The target assistant id.
|
|
26
|
+
file_id (str): The file id.
|
|
27
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
28
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
29
|
+
|
|
30
|
+
Raises:
|
|
31
|
+
InputRequired: The assistant id and file id are required.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
AssistantFile: The assistant file object.
|
|
35
|
+
"""
|
|
36
|
+
return cls.create(assistant_id,
|
|
37
|
+
file_id=file_id,
|
|
38
|
+
workspace=workspace,
|
|
39
|
+
api_key=api_key,
|
|
40
|
+
**kwargs)
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def create(cls,
|
|
44
|
+
assistant_id: str,
|
|
45
|
+
*,
|
|
46
|
+
file_id: str,
|
|
47
|
+
workspace: str = None,
|
|
48
|
+
api_key: str = None,
|
|
49
|
+
**kwargs) -> AssistantFile:
|
|
50
|
+
"""Create assistant file.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
assistant_id (str): The target assistant id.
|
|
54
|
+
file_id (str): The file id.
|
|
55
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
56
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
InputRequired: The assistant id and file id is required.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
AssistantFile: _description_
|
|
63
|
+
"""
|
|
64
|
+
if not file_id or not assistant_id:
|
|
65
|
+
raise InputRequired('input file_id and assistant_id is required!')
|
|
66
|
+
|
|
67
|
+
response = super().call(data={'file_id': file_id},
|
|
68
|
+
path=f'assistants/{assistant_id}/files',
|
|
69
|
+
api_key=api_key,
|
|
70
|
+
flattened_output=True,
|
|
71
|
+
workspace=workspace,
|
|
72
|
+
**kwargs)
|
|
73
|
+
return AssistantFile(**response)
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def list(cls,
|
|
77
|
+
assistant_id: str,
|
|
78
|
+
*,
|
|
79
|
+
limit: int = None,
|
|
80
|
+
order: str = None,
|
|
81
|
+
after: str = None,
|
|
82
|
+
before: str = None,
|
|
83
|
+
workspace: str = None,
|
|
84
|
+
api_key: str = None,
|
|
85
|
+
**kwargs) -> AssistantFileList:
|
|
86
|
+
"""List assistant files.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
assistant_id (str): The assistant id.
|
|
90
|
+
limit (int, optional): How many assistant to retrieve. Defaults to None.
|
|
91
|
+
order (str, optional): Sort order by created_at. Defaults to None.
|
|
92
|
+
after (str, optional): Assistant id after. Defaults to None.
|
|
93
|
+
before (str, optional): Assistant id before. Defaults to None.
|
|
94
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
95
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
ListAssistantFile: The list of file objects.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
response = super().list(limit=limit,
|
|
102
|
+
order=order,
|
|
103
|
+
after=after,
|
|
104
|
+
before=before,
|
|
105
|
+
path=f'assistants/{assistant_id}/files',
|
|
106
|
+
api_key=api_key,
|
|
107
|
+
flattened_output=True,
|
|
108
|
+
workspace=workspace,
|
|
109
|
+
**kwargs)
|
|
110
|
+
return AssistantFileList(**response)
|
|
111
|
+
|
|
112
|
+
@classmethod
|
|
113
|
+
def retrieve(cls,
|
|
114
|
+
file_id: str,
|
|
115
|
+
*,
|
|
116
|
+
assistant_id: str,
|
|
117
|
+
workspace: str = None,
|
|
118
|
+
api_key: str = None,
|
|
119
|
+
**kwargs) -> AssistantFile:
|
|
120
|
+
"""Retrieve file information.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
file_id (str): The file if.
|
|
124
|
+
assistant_id (str): The assistant id of the file.
|
|
125
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
126
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
AssistantFile: The `AssistantFile` object.
|
|
130
|
+
"""
|
|
131
|
+
if not assistant_id or not file_id:
|
|
132
|
+
raise InputRequired('assistant id and file id are required!')
|
|
133
|
+
response = super().get(
|
|
134
|
+
file_id,
|
|
135
|
+
path=f'assistants/{assistant_id}/files/{file_id}',
|
|
136
|
+
api_key=api_key,
|
|
137
|
+
flattened_output=True,
|
|
138
|
+
workspace=workspace,
|
|
139
|
+
**kwargs)
|
|
140
|
+
return AssistantFile(**response)
|
|
141
|
+
|
|
142
|
+
@classmethod
|
|
143
|
+
def get(cls,
|
|
144
|
+
file_id: str,
|
|
145
|
+
*,
|
|
146
|
+
assistant_id: str,
|
|
147
|
+
workspace: str = None,
|
|
148
|
+
api_key: str = None,
|
|
149
|
+
**kwargs) -> AssistantFile:
|
|
150
|
+
"""Retrieve file information.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
file_id (str): The file if.
|
|
154
|
+
assistant_id (str): The assistant id of the file.
|
|
155
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
156
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
AssistantFile: The `AssistantFile` object.
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
@classmethod
|
|
163
|
+
def delete(cls,
|
|
164
|
+
file_id: str,
|
|
165
|
+
*,
|
|
166
|
+
assistant_id: str,
|
|
167
|
+
workspace: str = None,
|
|
168
|
+
api_key: str = None,
|
|
169
|
+
**kwargs) -> DeleteResponse:
|
|
170
|
+
"""Delete the `file_id`.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
file_id (str): The file to be deleted.
|
|
174
|
+
assistant_id (str): The assistant id of the file.
|
|
175
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
176
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
AssistantsDeleteResponse: _description_
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
response = super().delete(
|
|
183
|
+
file_id,
|
|
184
|
+
path=f'assistants/{assistant_id}/files/{file_id}',
|
|
185
|
+
api_key=api_key,
|
|
186
|
+
flattened_output=True,
|
|
187
|
+
workspace=workspace,
|
|
188
|
+
**kwargs)
|
|
189
|
+
return DeleteResponse(**response)
|