dashscope 1.15.0__py3-none-any.whl → 1.18.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 +57 -10
- dashscope/aigc/code_generation.py +12 -9
- dashscope/aigc/conversation.py +3 -0
- dashscope/aigc/generation.py +3 -0
- dashscope/aigc/image_synthesis.py +26 -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/dashscope_response.py +63 -0
- dashscope/api_entities/http_request.py +21 -31
- dashscope/api_entities/websocket_request.py +3 -0
- dashscope/app/application.py +16 -18
- 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 +317 -70
- dashscope/common/base_type.py +130 -0
- dashscope/common/constants.py +1 -0
- dashscope/common/error.py +4 -0
- dashscope/common/utils.py +159 -27
- 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/rerank/__init__.py +0 -0
- dashscope/rerank/text_rerank.py +67 -0
- 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 +483 -0
- dashscope/threads/runs/steps.py +110 -0
- dashscope/threads/thread_types.py +651 -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.15.0.dist-info → dashscope-1.18.0.dist-info}/METADATA +2 -3
- dashscope-1.18.0.dist-info/RECORD +84 -0
- dashscope-1.15.0.dist-info/RECORD +0 -66
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/LICENSE +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/WHEEL +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/entry_points.txt +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/top_level.txt +0 -0
dashscope/app/application.py
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
# -*-coding:utf-8 -*-
|
|
3
|
-
|
|
4
2
|
"""
|
|
5
3
|
@File : application.py
|
|
6
4
|
@Date : 2024-02-24
|
|
@@ -18,12 +16,10 @@ from dashscope.common.error import InputRequired, InvalidInput
|
|
|
18
16
|
|
|
19
17
|
class Application(BaseApi):
|
|
20
18
|
task_group = 'apps'
|
|
21
|
-
function =
|
|
22
|
-
|
|
19
|
+
function = 'completion'
|
|
23
20
|
"""API for app completion calls.
|
|
24
21
|
|
|
25
22
|
"""
|
|
26
|
-
|
|
27
23
|
class DocReferenceType:
|
|
28
24
|
""" doc reference type for rag completion """
|
|
29
25
|
|
|
@@ -41,14 +37,15 @@ class Application(BaseApi):
|
|
|
41
37
|
|
|
42
38
|
@classmethod
|
|
43
39
|
def call(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
) -> Union[ApplicationResponse, Generator[ApplicationResponse, None,
|
|
40
|
+
cls,
|
|
41
|
+
app_id: str,
|
|
42
|
+
prompt: str,
|
|
43
|
+
history: list = None,
|
|
44
|
+
workspace: str = None,
|
|
45
|
+
api_key: str = None,
|
|
46
|
+
**kwargs
|
|
47
|
+
) -> Union[ApplicationResponse, Generator[ApplicationResponse, None,
|
|
48
|
+
None]]:
|
|
52
49
|
"""Call app completion service.
|
|
53
50
|
|
|
54
51
|
Args:
|
|
@@ -120,12 +117,14 @@ class Application(BaseApi):
|
|
|
120
117
|
headers['X-DashScope-WorkSpace'] = workspace
|
|
121
118
|
kwargs['headers'] = headers
|
|
122
119
|
|
|
123
|
-
input, parameters = cls._build_input_parameters(
|
|
120
|
+
input, parameters = cls._build_input_parameters(
|
|
121
|
+
prompt, history, **kwargs)
|
|
124
122
|
request = _build_api_request(model='',
|
|
125
123
|
input=input,
|
|
126
124
|
task_group=Application.task_group,
|
|
127
125
|
task=app_id,
|
|
128
126
|
function=Application.function,
|
|
127
|
+
workspace=workspace,
|
|
129
128
|
api_key=api_key,
|
|
130
129
|
is_service=False,
|
|
131
130
|
**parameters)
|
|
@@ -143,9 +142,7 @@ class Application(BaseApi):
|
|
|
143
142
|
def _build_input_parameters(cls, prompt, history, **kwargs):
|
|
144
143
|
parameters = {}
|
|
145
144
|
|
|
146
|
-
input_param = {HISTORY: history,
|
|
147
|
-
PROMPT: prompt
|
|
148
|
-
}
|
|
145
|
+
input_param = {HISTORY: history, PROMPT: prompt}
|
|
149
146
|
|
|
150
147
|
session_id = kwargs.pop('session_id', None)
|
|
151
148
|
if session_id is not None and session_id:
|
|
@@ -157,7 +154,8 @@ class Application(BaseApi):
|
|
|
157
154
|
|
|
158
155
|
doc_tag_codes = kwargs.pop('doc_tag_codes', None)
|
|
159
156
|
if doc_tag_codes is not None:
|
|
160
|
-
if isinstance(doc_tag_codes, list) and all(
|
|
157
|
+
if isinstance(doc_tag_codes, list) and all(
|
|
158
|
+
isinstance(item, str) for item in doc_tag_codes):
|
|
161
159
|
input_param['doc_tag_codes'] = doc_tag_codes
|
|
162
160
|
else:
|
|
163
161
|
raise InvalidInput('doc_tag_codes is not a List[str]')
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# yapf: disable
|
|
2
|
+
|
|
3
|
+
from dashscope.assistants.assistant_types import (Assistant, AssistantFile,
|
|
4
|
+
AssistantList,
|
|
5
|
+
DeleteResponse)
|
|
6
|
+
from dashscope.assistants.assistants import Assistants
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
Assistant,
|
|
10
|
+
Assistants,
|
|
11
|
+
AssistantList,
|
|
12
|
+
AssistantFile,
|
|
13
|
+
DeleteResponse,
|
|
14
|
+
]
|
|
@@ -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)
|