dashscope 1.16.0__py3-none-any.whl → 1.17.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.

Files changed (53) hide show
  1. dashscope/__init__.py +25 -3
  2. dashscope/aigc/code_generation.py +12 -9
  3. dashscope/aigc/conversation.py +3 -0
  4. dashscope/aigc/generation.py +3 -0
  5. dashscope/aigc/image_synthesis.py +21 -6
  6. dashscope/aigc/multimodal_conversation.py +3 -0
  7. dashscope/api_entities/aiohttp_request.py +1 -0
  8. dashscope/api_entities/api_request_factory.py +28 -12
  9. dashscope/api_entities/http_request.py +18 -9
  10. dashscope/api_entities/websocket_request.py +3 -0
  11. dashscope/app/application.py +16 -18
  12. dashscope/assistants/__init__.py +14 -0
  13. dashscope/assistants/assistant_types.py +164 -0
  14. dashscope/assistants/assistants.py +280 -0
  15. dashscope/assistants/files.py +189 -0
  16. dashscope/audio/asr/asr_phrase_manager.py +27 -5
  17. dashscope/audio/asr/recognition.py +10 -2
  18. dashscope/audio/asr/transcription.py +21 -3
  19. dashscope/audio/tts/speech_synthesizer.py +3 -0
  20. dashscope/cli.py +7 -7
  21. dashscope/client/base_api.py +303 -68
  22. dashscope/common/base_type.py +130 -0
  23. dashscope/common/constants.py +1 -0
  24. dashscope/common/error.py +4 -0
  25. dashscope/common/utils.py +22 -6
  26. dashscope/deployment.py +40 -6
  27. dashscope/embeddings/batch_text_embedding.py +24 -7
  28. dashscope/embeddings/multimodal_embedding.py +3 -0
  29. dashscope/embeddings/text_embedding.py +8 -1
  30. dashscope/files.py +107 -0
  31. dashscope/finetune.py +31 -7
  32. dashscope/model.py +9 -2
  33. dashscope/models.py +47 -0
  34. dashscope/nlp/understanding.py +2 -2
  35. dashscope/threads/__init__.py +24 -0
  36. dashscope/threads/messages/__init__.py +0 -0
  37. dashscope/threads/messages/files.py +111 -0
  38. dashscope/threads/messages/messages.py +218 -0
  39. dashscope/threads/runs/__init__.py +0 -0
  40. dashscope/threads/runs/runs.py +408 -0
  41. dashscope/threads/runs/steps.py +110 -0
  42. dashscope/threads/thread_types.py +571 -0
  43. dashscope/threads/threads.py +210 -0
  44. dashscope/tokenizers/tokenization.py +3 -0
  45. dashscope/utils/oss_utils.py +11 -0
  46. dashscope/version.py +1 -1
  47. {dashscope-1.16.0.dist-info → dashscope-1.17.1.dist-info}/METADATA +2 -3
  48. dashscope-1.17.1.dist-info/RECORD +84 -0
  49. dashscope-1.16.0.dist-info/RECORD +0 -68
  50. {dashscope-1.16.0.dist-info → dashscope-1.17.1.dist-info}/LICENSE +0 -0
  51. {dashscope-1.16.0.dist-info → dashscope-1.17.1.dist-info}/WHEEL +0 -0
  52. {dashscope-1.16.0.dist-info → dashscope-1.17.1.dist-info}/entry_points.txt +0 -0
  53. {dashscope-1.16.0.dist-info → dashscope-1.17.1.dist-info}/top_level.txt +0 -0
dashscope/finetune.py CHANGED
@@ -18,6 +18,7 @@ class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
18
18
  mode: str = None,
19
19
  hyper_parameters: dict = {},
20
20
  api_key: str = None,
21
+ workspace: str = None,
21
22
  **kwargs) -> DashScopeAPIResponse:
22
23
  """Create fine-tune job
23
24
 
@@ -31,6 +32,7 @@ class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
31
32
  hyper_parameters (dict, optional): The fine-tune hyper parameters.
32
33
  Defaults to empty.
33
34
  api_key (str, optional): The api key. Defaults to None.
35
+ workspace (str): The dashscope workspace id.
34
36
 
35
37
  Returns:
36
38
  DashScopeAPIResponse: The request result.
@@ -45,12 +47,16 @@ class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
45
47
  request['training_type'] = mode
46
48
  if 'finetuned_output' in kwargs:
47
49
  request['finetuned_output'] = kwargs['finetuned_output']
48
- return super().call(request, api_key, **kwargs)
50
+ return super().call(request,
51
+ api_key=api_key,
52
+ workspace=workspace,
53
+ **kwargs)
49
54
 
50
55
  @classmethod
51
56
  def cancel(cls,
52
57
  job_id: str,
53
58
  api_key: str = None,
59
+ workspace: str = None,
54
60
  **kwargs) -> DashScopeAPIResponse:
55
61
  """Cancel a running fine-tune job.
56
62
 
@@ -58,17 +64,19 @@ class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
58
64
  job_id (str): The fine-tune job id.
59
65
  api_key (str, optional): The api api_key, can be None,
60
66
  if None, will get by default rule(TODO: api key doc).
67
+ workspace (str): The dashscope workspace id.
61
68
 
62
69
  Returns:
63
70
  DashScopeAPIResponse: The request result.
64
71
  """
65
- return super().cancel(job_id, api_key, **kwargs)
72
+ return super().cancel(job_id, api_key, workspace=workspace, **kwargs)
66
73
 
67
74
  @classmethod
68
75
  def list(cls,
69
76
  page=1,
70
77
  page_size=10,
71
78
  api_key: str = None,
79
+ workspace: str = None,
72
80
  **kwargs) -> DashScopeAPIResponse:
73
81
  """List fine-tune job.
74
82
 
@@ -76,59 +84,73 @@ class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
76
84
  api_key (str, optional): The api key
77
85
  page (int, optional): Page number. Defaults to 1.
78
86
  page_size (int, optional): Items per page. Defaults to 10.
87
+ workspace (str): The dashscope workspace id.
79
88
 
80
89
  Returns:
81
90
  DashScopeAPIResponse: The fine-tune jobs in the result.
82
91
  """
83
- return super().list(page, page_size, api_key, **kwargs)
92
+ return super().list(page,
93
+ page_size,
94
+ api_key,
95
+ workspace=workspace,
96
+ **kwargs)
84
97
 
85
98
  @classmethod
86
99
  def get(cls,
87
100
  job_id: str,
88
101
  api_key: str = None,
102
+ workspace: str = None,
89
103
  **kwargs) -> DashScopeAPIResponse:
90
104
  """Get fine-tune job information.
91
105
 
92
106
  Args:
93
107
  job_id (str): The fine-tune job id
94
108
  api_key (str, optional): The api key. Defaults to None.
109
+ workspace (str): The dashscope workspace id.
95
110
 
96
111
  Returns:
97
112
  DashScopeAPIResponse: The job info
98
113
  """
99
- return super().get(job_id, api_key, **kwargs)
114
+ return super().get(job_id, api_key, workspace=workspace, **kwargs)
100
115
 
101
116
  @classmethod
102
117
  def delete(cls,
103
118
  job_id: str,
104
119
  api_key: str = None,
120
+ workspace: str = None,
105
121
  **kwargs) -> DashScopeAPIResponse:
106
122
  """Delete a fine-tune job.
107
123
 
108
124
  Args:
109
125
  job_id (str): The fine-tune job id.
110
126
  api_key (str, optional): The api key. Defaults to None.
127
+ workspace (str): The dashscope workspace id.
111
128
 
112
129
  Returns:
113
130
  DashScopeAPIResponse: The delete result.
114
131
  """
115
- return super().delete(job_id, api_key, **kwargs)
132
+ return super().delete(job_id, api_key, workspace=workspace, **kwargs)
116
133
 
117
134
  @classmethod
118
135
  def stream_events(cls,
119
136
  job_id: str,
120
137
  api_key: str = None,
138
+ workspace: str = None,
121
139
  **kwargs) -> DashScopeAPIResponse:
122
140
  """Get fine-tune job events.
123
141
 
124
142
  Args:
125
143
  job_id (str): The fine-tune job id
126
144
  api_key (str, optional): the api key. Defaults to None.
145
+ workspace (str): The dashscope workspace id.
127
146
 
128
147
  Returns:
129
148
  DashScopeAPIResponse: The job log events.
130
149
  """
131
- return super().stream_events(job_id, api_key, **kwargs)
150
+ return super().stream_events(job_id,
151
+ api_key,
152
+ workspace=workspace,
153
+ **kwargs)
132
154
 
133
155
  @classmethod
134
156
  def logs(cls,
@@ -136,6 +158,7 @@ class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
136
158
  offset=1,
137
159
  line=1000,
138
160
  api_key: str = None,
161
+ workspace: str = None,
139
162
  **kwargs) -> DashScopeAPIResponse:
140
163
  """Get log of the job.
141
164
 
@@ -144,8 +167,9 @@ class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
144
167
  offset (int, optional): start log line. Defaults to 1.
145
168
  line (int, optional): total line return. Defaults to 1000.
146
169
  api_key (str, optional): The api key. Defaults to None.
170
+ workspace (str): The dashscope workspace id.
147
171
 
148
172
  Returns:
149
173
  DashScopeAPIResponse: The response
150
174
  """
151
- return super().logs(job_id, offset, line)
175
+ return super().logs(job_id, offset, line, workspace=workspace)
dashscope/model.py CHANGED
@@ -9,23 +9,26 @@ class Model(ListMixin, GetMixin):
9
9
  def get(cls,
10
10
  name: str,
11
11
  api_key: str = None,
12
+ workspace: str = None,
12
13
  **kwargs) -> DashScopeAPIResponse:
13
14
  """Get the model information.
14
15
 
15
16
  Args:
16
17
  name (str): The model name.
17
18
  api_key (str, optional): The api key. Defaults to None.
19
+ workspace (str): The dashscope workspace id.
18
20
 
19
21
  Returns:
20
22
  DashScopeAPIResponse: The model information.
21
23
  """
22
- return super().get(name, api_key, **kwargs)
24
+ return super().get(name, api_key, workspace=workspace, **kwargs)
23
25
 
24
26
  @classmethod
25
27
  def list(cls,
26
28
  page=1,
27
29
  page_size=10,
28
30
  api_key: str = None,
31
+ workspace: str = None,
29
32
  **kwargs) -> DashScopeAPIResponse:
30
33
  """List models.
31
34
 
@@ -37,4 +40,8 @@ class Model(ListMixin, GetMixin):
37
40
  Returns:
38
41
  DashScopeAPIResponse: The models.
39
42
  """
40
- return super().list(api_key, page, page_size, **kwargs)
43
+ return super().list(api_key,
44
+ page,
45
+ page_size,
46
+ workspace=workspace,
47
+ **kwargs)
dashscope/models.py ADDED
@@ -0,0 +1,47 @@
1
+ from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
2
+ from dashscope.client.base_api import GetMixin, ListMixin
3
+
4
+
5
+ class Model(ListMixin, GetMixin):
6
+ SUB_PATH = 'models'
7
+
8
+ @classmethod
9
+ def get(cls,
10
+ name: str,
11
+ api_key: str = None,
12
+ workspace: str = None,
13
+ **kwargs) -> DashScopeAPIResponse:
14
+ """Get the model information.
15
+
16
+ Args:
17
+ name (str): The model name.
18
+ api_key (str, optional): The api key. Defaults to None.
19
+ workspace (str): The dashscope workspace id.
20
+
21
+ Returns:
22
+ DashScopeAPIResponse: The model information.
23
+ """
24
+ return super().get(name, api_key, workspace=workspace, **kwargs)
25
+
26
+ @classmethod
27
+ def list(cls,
28
+ page=1,
29
+ page_size=10,
30
+ api_key: str = None,
31
+ workspace: str = None,
32
+ **kwargs) -> DashScopeAPIResponse:
33
+ """List models.
34
+
35
+ Args:
36
+ api_key (str, optional): The api key
37
+ page (int, optional): Page number. Defaults to 1.
38
+ page_size (int, optional): Items per page. Defaults to 10.
39
+
40
+ Returns:
41
+ DashScopeAPIResponse: The models.
42
+ """
43
+ return super().list(api_key,
44
+ page,
45
+ page_size,
46
+ workspace=workspace,
47
+ **kwargs)
@@ -25,8 +25,8 @@ class Understanding(BaseApi):
25
25
 
26
26
  Args:
27
27
  model (str): The requested model, such as opennlu-v1
28
- sentence (str): The text content entered by the user that needs to be processed supports both Chinese and English. (The maximum limit for input is 1024 tokens, which is the sum of all input fields).
29
- labels (list): For the extraction task, label is the name of the type that needs to be extracted. For classification tasks, label is the classification system. Separate different labels with Chinese commas..
28
+ sentence (str): The text content entered by the user that needs to be processed supports both Chinese and English. (The maximum limit for input is 1024 tokens, which is the sum of all input fields). # noqa E501
29
+ labels (list): For the extraction task, label is the name of the type that needs to be extracted. For classification tasks, label is the classification system. Separate different labels with Chinese commas.. # noqa E501
30
30
  task (str): Task type, optional as extraction or classification, default as extraction.
31
31
  api_key (str, optional): The api api_key, can be None,
32
32
  if None, will get by default rule(TODO: api key doc).
@@ -0,0 +1,24 @@
1
+ # yapf: disable
2
+
3
+ from dashscope.threads.messages.messages import Messages
4
+ from dashscope.threads.runs.runs import Runs
5
+ from dashscope.threads.runs.steps import Steps
6
+ from dashscope.threads.thread_types import (MessageFile, Run, RunList, RunStep,
7
+ RunStepList, Thread, ThreadMessage,
8
+ ThreadMessageList)
9
+ from dashscope.threads.threads import Threads
10
+
11
+ __all__ = [
12
+ MessageFile,
13
+ Messages,
14
+ Run,
15
+ Runs,
16
+ RunList,
17
+ Steps,
18
+ RunStep,
19
+ RunStepList,
20
+ Threads,
21
+ Thread,
22
+ ThreadMessage,
23
+ ThreadMessageList,
24
+ ]
File without changes
@@ -0,0 +1,111 @@
1
+ from dashscope.client.base_api import GetStatusMixin, ListObjectMixin
2
+ from dashscope.common.error import InputRequired
3
+ from dashscope.threads.thread_types import MessageFile, MessageFileList
4
+
5
+ __all__ = ['Files']
6
+
7
+
8
+ class Files(ListObjectMixin, GetStatusMixin):
9
+ SUB_PATH = 'messages' # useless
10
+
11
+ @classmethod
12
+ def retrieve(cls,
13
+ file_id: str,
14
+ *,
15
+ thread_id: str,
16
+ message_id: str,
17
+ workspace: str = None,
18
+ api_key: str = None,
19
+ **kwargs) -> MessageFile:
20
+ """Retrieve the `MessageFile`.
21
+
22
+ Args:
23
+ thread_id (str): The thread id.
24
+ message_id (str): The message id.
25
+ file_id (str): The file id.
26
+ workspace (str): The dashscope workspace id.
27
+ api_key (str, optional): The api key. Defaults to None.
28
+
29
+ Returns:
30
+ MessageFile: The `MessageFile` object.
31
+ """
32
+ return cls.get(file_id,
33
+ thread_id=thread_id,
34
+ message_id=message_id,
35
+ workspace=workspace,
36
+ api_key=api_key,
37
+ **kwargs)
38
+
39
+ @classmethod
40
+ def get(cls,
41
+ file_id: str,
42
+ *,
43
+ message_id: str,
44
+ thread_id: str,
45
+ workspace: str = None,
46
+ api_key: str = None,
47
+ **kwargs) -> MessageFile:
48
+ """Retrieve the `MessageFile`.
49
+
50
+ Args:
51
+ assistant_id (str): The assistant id.
52
+ message_id (str): The message id.
53
+ file_id (str): The file id.
54
+ workspace (str): The dashscope workspace id.
55
+ api_key (str, optional): The api key. Defaults to None.
56
+
57
+ Returns:
58
+ MessageFile: The `MessageFile` object.
59
+ """
60
+ if not thread_id or not message_id or not file_id:
61
+ raise InputRequired(
62
+ 'thread id, message id and file id are required!')
63
+ response = super().get(
64
+ message_id,
65
+ path=f'threads/{thread_id}/messages/{message_id}/files/{file_id}',
66
+ workspace=workspace,
67
+ api_key=api_key,
68
+ flattened_output=True,
69
+ **kwargs)
70
+ return MessageFile(**response)
71
+
72
+ @classmethod
73
+ def list(cls,
74
+ message_id: str,
75
+ *,
76
+ thread_id: str,
77
+ limit: int = None,
78
+ order: str = None,
79
+ after: str = None,
80
+ before: str = None,
81
+ workspace: str = None,
82
+ api_key: str = None,
83
+ **kwargs) -> MessageFileList:
84
+ """List message files.
85
+
86
+ Args:
87
+ thread_id (str): The thread id.
88
+ message_id (str): The message_id.
89
+ limit (int, optional): How many assistant to retrieve. Defaults to None.
90
+ order (str, optional): Sort order by created_at. Defaults to None.
91
+ after (str, optional): Assistant id after. Defaults to None.
92
+ before (str, optional): Assistant id before. Defaults to None.
93
+ workspace (str, optional): The DashScope workspace id. Defaults to None.
94
+ api_key (str, optional): Your DashScope api key. Defaults to None.
95
+
96
+ Returns:
97
+ MessageFileList: The `MessageFileList`.
98
+ """
99
+ if not thread_id or not message_id:
100
+ raise InputRequired('thread id, message id are required!')
101
+ response = super().list(
102
+ limit=limit,
103
+ order=order,
104
+ after=after,
105
+ before=before,
106
+ path=f'threads/{thread_id}/messages/{message_id}/files',
107
+ workspace=workspace,
108
+ api_key=api_key,
109
+ flattened_output=True,
110
+ **kwargs)
111
+ return MessageFileList(**response)
@@ -0,0 +1,218 @@
1
+ from typing import Dict, List, Optional
2
+
3
+ from dashscope.client.base_api import (CreateMixin, GetStatusMixin,
4
+ ListObjectMixin, UpdateMixin)
5
+ from dashscope.common.error import InputRequired
6
+ from dashscope.threads.thread_types import ThreadMessage, ThreadMessageList
7
+
8
+ __all__ = ['Messages']
9
+
10
+
11
+ class Messages(CreateMixin, ListObjectMixin, GetStatusMixin, UpdateMixin):
12
+ SUB_PATH = 'messages' # useless
13
+
14
+ @classmethod
15
+ def call(cls,
16
+ thread_id: str,
17
+ *,
18
+ content: str,
19
+ role: str = 'user',
20
+ file_ids: List[str] = [],
21
+ metadata: Optional[object] = None,
22
+ workspace: str = None,
23
+ api_key: str = None,
24
+ **kwargs) -> ThreadMessage:
25
+ """Create message of thread.
26
+
27
+ Args:
28
+ thread_id (str): The thread id.
29
+ content (str): The message content.
30
+ role (str, optional): The message role. Defaults to 'user'.
31
+ file_ids (List[str], optional): The file_ids include in message. Defaults to [].
32
+ metadata (Optional[object], optional): The custom key/value pairs. Defaults to None.
33
+ workspace (str, optional): The DashScope workspace id. Defaults to None.
34
+ api_key (str, optional): The DashScope api key. Defaults to None.
35
+
36
+ Returns:
37
+ ThreadMessage: The `ThreadMessage` object.
38
+ """
39
+ return cls.create(thread_id,
40
+ content=content,
41
+ role=role,
42
+ file_ids=file_ids,
43
+ metadata=metadata,
44
+ workspace=workspace,
45
+ **kwargs)
46
+
47
+ @classmethod
48
+ def create(cls,
49
+ thread_id: str,
50
+ *,
51
+ content: str,
52
+ role: str = 'user',
53
+ file_ids: List[str] = [],
54
+ metadata: Optional[object] = None,
55
+ workspace: str = None,
56
+ api_key: str = None,
57
+ **kwargs) -> ThreadMessage:
58
+ """Create message of thread.
59
+
60
+ Args:
61
+ thread_id (str): The thread id.
62
+ content (str): The message content.
63
+ role (str, optional): The message role. Defaults to 'user'.
64
+ file_ids (List[str], optional): The file_ids include in message. Defaults to [].
65
+ metadata (Optional[object], optional): The custom key/value pairs. Defaults to None.
66
+ workspace (str, optional): The DashScope workspace id. Defaults to None.
67
+ api_key (str, optional): The DashScope api key. Defaults to None.
68
+
69
+ Returns:
70
+ ThreadMessage: The `ThreadMessage` object.
71
+ """
72
+ cls.SUB_PATH = '%s/messages' % thread_id
73
+ data = {}
74
+ if not thread_id or not content:
75
+ raise InputRequired('thread_id and content are required!')
76
+ data['content'] = content
77
+ data['role'] = role
78
+ if metadata:
79
+ data['metadata'] = metadata
80
+ if file_ids:
81
+ data['file_ids'] = file_ids
82
+ response = super().call(data=data,
83
+ path=f'threads/{thread_id}/messages',
84
+ api_key=api_key,
85
+ flattened_output=True,
86
+ workspace=workspace,
87
+ **kwargs)
88
+ return ThreadMessage(**response)
89
+
90
+ @classmethod
91
+ def retrieve(cls,
92
+ message_id: str,
93
+ *,
94
+ thread_id: str,
95
+ workspace: str = None,
96
+ api_key: str = None,
97
+ **kwargs) -> ThreadMessage:
98
+ """Get the `ThreadMessage`.
99
+
100
+ Args:
101
+ thread_id (str): The thread id.
102
+ message_id (str): The message id.
103
+ workspace (str): The dashscope workspace id.
104
+ api_key (str, optional): The api key. Defaults to None.
105
+
106
+ Returns:
107
+ ThreadMessage: The `ThreadMessage` object.
108
+ """
109
+ return cls.get(message_id,
110
+ thread_id=thread_id,
111
+ workspace=workspace,
112
+ api_key=api_key,
113
+ **kwargs)
114
+
115
+ @classmethod
116
+ def get(cls,
117
+ message_id: str,
118
+ *,
119
+ thread_id: str,
120
+ workspace: str = None,
121
+ api_key: str = None,
122
+ **kwargs) -> ThreadMessage:
123
+ """Get the `ThreadMessage`.
124
+
125
+ Args:
126
+ thread_id (str): The thread id.
127
+ message_id (str): The message id.
128
+ workspace (str): The dashscope workspace id.
129
+ api_key (str, optional): The api key. Defaults to None.
130
+
131
+ Returns:
132
+ ThreadMessage: The `ThreadMessage` object.
133
+ """
134
+ if not message_id or not thread_id:
135
+ raise InputRequired('thread id, message id are required!')
136
+ response = super().get(
137
+ message_id,
138
+ path=f'threads/{thread_id}/messages/{message_id}',
139
+ workspace=workspace,
140
+ api_key=api_key,
141
+ flattened_output=True,
142
+ **kwargs)
143
+ return ThreadMessage(**response)
144
+
145
+ @classmethod
146
+ def list(cls,
147
+ thread_id: str,
148
+ *,
149
+ limit: int = None,
150
+ order: str = None,
151
+ after: str = None,
152
+ before: str = None,
153
+ workspace: str = None,
154
+ api_key: str = None,
155
+ **kwargs) -> ThreadMessageList:
156
+ """List message of the thread.
157
+
158
+ Args:
159
+ thread_id (str): The thread id.
160
+ limit (int, optional): How many assistant to retrieve. Defaults to None.
161
+ order (str, optional): Sort order by created_at. Defaults to None.
162
+ after (str, optional): Assistant id after. Defaults to None.
163
+ before (str, optional): Assistant id before. Defaults to None.
164
+ workspace (str, optional): The DashScope workspace id. Defaults to None.
165
+ api_key (str, optional): Your DashScope api key. Defaults to None.
166
+
167
+ Returns:
168
+ ThreadMessageList: The `ThreadMessageList` object.
169
+ """
170
+ if not thread_id:
171
+ raise InputRequired('thread id is required!')
172
+ response = super().list(limit=limit,
173
+ order=order,
174
+ after=after,
175
+ before=before,
176
+ path=f'threads/{thread_id}/messages',
177
+ workspace=workspace,
178
+ api_key=api_key,
179
+ flattened_output=True,
180
+ **kwargs)
181
+ return ThreadMessageList(**response)
182
+
183
+ @classmethod
184
+ def update(cls,
185
+ message_id: str,
186
+ *,
187
+ thread_id: str,
188
+ metadata: Dict = None,
189
+ workspace: str = None,
190
+ api_key: str = None,
191
+ **kwargs) -> ThreadMessage:
192
+ """Update an message of the thread.
193
+
194
+ Args:
195
+ thread_id (str): The thread id.
196
+ message_id (str): The message id.
197
+ content (str): The message content.
198
+ role (str, optional): The message role. Defaults to 'user'.
199
+ file_ids (List[str], optional): The file_ids include in message. Defaults to [].
200
+ metadata (Optional[object], optional): The custom key/value pairs. Defaults to None.
201
+ workspace (str, optional): The DashScope workspace id. Defaults to None.
202
+ api_key (str, optional): The DashScope api key. Defaults to None.
203
+
204
+ Returns:
205
+ ThreadMessage: The `ThreadMessage` object.
206
+ """
207
+ if not thread_id or not message_id:
208
+ raise InputRequired('thread id and message id are required!')
209
+ response = super().update(target=message_id,
210
+ json={'metadata': metadata},
211
+ path='threads/%s/messages/%s' %
212
+ (thread_id, message_id),
213
+ api_key=api_key,
214
+ workspace=workspace,
215
+ flattened_output=True,
216
+ method='post',
217
+ **kwargs)
218
+ return ThreadMessage(**response)
File without changes