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 ):
26+ """A class for a thread resource.
27+
28+ It provides methods for updating, deleting, writing to, and reading from a thread.
29+ """
2530 @safe_on_delete
2631 async def _update (
2732 self ,
@@ -33,6 +38,17 @@ async def _update(
3338 expiration_policy : UndefinedOr [ExpirationPolicyAlias ] = UNDEFINED ,
3439 timeout : float = 60 ,
3540 ) -> Self :
41+ """Update the thread's properties, including the name, the description, labels,
42+ ttl days, and the expiration policy of the thread.
43+
44+ :param name: the new name of the thread.
45+ :param description: the new description for the thread.
46+ :param labels: a set of new labels for the thread.
47+ :param ttl_days: the updated time-to-live in days for the thread.
48+ :param expiration_policy: an updated expiration policy for the file.
49+ :param timeout: timeout for the operation in seconds.
50+ Defaults to 60 seconds.
51+ """
3652 # pylint: disable=too-many-locals
3753 name_ = get_defined_value (name , '' )
3854 description_ = get_defined_value (description , '' )
@@ -78,6 +94,14 @@ async def _delete(
7894 * ,
7995 timeout : float = 60 ,
8096 ) -> None :
97+ """Delete the thread.
98+
99+ This method deletes the thread and marks it as deleted.
100+ Raises an exception if the deletion fails.
101+
102+ :param timeout: timeout for the operation.
103+ Defaults to 60 seconds.
104+ """
81105 request = DeleteThreadRequest (thread_id = self .id )
82106
83107 async with self ._client .get_service_stub (ThreadServiceStub , timeout = timeout ) as stub :
@@ -97,6 +121,15 @@ async def _write(
97121 labels : UndefinedOr [dict [str , str ]] = UNDEFINED ,
98122 timeout : float = 60 ,
99123 ) -> Message :
124+ """Write a message to the thread.
125+
126+ This method allows sending a message to the thread with optional labels.
127+
128+ :param message: the message to be sent to the thread.
129+ :param labels: optional labels for the message.
130+ :param timeout: timeout for the operation.
131+ Defaults to 60 seconds.
132+ """
100133 # pylint: disable-next=protected-access
101134 return await self ._sdk ._messages ._create (
102135 thread_id = self .id ,
@@ -110,6 +143,13 @@ async def _read(
110143 * ,
111144 timeout : float = 60 ,
112145 ) -> AsyncIterator [Message ]:
146+ """Read messages from the thread.
147+
148+ This method allows iterating over messages in the thread.
149+
150+ :param timeout: timeout for the operation.
151+ Defaults to 60 seconds.
152+ """
113153 # NB: in other methods it is solved via @safe decorator, but it is doesn't work
114154 # with iterators, so, temporary here will be small copypaste
115155 # Also I'm not sure enough if we need to put whole thread reading under a lock
@@ -125,17 +165,32 @@ async def _read(
125165
126166@dataclasses .dataclass (frozen = True )
127167class RichThread (BaseThread ):
168+ """Rich representation of a thread with additional metadata.
169+
170+ This class extends :class:`.BaseThread` by adding attributes that provide
171+ more information about the thread's creator and timestamps.
172+ """
173+ #: the name of the thread
128174 name : str | None
175+ #: the description of the thread
129176 description : str | None
177+ #: the identifier of the user who created the thread
130178 created_by : str
179+ #: the timestamp when the thread was created
131180 created_at : datetime
181+ #: the identifier of the user who last updated the thread
132182 updated_by : str
183+ #: the timestamp when the thread was last updated
133184 updated_at : datetime
185+ #: the timestamp when the thread will expire
134186 expires_at : datetime
187+ #: additional labels associated with the thread
135188 labels : dict [str , str ] | None
136189
137-
190+ @ doc_from ( BaseThread )
138191class AsyncThread (RichThread ):
192+
193+ @doc_from (BaseThread ._update )
139194 async def update (
140195 self ,
141196 * ,
@@ -155,13 +210,15 @@ async def update(
155210 timeout = timeout ,
156211 )
157212
213+ @doc_from (BaseThread ._delete )
158214 async def delete (
159215 self ,
160216 * ,
161217 timeout : float = 60 ,
162218 ) -> None :
163219 await self ._delete (timeout = timeout )
164220
221+ @doc_from (BaseThread ._write )
165222 async def write (
166223 self ,
167224 message : MessageType ,
@@ -175,6 +232,7 @@ async def write(
175232 timeout = timeout
176233 )
177234
235+ @doc_from (BaseThread ._read )
178236 async def read (
179237 self ,
180238 * ,
@@ -185,13 +243,14 @@ async def read(
185243
186244 __aiter__ = read
187245
188-
246+ @ doc_from ( BaseThread )
189247class Thread (RichThread ):
190248 __update = run_sync (RichThread ._update )
191249 __delete = run_sync (RichThread ._delete )
192250 __write = run_sync (RichThread ._write )
193251 __read = run_sync_generator (RichThread ._read )
194252
253+ @doc_from (BaseThread ._update )
195254 def update (
196255 self ,
197256 * ,
@@ -211,13 +270,15 @@ def update(
211270 timeout = timeout ,
212271 )
213272
273+ @doc_from (BaseThread ._delete )
214274 def delete (
215275 self ,
216276 * ,
217277 timeout : float = 60 ,
218278 ) -> None :
219279 self .__delete (timeout = timeout )
220280
281+ @doc_from (BaseThread ._write )
221282 def write (
222283 self ,
223284 message : MessageType ,
@@ -231,6 +292,7 @@ def write(
231292 timeout = timeout
232293 )
233294
295+ @doc_from (BaseThread ._read )
234296 def read (
235297 self ,
236298 * ,
0 commit comments