Resolve (db_url, table_name, tokenizer_path) from a Trinity config file. Reads the experience pipeline's saved input. The viewer is only usable when the pipeline actually writes a SQL database, so requests are rejected when ``save_input`` is disabled or ``input_save_path`` is not a data
(config_path: str)
| 18 | |
| 19 | |
| 20 | def _resolve_from_config(config_path: str) -> tuple[str, str, str]: |
| 21 | """Resolve (db_url, table_name, tokenizer_path) from a Trinity config file. |
| 22 | |
| 23 | Reads the experience pipeline's saved input. The viewer is only usable when |
| 24 | the pipeline actually writes a SQL database, so requests are rejected when |
| 25 | ``save_input`` is disabled or ``input_save_path`` is not a database URL. |
| 26 | """ |
| 27 | from trinity.buffer.storage.queue import is_database_url |
| 28 | from trinity.common.config import load_config |
| 29 | |
| 30 | config = load_config(config_path) |
| 31 | pipeline_cfg = config.data_processor.experience_pipeline |
| 32 | |
| 33 | if not pipeline_cfg.save_input: |
| 34 | raise typer.BadParameter( |
| 35 | f"Cannot view from {config_path}: " |
| 36 | "data_processor.experience_pipeline.save_input is False, " |
| 37 | "so no input database is produced." |
| 38 | ) |
| 39 | save_path = pipeline_cfg.input_save_path |
| 40 | if save_path is None: |
| 41 | # save_input is on but no path given: the pipeline writes a SQLite DB |
| 42 | # under the buffer cache dir. Resolve the same default so `view` works |
| 43 | # without a full config validation pass. |
| 44 | from trinity.buffer.pipelines.experience_pipeline import default_input_save_path |
| 45 | |
| 46 | save_path = default_input_save_path(config) |
| 47 | if not is_database_url(save_path): |
| 48 | raise typer.BadParameter( |
| 49 | f"Cannot view from {config_path}: " |
| 50 | "data_processor.experience_pipeline.input_save_path " |
| 51 | f"({save_path!r}) is not a database URL, so no SQL database is produced." |
| 52 | ) |
| 53 | |
| 54 | tokenizer_path = config.model.model_path |
| 55 | if not tokenizer_path: |
| 56 | raise typer.BadParameter(f"Cannot view from {config_path}: model.model_path is not set.") |
| 57 | |
| 58 | _warn_if_renamed(config) |
| 59 | |
| 60 | # Mirrors ExperiencePipeline: the SQL input writer is created with table |
| 61 | # name "pipeline_input" (see trinity/buffer/pipelines/experience_pipeline.py). |
| 62 | return save_path, "pipeline_input", tokenizer_path |
| 63 | |
| 64 | |
| 65 | def _warn_if_renamed(config) -> None: |