(self, **kwargs)
| 49 | return chat |
| 50 | |
| 51 | async def delete(self, **kwargs) -> ModelEntity: |
| 52 | kwargs = self._check_kwargs(object_id_required=True, **kwargs) |
| 53 | assistant_id = kwargs.get("assistant_id") |
| 54 | chat_id = kwargs.get("chat_id") |
| 55 | |
| 56 | async with self.postgres_pool.get_db_connection() as conn: |
| 57 | async with conn.transaction(): |
| 58 | # get assistant |
| 59 | assistant = await assistant_ops.get( |
| 60 | postgres_conn=conn, |
| 61 | assistant_id=assistant_id, |
| 62 | ) |
| 63 | |
| 64 | # get chat |
| 65 | chat = await self.get( |
| 66 | postgres_conn=conn, |
| 67 | assistant_id=assistant_id, |
| 68 | chat_id=chat_id, |
| 69 | ) |
| 70 | |
| 71 | # delete chat |
| 72 | await self._delete_entity(conn, chat) |
| 73 | |
| 74 | # update assistant num_chats |
| 75 | await assistant_ops.update( |
| 76 | postgres_conn=conn, |
| 77 | assistant_id=assistant_id, |
| 78 | update_dict={"num_chats": assistant.num_chats - 1}, |
| 79 | ) |
| 80 | |
| 81 | return assistant |
| 82 | |
| 83 | |
| 84 | chat_ops = ChatModelOperator( |
no test coverage detected