management.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. from __future__ import annotations # for Python 3.10+
  2. import json
  3. from typing import Any, Optional, Union
  4. from uuid import UUID
  5. from typing_extensions import deprecated
  6. from ..models import Message
  7. class ManagementMixins:
  8. @deprecated("Use client.prompts.update() instead")
  9. async def update_prompt(
  10. self,
  11. name: str,
  12. template: Optional[str] = None,
  13. input_types: Optional[dict[str, str]] = None,
  14. ) -> dict:
  15. """
  16. Update a prompt in the database.
  17. Args:
  18. name (str): The name of the prompt to update.
  19. template (Optional[str]): The new template for the prompt.
  20. input_types (Optional[dict[str, str]]): The new input types for the prompt.
  21. Returns:
  22. dict: The response from the server.
  23. """
  24. data: dict = {"name": name}
  25. if template is not None:
  26. data["template"] = template
  27. if input_types is not None:
  28. data["input_types"] = input_types
  29. return await self._make_request("POST", "update_prompt", json=data) # type: ignore
  30. @deprecated("Use client.prompts.create() instead")
  31. async def add_prompt(
  32. self,
  33. name: str,
  34. template: str,
  35. input_types: dict[str, str],
  36. ) -> dict:
  37. """
  38. Add a new prompt to the system.
  39. Args:
  40. name (str): The name of the prompt.
  41. template (str): The template for the prompt.
  42. input_types (dict[str, str]): The input types for the prompt.
  43. Returns:
  44. dict: The response from the server.
  45. """
  46. data = {
  47. "name": name,
  48. "template": template,
  49. "input_types": input_types,
  50. }
  51. return await self._make_request("POST", "add_prompt", json=data) # type: ignore
  52. @deprecated("Use client.prompts.retrieve() instead")
  53. async def get_prompt(
  54. self,
  55. prompt_name: str,
  56. inputs: Optional[dict[str, Any]] = None,
  57. prompt_override: Optional[str] = None,
  58. ) -> dict:
  59. """
  60. Get a prompt from the system.
  61. Args:
  62. prompt_name (str): The name of the prompt to retrieve.
  63. inputs (Optional[dict[str, Any]]): Optional inputs for the prompt.
  64. prompt_override (Optional[str]): Optional override for the prompt template.
  65. Returns:
  66. dict: The response from the server.
  67. """
  68. params = {}
  69. if inputs:
  70. params["inputs"] = json.dumps(inputs)
  71. if prompt_override:
  72. params["prompt_override"] = prompt_override
  73. return await self._make_request( # type: ignore
  74. "GET", f"get_prompt/{prompt_name}", params=params
  75. )
  76. @deprecated("Use client.prompts.list() instead")
  77. async def get_all_prompts(self) -> dict:
  78. """
  79. Get all prompts from the system.
  80. Returns:
  81. dict: The response from the server containing all prompts.
  82. """
  83. return await self._make_request("GET", "get_all_prompts") # type: ignore
  84. @deprecated("Use client.prompts.delete() instead")
  85. async def delete_prompt(self, prompt_name: str) -> dict:
  86. """
  87. Delete a prompt from the system.
  88. Args:
  89. prompt_name (str): The name of the prompt to delete.
  90. Returns:
  91. dict: The response from the server.
  92. """
  93. return await self._make_request( # type: ignore
  94. "DELETE", f"delete_prompt/{prompt_name}"
  95. )
  96. @deprecated(
  97. "This method is deprecated. New, improved analytics features will be added in a future release."
  98. )
  99. async def analytics(
  100. self,
  101. filter_criteria: Optional[Union[dict, str]] = None,
  102. analysis_types: Optional[Union[dict, str]] = None,
  103. ) -> dict:
  104. """
  105. Get analytics data from the server.
  106. Args:
  107. filter_criteria (Optional[Union[dict, str]]): The filter criteria to use.
  108. analysis_types (Optional[Union[dict, str]]): The types of analysis to perform.
  109. Returns:
  110. dict: The analytics data from the server.
  111. """
  112. params = {}
  113. if filter_criteria:
  114. if isinstance(filter_criteria, dict):
  115. params["filter_criteria"] = json.dumps(filter_criteria)
  116. else:
  117. params["filter_criteria"] = filter_criteria
  118. if analysis_types:
  119. if isinstance(analysis_types, dict):
  120. params["analysis_types"] = json.dumps(analysis_types)
  121. else:
  122. params["analysis_types"] = analysis_types
  123. return await self._make_request("GET", "analytics", params=params) # type: ignore
  124. @deprecated("Use client.system.settings() instead")
  125. async def app_settings(self) -> dict:
  126. """
  127. Get the configuration settings for the app.
  128. Returns:
  129. dict: The app settings.
  130. """
  131. return await self._make_request("GET", "app_settings") # type: ignore
  132. @deprecated("Use client.users.list() instead")
  133. async def users_overview(
  134. self,
  135. user_ids: Optional[list[str]] = None,
  136. offset: Optional[int] = None,
  137. limit: Optional[int] = None,
  138. ) -> dict:
  139. """
  140. An overview of users in the R2R deployment.
  141. Args:
  142. user_ids (Optional[list[str]]): List of user IDs to get an overview for.
  143. Returns:
  144. dict: The overview of users in the system.
  145. """
  146. params: dict = {}
  147. if user_ids is not None:
  148. params["user_ids"] = [str(uid) for uid in user_ids]
  149. if offset is not None:
  150. params["offset"] = offset
  151. if limit is not None:
  152. params["limit"] = limit
  153. return await self._make_request( # type: ignore
  154. "GET", "users_overview", params=params
  155. )
  156. @deprecated("Use client.<object>.delete() instead")
  157. async def delete(
  158. self,
  159. filters: dict,
  160. ) -> dict:
  161. """
  162. Delete data from the database given a set of filters.
  163. Args:
  164. filters (dict[str, str]): The filters to delete by.
  165. Returns:
  166. dict: The results of the deletion.
  167. """
  168. filters_json = json.dumps(filters)
  169. return await self._make_request( # type: ignore
  170. "DELETE", "delete", params={"filters": filters_json}
  171. ) or {"results": {}}
  172. @deprecated("Use client.documents.download() instead")
  173. async def download_file(
  174. self,
  175. document_id: Union[str, UUID],
  176. ):
  177. """
  178. Download a file from the R2R deployment.
  179. Args:
  180. document_id (str): The ID of the document to download.
  181. Returns:
  182. dict: The response from the server.
  183. """
  184. return await self._make_request( # type: ignore
  185. "GET", f"download_file/{str(document_id)}"
  186. )
  187. @deprecated("Use client.documents.list() instead")
  188. async def documents_overview(
  189. self,
  190. document_ids: Optional[list[Union[UUID, str]]] = None,
  191. offset: Optional[int] = None,
  192. limit: Optional[int] = None,
  193. ) -> dict:
  194. """
  195. Get an overview of documents in the R2R deployment.
  196. Args:
  197. document_ids (Optional[list[str]]): List of document IDs to get an overview for.
  198. Returns:
  199. dict: The overview of documents in the system.
  200. """
  201. params: dict = {}
  202. document_ids = (
  203. [str(doc_id) for doc_id in document_ids] if document_ids else None
  204. )
  205. if document_ids:
  206. params["document_ids"] = document_ids
  207. if offset is not None:
  208. params["offset"] = offset
  209. if limit is not None:
  210. params["limit"] = limit
  211. return await self._make_request( # type: ignore
  212. "GET", "documents_overview", params=params
  213. )
  214. @deprecated("Use client.documents.list_chunks() instead")
  215. async def document_chunks(
  216. self,
  217. document_id: str,
  218. offset: Optional[int] = None,
  219. limit: Optional[int] = None,
  220. include_vectors: Optional[bool] = False,
  221. ) -> dict:
  222. """
  223. Get the chunks for a document.
  224. Args:
  225. document_id (str): The ID of the document to get chunks for.
  226. Returns:
  227. dict: The chunks for the document.
  228. """
  229. params: dict = {}
  230. if offset is not None:
  231. params["offset"] = offset
  232. if limit is not None:
  233. params["limit"] = limit
  234. if include_vectors:
  235. params["include_vectors"] = include_vectors
  236. if not params:
  237. return await self._make_request( # type: ignore
  238. "GET", f"document_chunks/{document_id}"
  239. )
  240. else:
  241. return await self._make_request( # type: ignore
  242. "GET", f"document_chunks/{document_id}", params=params
  243. )
  244. @deprecated("Use client.collections.list() instead")
  245. async def collections_overview(
  246. self,
  247. collection_ids: Optional[list[str]] = None,
  248. offset: Optional[int] = None,
  249. limit: Optional[int] = None,
  250. ) -> dict:
  251. """
  252. Get an overview of existing collections.
  253. Args:
  254. collection_ids (Optional[list[str]]): List of collection IDs to get an overview for.
  255. limit (Optional[int]): The maximum number of collections to return.
  256. offset (Optional[int]): The offset to start listing collections from.
  257. Returns:
  258. dict: The overview of collections in the system.
  259. """
  260. params: dict = {}
  261. if collection_ids:
  262. params["collection_ids"] = collection_ids
  263. if offset:
  264. params["offset"] = offset
  265. if limit:
  266. params["limit"] = limit
  267. return await self._make_request( # type: ignore
  268. "GET", "collections_overview", params=params
  269. )
  270. @deprecated("Use client.collections.create() instead")
  271. async def create_collection(
  272. self,
  273. name: str,
  274. description: Optional[str] = None,
  275. ) -> dict:
  276. """
  277. Create a new collection.
  278. Args:
  279. name (str): The name of the collection.
  280. description (Optional[str]): The description of the collection.
  281. Returns:
  282. dict: The response from the server.
  283. """
  284. data = {"name": name}
  285. if description is not None:
  286. data["description"] = description
  287. return await self._make_request( # type: ignore
  288. "POST", "create_collection", json=data
  289. )
  290. @deprecated("Use client.collections.retrieve() instead")
  291. async def get_collection(
  292. self,
  293. collection_id: Union[str, UUID],
  294. ) -> dict:
  295. """
  296. Get a collection by its ID.
  297. Args:
  298. collection_id (str): The ID of the collection to get.
  299. Returns:
  300. dict: The collection data.
  301. """
  302. return await self._make_request( # type: ignore
  303. "GET", f"get_collection/{str(collection_id)}"
  304. )
  305. @deprecated("Use client.collections.update() instead")
  306. async def update_collection(
  307. self,
  308. collection_id: Union[str, UUID],
  309. name: Optional[str] = None,
  310. description: Optional[str] = None,
  311. ) -> dict:
  312. """
  313. Updates the name and description of a collection.
  314. Args:
  315. collection_id (str): The ID of the collection to update.
  316. name (Optional[str]): The new name for the collection.
  317. description (Optional[str]): The new description of the collection.
  318. Returns:
  319. dict: The response from the server.
  320. """
  321. data = {"collection_id": str(collection_id)}
  322. if name is not None:
  323. data["name"] = name
  324. if description is not None:
  325. data["description"] = description
  326. return await self._make_request( # type: ignore
  327. "PUT", "update_collection", json=data
  328. )
  329. @deprecated("Use client.collections.delete() instead")
  330. async def delete_collection(
  331. self,
  332. collection_id: Union[str, UUID],
  333. ) -> dict:
  334. """
  335. Delete a collection by its ID.
  336. Args:
  337. collection_id (str): The ID of the collection to delete.
  338. Returns:
  339. dict: The response from the server.
  340. """
  341. return await self._make_request( # type: ignore
  342. "DELETE", f"delete_collection/{str(collection_id)}"
  343. )
  344. @deprecated("Use client.users.delete() instead")
  345. async def delete_user(
  346. self,
  347. user_id: str,
  348. password: Optional[str] = None,
  349. delete_vector_data: bool = False,
  350. ) -> dict:
  351. """
  352. Delete a collection by its ID.
  353. Args:
  354. collection_id (str): The ID of the collection to delete.
  355. Returns:
  356. dict: The response from the server.
  357. """
  358. params: dict = {}
  359. if password is not None:
  360. params["password"] = password
  361. if delete_vector_data:
  362. params["delete_vector_data"] = delete_vector_data
  363. if not params:
  364. return await self._make_request("DELETE", f"user/{user_id}") # type: ignore
  365. else:
  366. return await self._make_request( # type: ignore
  367. "DELETE", f"user/{user_id}", json=params
  368. )
  369. @deprecated("Use client.collections.list() instead")
  370. async def list_collections(
  371. self,
  372. offset: Optional[int] = None,
  373. limit: Optional[int] = None,
  374. ) -> dict:
  375. """
  376. List all collections in the R2R deployment.
  377. Args:
  378. offset (Optional[int]): The offset to start listing collections from.
  379. limit (Optional[int]): The maximum number of collections to return.
  380. Returns:
  381. dict: The list of collections.
  382. """
  383. params = {}
  384. if offset is not None:
  385. params["offset"] = offset
  386. if limit is not None:
  387. params["limit"] = limit
  388. return await self._make_request( # type: ignore
  389. "GET", "list_collections", params=params
  390. )
  391. @deprecated("Use client.collections.add_user() instead")
  392. async def add_user_to_collection(
  393. self,
  394. user_id: Union[str, UUID],
  395. collection_id: Union[str, UUID],
  396. ) -> dict:
  397. """
  398. Add a user to a collection.
  399. Args:
  400. user_id (str): The ID of the user to add.
  401. collection_id (str): The ID of the collection to add the user to.
  402. Returns:
  403. dict: The response from the server.
  404. """
  405. data = {
  406. "user_id": str(user_id),
  407. "collection_id": str(collection_id),
  408. }
  409. return await self._make_request( # type: ignore
  410. "POST", "add_user_to_collection", json=data
  411. )
  412. @deprecated("Use client.collections.remove_user() instead")
  413. async def remove_user_from_collection(
  414. self,
  415. user_id: Union[str, UUID],
  416. collection_id: Union[str, UUID],
  417. ) -> dict:
  418. """
  419. Remove a user from a collection.
  420. Args:
  421. user_id (str): The ID of the user to remove.
  422. collection_id (str): The ID of the collection to remove the user from.
  423. Returns:
  424. dict: The response from the server.
  425. """
  426. data = {
  427. "user_id": str(user_id),
  428. "collection_id": str(collection_id),
  429. }
  430. return await self._make_request( # type: ignore
  431. "POST", "remove_user_from_collection", json=data
  432. )
  433. @deprecated("Use client.collections.list_users() instead")
  434. async def get_users_in_collection(
  435. self,
  436. collection_id: Union[str, UUID],
  437. offset: Optional[int] = None,
  438. limit: Optional[int] = None,
  439. ) -> dict:
  440. """
  441. Get all users in a collection.
  442. Args:
  443. collection_id (str): The ID of the collection to get users for.
  444. offset (Optional[int]): The offset to start listing users from.
  445. limit (Optional[int]): The maximum number of users to return.
  446. Returns:
  447. dict: The list of users in the collection.
  448. """
  449. params = {}
  450. if offset is not None:
  451. params["offset"] = offset
  452. if limit is not None:
  453. params["limit"] = limit
  454. return await self._make_request( # type: ignore
  455. "GET",
  456. f"get_users_in_collection/{str(collection_id)}",
  457. params=params,
  458. )
  459. @deprecated("Use client.users.list_collections() instead")
  460. async def user_collections(
  461. self,
  462. user_id: Union[str, UUID],
  463. offset: Optional[int] = None,
  464. limit: Optional[int] = None,
  465. ) -> dict:
  466. """
  467. Get all collections that a user is a member of.
  468. Args:
  469. user_id (str): The ID of the user to get collections for.
  470. Returns:
  471. dict: The list of collections that the user is a member of.
  472. """
  473. params = {}
  474. if offset is not None:
  475. params["offset"] = offset
  476. if limit is not None:
  477. params["limit"] = limit
  478. if not params:
  479. return await self._make_request( # type: ignore
  480. "GET", f"user_collections/{str(user_id)}"
  481. )
  482. else:
  483. return await self._make_request( # type: ignore
  484. "GET", f"user_collections/{str(user_id)}", params=params
  485. )
  486. @deprecated("Use client.collections.add_document() instead")
  487. async def assign_document_to_collection(
  488. self,
  489. document_id: Union[str, UUID],
  490. collection_id: Union[str, UUID],
  491. ) -> dict:
  492. """
  493. Assign a document to a collection.
  494. Args:
  495. document_id (str): The ID of the document to assign.
  496. collection_id (str): The ID of the collection to assign the document to.
  497. Returns:
  498. dict: The response from the server.
  499. """
  500. data = {
  501. "document_id": str(document_id),
  502. "collection_id": str(collection_id),
  503. }
  504. return await self._make_request( # type: ignore
  505. "POST", "assign_document_to_collection", json=data
  506. )
  507. # TODO: Verify that this method is implemented, also, should be a PUT request
  508. @deprecated("Use client.collections.remove_document() instead")
  509. async def remove_document_from_collection(
  510. self,
  511. document_id: Union[str, UUID],
  512. collection_id: Union[str, UUID],
  513. ) -> dict:
  514. """
  515. Remove a document from a collection.
  516. Args:
  517. document_id (str): The ID of the document to remove.
  518. collection_id (str): The ID of the collection to remove the document from.
  519. Returns:
  520. dict: The response from the server.
  521. """
  522. data = {
  523. "document_id": str(document_id),
  524. "collection_id": str(collection_id),
  525. }
  526. return await self._make_request( # type: ignore
  527. "POST", "remove_document_from_collection", json=data
  528. )
  529. @deprecated("Use client.documents.list_collections() instead")
  530. async def document_collections(
  531. self,
  532. document_id: Union[str, UUID],
  533. offset: Optional[int] = None,
  534. limit: Optional[int] = None,
  535. ) -> dict:
  536. """
  537. Get all collections that a document is assigned to.
  538. Args:
  539. document_id (str): The ID of the document to get collections for.
  540. Returns:
  541. dict: The list of collections that the document is assigned to.
  542. """
  543. params = {}
  544. if offset is not None:
  545. params["offset"] = offset
  546. if limit is not None:
  547. params["limit"] = limit
  548. if not params:
  549. return await self._make_request( # type: ignore
  550. "GET",
  551. f"document_collections/{str(document_id)}",
  552. params=params,
  553. )
  554. else:
  555. return await self._make_request( # type: ignore
  556. "GET", f"document_collections/{str(document_id)}"
  557. )
  558. @deprecated("Use client.collections.list_documents() instead")
  559. async def documents_in_collection(
  560. self,
  561. collection_id: Union[str, UUID],
  562. offset: Optional[int] = None,
  563. limit: Optional[int] = None,
  564. ) -> dict:
  565. """
  566. Get all documents in a collection.
  567. Args:
  568. collection_id (str): The ID of the collection to get documents for.
  569. offset (Optional[int]): The offset to start listing documents from.
  570. limit (Optional[int]): The maximum number of documents to return.
  571. Returns:
  572. dict: The list of documents in the collection.
  573. """
  574. params = {}
  575. if offset is not None:
  576. params["offset"] = offset
  577. if limit is not None:
  578. params["limit"] = limit
  579. return await self._make_request( # type: ignore
  580. "GET", f"collection/{str(collection_id)}/documents", params=params
  581. )
  582. @deprecated("Use client.conversations.list() instead")
  583. async def conversations_overview(
  584. self,
  585. conversation_ids: Optional[list[Union[UUID, str]]] = None,
  586. offset: Optional[int] = None,
  587. limit: Optional[int] = None,
  588. ) -> dict:
  589. """
  590. Get an overview of existing conversations.
  591. Args:
  592. conversation_ids (Optional[list[Union[UUID, str]]]): list of conversation IDs to retrieve.
  593. offset (Optional[int]): The offset to start listing conversations from.
  594. limit (Optional[int]): The maximum number of conversations to return.
  595. Returns:
  596. dict[str, any]: The overview of conversations in the system.
  597. """
  598. params: dict = {}
  599. if conversation_ids:
  600. params["conversation_ids"] = [str(cid) for cid in conversation_ids]
  601. if offset is not None:
  602. params["offset"] = offset
  603. if limit is not None:
  604. params["limit"] = limit
  605. return await self._make_request( # type: ignore
  606. "GET", "conversations_overview", params=params
  607. )
  608. @deprecated("Use client.conversations.retrieve() instead")
  609. async def get_conversation(
  610. self,
  611. conversation_id: Union[str, UUID],
  612. ) -> dict:
  613. """
  614. Get a conversation by its ID.
  615. Args:
  616. conversation_id (Union[str, UUID]): The ID of the conversation to retrieve.
  617. Returns:
  618. dict: The conversation data.
  619. """
  620. return await self._make_request( # type: ignore
  621. "GET", f"get_conversation/{str(conversation_id)}"
  622. )
  623. @deprecated("Use client.conversations.create() instead")
  624. async def create_conversation(self) -> dict:
  625. """
  626. Create a new conversation.
  627. Returns:
  628. dict: The response from the server.
  629. """
  630. return await self._make_request("POST", "create_conversation") # type: ignore
  631. @deprecated("Use client.conversations.add_message() instead")
  632. async def add_message(
  633. self,
  634. conversation_id: Union[str, UUID],
  635. message: dict,
  636. parent_id: Optional[str] = None,
  637. metadata: Optional[dict[str, Any]] = None,
  638. ) -> dict:
  639. """
  640. Add a message to an existing conversation.
  641. Args:
  642. conversation_id (Union[str, UUID]): The ID of the conversation.
  643. message (Message): The message to add.
  644. parent_id (Optional[str]): The ID of the parent message.
  645. metadata (Optional[dict[str, Any]]): Additional metadata for the message.
  646. Returns:
  647. dict: The response from the server.
  648. """
  649. data: dict = {"message": message}
  650. if parent_id is not None:
  651. data["parent_id"] = parent_id
  652. if metadata is not None:
  653. data["metadata"] = metadata
  654. if len(data) == 1:
  655. return await self._make_request( # type: ignore
  656. "POST", f"add_message/{str(conversation_id)}", json=data
  657. )
  658. else:
  659. return await self._make_request( # type: ignore
  660. "POST", f"add_message/{str(conversation_id)}", data=data
  661. )
  662. @deprecated("Use client.conversations.update_message() instead")
  663. async def update_message(
  664. self,
  665. message_id: str,
  666. message: Message,
  667. ) -> dict:
  668. """
  669. Update a message in an existing conversation.
  670. Args:
  671. message_id (str): The ID of the message to update.
  672. message (Message): The updated message.
  673. Returns:
  674. dict: The response from the server.
  675. """
  676. return await self._make_request( # type: ignore
  677. "PUT", f"update_message/{message_id}", data=message
  678. )
  679. async def update_message_metadata(
  680. self,
  681. message_id: str,
  682. metadata: dict[str, Any],
  683. ) -> dict:
  684. """
  685. Update the metadata of a message.
  686. Args:
  687. message_id (str): The ID of the message to update.
  688. metadata (dict[str, Any]): The metadata to update.
  689. Returns:
  690. dict: The response from the server.
  691. """
  692. return await self._make_request( # type: ignore
  693. "PATCH", f"messages/{message_id}/metadata", json=metadata
  694. )
  695. @deprecated("Use client.conversations.list_branches() instead")
  696. async def branches_overview(
  697. self,
  698. conversation_id: Union[str, UUID],
  699. ) -> dict:
  700. """
  701. Get an overview of branches in a conversation.
  702. Args:
  703. conversation_id (Union[str, UUID]): The ID of the conversation to get branches for.
  704. Returns:
  705. dict: The response from the server.
  706. """
  707. return await self._make_request( # type: ignore
  708. "GET", f"branches_overview/{str(conversation_id)}"
  709. )
  710. # TODO: Publish these methods once more testing is done
  711. # async def get_next_branch(self, branch_id: str) -> dict:
  712. # """
  713. # Get the next branch in a conversation.
  714. #
  715. # Args:
  716. # branch_id (str): The ID of the branch to get the next branch for.
  717. #
  718. # Returns:
  719. # dict: The response from the server.
  720. # """
  721. # return await self._make_request("GET", f"get_next_branch/{branch_id}") # type: ignore
  722. #
  723. # async def get_previous_branch(self, branch_id: str) -> dict:
  724. # """
  725. # Get the previous branch in a conversation.
  726. #
  727. # Args:
  728. # branch_id (str): The ID of the branch to get the previous branch for.
  729. #
  730. # Returns:
  731. # dict: The response from the server.
  732. # """
  733. # return await self._make_request("GET", f"get_previous_branch/{branch_id}") # type: ignore
  734. #
  735. # async def branch_at_message(
  736. # self,
  737. # conversation_id: Union[str, UUID],
  738. # message_id: str,
  739. # ) -> dict:
  740. # """
  741. # Branch at a specific message in a conversation.
  742. #
  743. # Args:
  744. # conversation_id (Union[str, UUID]): The ID of the conversation to branch.
  745. # message_id (str): The ID of the message to branch at.
  746. #
  747. # Returns:
  748. # dict: The response from the server.
  749. # """
  750. # return await self._make_request("POST", f"branch_at_message/{str(conversation_id)}/{message_id}") # type: ignore
  751. @deprecated("Use client.conversations.delete() instead")
  752. async def delete_conversation(
  753. self,
  754. conversation_id: Union[str, UUID],
  755. ) -> dict:
  756. """
  757. Delete a conversation by its ID.
  758. Args:
  759. conversation_id (Union[str, UUID]): The ID of the conversation to delete.
  760. Returns:
  761. dict: The response from the server.
  762. """
  763. return await self._make_request( # type: ignore
  764. "DELETE", f"delete_conversation/{str(conversation_id)}"
  765. )