(self, create_dict: Dict, **kwargs)
| 12 | |
| 13 | class ChatModelOperator(PostgresModelOperator): |
| 14 | async def create(self, create_dict: Dict, **kwargs) -> ModelEntity: |
| 15 | kwargs = self._check_kwargs(object_id_required=None, **kwargs) |
| 16 | assistant_id = kwargs.get("assistant_id") |
| 17 | name = create_dict.get("name", "") |
| 18 | metadata = create_dict.get("metadata", {}) |
| 19 | |
| 20 | async with self.postgres_pool.get_db_connection() as conn: |
| 21 | async with conn.transaction(): |
| 22 | # validate assistant |
| 23 | assistant: Assistant = await assistant_ops.get( |
| 24 | postgres_conn=conn, |
| 25 | assistant_id=assistant_id, |
| 26 | ) |
| 27 | |
| 28 | # initialize chat memory |
| 29 | chat_memory: ChatMemory = assistant.memory.init_chat_memory() |
| 30 | |
| 31 | # create chat |
| 32 | chat = await self._create_entity( |
| 33 | conn, |
| 34 | create_dict={ |
| 35 | "memory": chat_memory.model_dump(), |
| 36 | "name": name, |
| 37 | "metadata": metadata, |
| 38 | }, |
| 39 | **kwargs, |
| 40 | ) |
| 41 | |
| 42 | # update assistant num_chats |
| 43 | await assistant_ops.update( |
| 44 | postgres_conn=conn, |
| 45 | assistant_id=assistant_id, |
| 46 | update_dict={"num_chats": assistant.num_chats + 1}, |
| 47 | ) |
| 48 | |
| 49 | return chat |
| 50 | |
| 51 | async def delete(self, **kwargs) -> ModelEntity: |
| 52 | kwargs = self._check_kwargs(object_id_required=True, **kwargs) |
nothing calls this directly
no test coverage detected