feat: emit verbose client info when --verbose/--debug set
This commit is contained in:
parent
9b89845280
commit
0d0d40e219
1 changed files with 28 additions and 3 deletions
|
|
@ -99,12 +99,17 @@ def create_client(
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = config.defaults.timeout
|
timeout = config.defaults.timeout
|
||||||
|
|
||||||
return httpx.Client(
|
client = httpx.Client(
|
||||||
base_url=effective_uri,
|
base_url=effective_uri,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if _is_verbose_enabled():
|
||||||
|
_emit_verbose_config(effective_uri, headers, timeout)
|
||||||
|
|
||||||
|
return client
|
||||||
|
|
||||||
|
|
||||||
def create_async_client(
|
def create_async_client(
|
||||||
profile: str | None = None,
|
profile: str | None = None,
|
||||||
|
|
@ -153,12 +158,17 @@ def create_async_client(
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = config.defaults.timeout
|
timeout = config.defaults.timeout
|
||||||
|
|
||||||
return httpx.AsyncClient(
|
client = httpx.AsyncClient(
|
||||||
base_url=effective_uri,
|
base_url=effective_uri,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if _is_verbose_enabled():
|
||||||
|
_emit_verbose_config(effective_uri, headers, timeout, async_client=True)
|
||||||
|
|
||||||
|
return client
|
||||||
|
|
||||||
|
|
||||||
def handle_response(response: httpx.Response) -> dict[str, Any]:
|
def handle_response(response: httpx.Response) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
|
|
@ -264,9 +274,24 @@ def _is_verbose_enabled() -> bool:
|
||||||
try:
|
try:
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
ctx = typer.get_current_context(silent=True)
|
ctx = typer.core.TyperGroup.get_current_context(silent=True) # type: ignore[attr-defined]
|
||||||
if ctx and isinstance(ctx.obj, dict):
|
if ctx and isinstance(ctx.obj, dict):
|
||||||
return bool(ctx.obj.get("verbose"))
|
return bool(ctx.obj.get("verbose"))
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _emit_verbose_config(
|
||||||
|
uri: str, headers: dict[str, str], timeout: float, async_client: bool = False
|
||||||
|
) -> None:
|
||||||
|
"""Emit basic client config when verbose is enabled."""
|
||||||
|
try:
|
||||||
|
Console().log(
|
||||||
|
f"[bold cyan]openwebui-cli[/bold cyan] client init "
|
||||||
|
f"(async={async_client}) uri={uri} timeout={timeout}s "
|
||||||
|
f"auth={'yes' if 'Authorization' in headers else 'no'}"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
# Do not break execution if logging fails
|
||||||
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue