From 1e163360fb8ce582a838ea42ad72360f1c338f18 Mon Sep 17 00:00:00 2001 From: Charlie Doern Date: Wed, 12 Mar 2025 14:00:22 -0400 Subject: [PATCH] fix: validate endpoint url currently `llama-stack-client configure` allows a user to set up with a valid URL such as ` ['::', '0.0.0.0']:8321` and then any subsequent command fails due to improperly reading the bad URL from the config.yaml Signed-off-by: Charlie Doern --- src/llama_stack_client/lib/cli/configure.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/llama_stack_client/lib/cli/configure.py b/src/llama_stack_client/lib/cli/configure.py index 9ad4bae5..0319acbe 100644 --- a/src/llama_stack_client/lib/cli/configure.py +++ b/src/llama_stack_client/lib/cli/configure.py @@ -10,6 +10,7 @@ import yaml from prompt_toolkit import prompt from prompt_toolkit.validation import Validator +from urllib.parse import urlparse from llama_stack_client.lib.cli.constants import LLAMA_STACK_CLIENT_CONFIG_DIR, get_config_file_path @@ -36,8 +37,8 @@ def configure(endpoint: str | None, api_key: str | None): final_endpoint = prompt( "> Enter the endpoint of the Llama Stack distribution server: ", validator=Validator.from_callable( - lambda x: len(x) > 0, - error_message="Endpoint cannot be empty, please enter a valid endpoint", + lambda x: len(x) > 0 and (parsed := urlparse(x)).scheme and parsed.netloc, + error_message="Endpoint cannot be empty and must be a valid URL, please enter a valid endpoint", ), )