Ensure the URL uses HTTP(S) and points to a loopback address.
(url: str)
| 49 | |
| 50 | |
| 51 | def _validate_loopback_url(url: str) -> None: |
| 52 | """Ensure the URL uses HTTP(S) and points to a loopback address.""" |
| 53 | parsed = urllib.parse.urlparse(url) |
| 54 | if parsed.scheme not in ('http', 'https'): |
| 55 | raise ValueError( |
| 56 | f"Docker Model Runner URL must use http or https, " |
| 57 | f"got: {parsed.scheme}" |
| 58 | ) |
| 59 | hostname = (parsed.hostname or '').lower() |
| 60 | if hostname not in _LOOPBACK_HOSTS: |
| 61 | raise ValueError( |
| 62 | f"Docker Model Runner URL must point to a loopback address " |
| 63 | f"(localhost/127.0.0.1/::1), got: {hostname}" |
| 64 | ) |
| 65 | |
| 66 | |
| 67 | class DockerClient(LLMClient): |