Parse lora adapers from cli input. Args: adapters (list[str]): CLI input string of lora adapter path(s). Returns: dict[str, str] | None: Parsed lora adapter path(s).
(adapters: list[str])
| 40 | |
| 41 | |
| 42 | def get_lora_adapters(adapters: list[str]): |
| 43 | """Parse lora adapers from cli input. |
| 44 | |
| 45 | Args: |
| 46 | adapters (list[str]): CLI input string of lora adapter path(s). |
| 47 | |
| 48 | Returns: |
| 49 | dict[str, str] | None: Parsed lora adapter path(s). |
| 50 | """ |
| 51 | if not adapters: |
| 52 | return None |
| 53 | n = len(adapters) |
| 54 | output = {} |
| 55 | if n == 1: |
| 56 | name = 'default' |
| 57 | path = adapters[0].strip() |
| 58 | if '=' in path: |
| 59 | name, path = path.split('=', 1) |
| 60 | output[name] = path |
| 61 | else: |
| 62 | for pair in adapters: |
| 63 | assert '=' in pair, f'Multiple lora paths must in format of ' \ |
| 64 | f'xxx=yyy. But given: {pair}' |
| 65 | name, path = pair.strip().split('=', 1) |
| 66 | assert name not in output, f'Multiple lora paths with repeated lora name: {name}' |
| 67 | output[name] = path |
| 68 | return output |
| 69 | |
| 70 | |
| 71 | def get_chat_template(chat_template: str, model_path: str = None): |
no outgoing calls
no test coverage detected