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 working with messages that the thread contains (e.g. updating, deleting, writing to, and reading from).
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,16 @@ 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. Could be a string, a dictionary, or a result object.
129+ Read more about other possible message types in the `documentation <https://yandex.cloud/docs/foundation-models/sdk/#usage>`_.
130+ :param labels: optional labels for the message.
131+ :param timeout: timeout for the operation.
132+ Defaults to 60 seconds.
133+ """
100134 # pylint: disable-next=protected-access
101135 return await self ._sdk ._messages ._create (
102136 thread_id = self .id ,
@@ -110,6 +144,13 @@ async def _read(
110144 * ,
111145 timeout : float = 60 ,
112146 ) -> AsyncIterator [Message ]:
147+ """Read messages from the thread.
148+
149+ This method allows iterating over messages in the thread.
150+
151+ :param timeout: timeout for the operation.
152+ Defaults to 60 seconds.
153+ """
113154 # NB: in other methods it is solved via @safe decorator, but it is doesn't work
114155 # with iterators, so, temporary here will be small copypaste
115156 # Also I'm not sure enough if we need to put whole thread reading under a lock
@@ -125,17 +166,26 @@ async def _read(
125166
126167@dataclasses .dataclass (frozen = True )
127168class RichThread (BaseThread ):
169+ #: the name of the thread
128170 name : str | None
171+ #: the description of the thread
129172 description : str | None
173+ #: the identifier of the user who created the thread
130174 created_by : str
175+ #: the timestamp when the thread was created
131176 created_at : datetime
177+ #: the identifier of the user who last updated the thread
132178 updated_by : str
179+ #: the timestamp when the thread was last updated
133180 updated_at : datetime
181+ #: the timestamp when the thread will expire
134182 expires_at : datetime
183+ #: additional labels associated with the thread
135184 labels : dict [str , str ] | None
136185
137-
138186class AsyncThread (RichThread ):
187+
188+ @doc_from (BaseThread ._update )
139189 async def update (
140190 self ,
141191 * ,
@@ -155,13 +205,15 @@ async def update(
155205 timeout = timeout ,
156206 )
157207
208+ @doc_from (BaseThread ._delete )
158209 async def delete (
159210 self ,
160211 * ,
161212 timeout : float = 60 ,
162213 ) -> None :
163214 await self ._delete (timeout = timeout )
164215
216+ @doc_from (BaseThread ._write )
165217 async def write (
166218 self ,
167219 message : MessageType ,
@@ -175,6 +227,7 @@ async def write(
175227 timeout = timeout
176228 )
177229
230+ @doc_from (BaseThread ._read )
178231 async def read (
179232 self ,
180233 * ,
@@ -183,15 +236,16 @@ async def read(
183236 async for message in self ._read (timeout = timeout ):
184237 yield message
185238
239+ #: alias for the read method
186240 __aiter__ = read
187241
188-
189242class Thread (RichThread ):
190243 __update = run_sync (RichThread ._update )
191244 __delete = run_sync (RichThread ._delete )
192245 __write = run_sync (RichThread ._write )
193246 __read = run_sync_generator (RichThread ._read )
194247
248+ @doc_from (BaseThread ._update )
195249 def update (
196250 self ,
197251 * ,
@@ -211,13 +265,15 @@ def update(
211265 timeout = timeout ,
212266 )
213267
268+ @doc_from (BaseThread ._delete )
214269 def delete (
215270 self ,
216271 * ,
217272 timeout : float = 60 ,
218273 ) -> None :
219274 self .__delete (timeout = timeout )
220275
276+ @doc_from (BaseThread ._write )
221277 def write (
222278 self ,
223279 message : MessageType ,
@@ -231,6 +287,7 @@ def write(
231287 timeout = timeout
232288 )
233289
290+ @doc_from (BaseThread ._read )
234291 def read (
235292 self ,
236293 * ,
0 commit comments