1212
1313
1414class ChatRepository (pydantic .BaseModel ):
15+ """Wrapper around a database session providing functionality relating to chats."""
16+
1517 session : database .AsyncSession
1618
1719 class Config :
@@ -38,6 +40,10 @@ async def get_prompter_message_by_id(self, message_id: str) -> models.DbMessage:
3840 async def start_work (
3941 self , * , message_id : str , worker_id : str , worker_config : inference .WorkerConfig
4042 ) -> models .DbMessage :
43+ """
44+ Update an assistant message in the database to be allocated to a specific worker.
45+ The message must be in `pending` state. An exception is raised if the message has timed out or was cancelled.
46+ """
4147 logger .debug (f"Starting work on message { message_id } " )
4248 message = await self .get_assistant_message_by_id (message_id )
4349
@@ -65,6 +71,10 @@ async def start_work(
6571 return message
6672
6773 async def reset_work (self , message_id : str ) -> models .DbMessage :
74+ """
75+ Update an assistant message in the database which has already been allocated to a worker to remove the
76+ allocation and reset the message state to `pending`.
77+ """
6878 logger .warning (f"Resetting work on message { message_id } " )
6979 message = await self .get_assistant_message_by_id (message_id )
7080 message .state = inference .MessageState .pending
@@ -78,6 +88,7 @@ async def reset_work(self, message_id: str) -> models.DbMessage:
7888 return message
7989
8090 async def abort_work (self , message_id : str , reason : str ) -> models .DbMessage :
91+ """Update an assistant message in the database to mark it as having been aborted by the allocated worker."""
8192 logger .warning (f"Aborting work on message { message_id } " )
8293 message = await self .get_assistant_message_by_id (message_id )
8394 message .state = inference .MessageState .aborted_by_worker
@@ -88,7 +99,13 @@ async def abort_work(self, message_id: str, reason: str) -> models.DbMessage:
8899 await self .session .refresh (message )
89100 return message
90101
91- async def complete_work (self , message_id : str , content : str , used_plugin : inference .PluginUsed ) -> models .DbMessage :
102+ async def complete_work (
103+ self , message_id : str , content : str , used_plugin : inference .PluginUsed | None
104+ ) -> models .DbMessage :
105+ """
106+ Update an assistant message in the database to mark it as having been completed with the given content, also
107+ updating the used plugin if one is specified.
108+ """
92109 logger .debug (f"Completing work on message { message_id } " )
93110 message = await self .get_assistant_message_by_id (message_id )
94111 message .state = inference .MessageState .complete
0 commit comments