Initialize async engine and create tables.
(self)
| 333 | self.total_samples = float("inf") |
| 334 | |
| 335 | async def prepare(self) -> None: |
| 336 | """Initialize async engine and create tables.""" |
| 337 | if self._initialized: |
| 338 | return |
| 339 | from trinity.buffer.schema.formatter import TaskFormatter |
| 340 | |
| 341 | result = await init_async_engine( |
| 342 | self.config.path, self.config.name, self.config.schema_type # type: ignore |
| 343 | ) |
| 344 | self.engine, self.table_model_cls = result |
| 345 | self.session = async_sessionmaker(self.engine, expire_on_commit=False) |
| 346 | self.default_workflow_cls = WORKFLOWS.get(self.config.default_workflow_type) |
| 347 | self.default_reward_fn_cls = REWARD_FUNCTIONS.get(self.config.default_reward_fn_type) |
| 348 | self.formatter = TaskFormatter(self.config) |
| 349 | self._initialized = True |
| 350 | self.logger.info(f"SQL task storage initialized at {self.config.path}") |
| 351 | |
| 352 | async def write(self, data: List[Dict]) -> None: |
| 353 | await self.prepare() |