Parse the output of fabric --listmodels command.
(output: str)
| 110 | |
| 111 | |
| 112 | def parse_models_output(output: str) -> Dict[str, List[str]]: |
| 113 | """Parse the output of fabric --listmodels command.""" |
| 114 | logger.debug("Parsing models output") |
| 115 | providers = {} |
| 116 | current_provider = None |
| 117 | |
| 118 | lines = output.split("\n") |
| 119 | for line in lines: |
| 120 | line = line.strip() |
| 121 | if not line: |
| 122 | continue |
| 123 | |
| 124 | if line == "Available models:": |
| 125 | continue |
| 126 | |
| 127 | if not line.startswith("\t") and not line.startswith("["): |
| 128 | current_provider = line.strip() |
| 129 | providers[current_provider] = [] |
| 130 | elif current_provider and (line.startswith("\t") or line.startswith("[")): |
| 131 | model = line.strip() |
| 132 | if "[" in model and "]" in model: |
| 133 | model = model.split("]", 1)[1].strip() |
| 134 | providers[current_provider].append(model) |
| 135 | |
| 136 | logger.debug(f"Found providers: {list(providers.keys())}") |
| 137 | return providers |
| 138 | |
| 139 | |
| 140 | def safe_run_command(command: List[str], retry: bool = True) -> Tuple[bool, str, str]: |