1717from yandex_cloud_ml_sdk ._types .message import MessageType
1818from yandex_cloud_ml_sdk ._types .misc import UNDEFINED , UndefinedOr , get_defined_value
1919from yandex_cloud_ml_sdk ._types .resource import ExpirableResource , safe_on_delete
20+ from yandex_cloud_ml_sdk ._utils .doc import doc_from
2021from yandex_cloud_ml_sdk ._utils .sync import run_sync , run_sync_generator
2122
2223
2324@dataclasses .dataclass (frozen = True )
2425class BaseThread (ExpirableResource [ProtoThread ]):
26+ """A class for a thread resource.
27+
28+ It provides methods for working with messages that the thread contains (e.g. updating, deleting, writing to, and reading from).
29+ """
30+
2531 @safe_on_delete
2632 async def _update (
2733 self ,
@@ -33,6 +39,17 @@ async def _update(
3339 expiration_policy : UndefinedOr [ExpirationPolicyAlias ] = UNDEFINED ,
3440 timeout : float = 60 ,
3541 ) -> Self :
42+ """Update the thread's properties, including the name, the description, labels,
43+ ttl days, and the expiration policy of the thread.
44+
45+ :param name: the new name of the thread.
46+ :param description: the new description for the thread.
47+ :param labels: a set of new labels for the thread.
48+ :param ttl_days: the updated time-to-live in days for the thread.
49+ :param expiration_policy: an updated expiration policy for the file.
50+ :param timeout: timeout for the operation in seconds.
51+ Defaults to 60 seconds.
52+ """
3653 # pylint: disable=too-many-locals
3754 name_ = get_defined_value (name , '' )
3855 description_ = get_defined_value (description , '' )
@@ -78,6 +95,14 @@ async def _delete(
7895 * ,
7996 timeout : float = 60 ,
8097 ) -> None :
98+ """Delete the thread.
99+
100+ This method deletes the thread and marks it as deleted.
101+ Raises an exception if the deletion fails.
102+
103+ :param timeout: timeout for the operation.
104+ Defaults to 60 seconds.
105+ """
81106 request = DeleteThreadRequest (thread_id = self .id )
82107
83108 async with self ._client .get_service_stub (ThreadServiceStub , timeout = timeout ) as stub :
@@ -97,6 +122,16 @@ async def _write(
97122 labels : UndefinedOr [dict [str , str ]] = UNDEFINED ,
98123 timeout : float = 60 ,
99124 ) -> Message :
125+ """Write a message to the thread.
126+
127+ This method allows sending a message to the thread with optional labels.
128+
129+ :param message: the message to be sent to the thread. Could be a string, a dictionary, or a result object.
130+ Read more about other possible message types in the `documentation <https://yandex.cloud/docs/foundation-models/sdk/#usage>`_.
131+ :param labels: optional labels for the message.
132+ :param timeout: timeout for the operation.
133+ Defaults to 60 seconds.
134+ """
100135 # pylint: disable-next=protected-access
101136 return await self ._sdk ._messages ._create (
102137 thread_id = self .id ,
@@ -110,6 +145,13 @@ async def _read(
110145 * ,
111146 timeout : float = 60 ,
112147 ) -> AsyncIterator [Message ]:
148+ """Read messages from the thread.
149+
150+ This method allows iterating over messages in the thread.
151+
152+ :param timeout: timeout for the operation.
153+ Defaults to 60 seconds.
154+ """
113155 # NB: in other methods it is solved via @safe decorator, but it is doesn't work
114156 # with iterators, so, temporary here will be small copypaste
115157 # Also I'm not sure enough if we need to put whole thread reading under a lock
@@ -125,17 +167,26 @@ async def _read(
125167
126168@dataclasses .dataclass (frozen = True )
127169class RichThread (BaseThread ):
170+ #: the name of the thread
128171 name : str | None
172+ #: the description of the thread
129173 description : str | None
174+ #: the identifier of the user who created the thread
130175 created_by : str
176+ #: the timestamp when the thread was created
131177 created_at : datetime
178+ #: the identifier of the user who last updated the thread
132179 updated_by : str
180+ #: the timestamp when the thread was last updated
133181 updated_at : datetime
182+ #: the timestamp when the thread will expire
134183 expires_at : datetime
184+ #: additional labels associated with the thread
135185 labels : dict [str , str ] | None
136186
137-
138187class AsyncThread (RichThread ):
188+
189+ @doc_from (BaseThread ._update )
139190 async def update (
140191 self ,
141192 * ,
@@ -155,13 +206,15 @@ async def update(
155206 timeout = timeout ,
156207 )
157208
209+ @doc_from (BaseThread ._delete )
158210 async def delete (
159211 self ,
160212 * ,
161213 timeout : float = 60 ,
162214 ) -> None :
163215 await self ._delete (timeout = timeout )
164216
217+ @doc_from (BaseThread ._write )
165218 async def write (
166219 self ,
167220 message : MessageType ,
@@ -175,6 +228,7 @@ async def write(
175228 timeout = timeout
176229 )
177230
231+ @doc_from (BaseThread ._read )
178232 async def read (
179233 self ,
180234 * ,
@@ -183,15 +237,16 @@ async def read(
183237 async for message in self ._read (timeout = timeout ):
184238 yield message
185239
240+ #: alias for the read method
186241 __aiter__ = read
187242
188-
189243class Thread (RichThread ):
190244 __update = run_sync (RichThread ._update )
191245 __delete = run_sync (RichThread ._delete )
192246 __write = run_sync (RichThread ._write )
193247 __read = run_sync_generator (RichThread ._read )
194248
249+ @doc_from (BaseThread ._update )
195250 def update (
196251 self ,
197252 * ,
@@ -211,13 +266,15 @@ def update(
211266 timeout = timeout ,
212267 )
213268
269+ @doc_from (BaseThread ._delete )
214270 def delete (
215271 self ,
216272 * ,
217273 timeout : float = 60 ,
218274 ) -> None :
219275 self .__delete (timeout = timeout )
220276
277+ @doc_from (BaseThread ._write )
221278 def write (
222279 self ,
223280 message : MessageType ,
@@ -231,6 +288,7 @@ def write(
231288 timeout = timeout
232289 )
233290
291+ @doc_from (BaseThread ._read )
234292 def read (
235293 self ,
236294 * ,
0 commit comments