From c81da86460c8f03ac0dda8118faf496ec11e6f71 Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Tue, 15 Oct 2024 18:13:44 -0700 Subject: [PATCH] Fix nits in CLI (#108) Fixes: - [Opening browser doesn't work in ssh](https://app.clickup.com/t/86b2h46f7) - ["bright black" color text in `arcade chat -d` is invisible in iTerm](https://app.clickup.com/t/86b2h494v) - [Colors and styles are inconsistent in non-zsh shells](https://app.clickup.com/t/86b2h49kb) --- arcade/arcade/cli/display.py | 5 +++-- arcade/arcade/cli/main.py | 25 ++++++++++++++++++------- arcade/arcade/cli/utils.py | 6 +++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/arcade/arcade/cli/display.py b/arcade/arcade/cli/display.py index 5cb55b81..cc3200ed 100644 --- a/arcade/arcade/cli/display.py +++ b/arcade/arcade/cli/display.py @@ -116,11 +116,12 @@ def display_tool_messages(tool_messages: list[dict]) -> None: if message["role"] == "assistant": for tool_call in message.get("tool_calls", []): console.print( - f"[bright_black][bold]Called tool '{tool_call['function']['name']}'[/bold]\n[bold]Parameters:[/bold]{tool_call['function']['arguments']}[/bright_black]" + f"[bold]Called tool '{tool_call['function']['name']}' with parameters:[/bold] {tool_call['function']['arguments']}", + style="dim", ) elif message["role"] == "tool": console.print( - f"[bright_black][bold]'{message['name']}' tool returned:[/bold]{message['content']}[/bright_black]" + f"[bold]'{message['name']}' tool returned:[/bold] {message['content']}", style="dim" ) diff --git a/arcade/arcade/cli/main.py b/arcade/arcade/cli/main.py index 6217e80c..2e1194dd 100644 --- a/arcade/arcade/cli/main.py +++ b/arcade/arcade/cli/main.py @@ -76,8 +76,13 @@ def login( callback_uri = "http://localhost:9905/callback" params = urlencode({"callback_uri": callback_uri, "state": state}) login_url = f"https://{host}/api/v1/auth/cli_login?{params}" + console.print("Opening a browser to log you in...") - webbrowser.open(login_url) + if not webbrowser.open(login_url): + console.print( + f"If a browser doesn't open automatically, copy this URL and paste it into your browser: {login_url}", + style="dim", + ) # Wait for the server thread to finish server_thread.join() @@ -230,7 +235,6 @@ def chat( client = Arcade(api_key=config.api.key, base_url=config.engine_url) user_email = config.user.email if config.user else None - user_attribution = f"({user_email})" if user_email else "" try: # start messages conversation @@ -245,7 +249,7 @@ def chat( log_engine_health(client) while True: - console.print(f"\n[magenta][bold]User[/bold] {user_attribution}:[/magenta] ") + console.print(f"\n[magenta][bold]User[/bold] ({user_email}):[/magenta] ") # Use input() instead of console.input() to leverage readline history user_input = input() @@ -331,7 +335,8 @@ def config( console.print("✅ Configuration updated successfully.", style="bold green") else: console.print( - f"❌ Invalid configuration name: {name} in section: {section}", style="bold red" + f"❌ Invalid configuration name: {name} in section: {section}", + style="bold red", ) raise typer.Exit(code=1) else: @@ -350,7 +355,10 @@ def evals( help="Maximum number of concurrent evaluations (default: 1)", ), models: str = typer.Option( - "gpt-4o", "--models", "-m", help="The models to use for evaluation (default: gpt-4o)" + "gpt-4o", + "--models", + "-m", + help="The models to use for evaluation (default: gpt-4o)", ), host: str = typer.Option( None, @@ -409,7 +417,8 @@ def evals( if show_details: suite_label = "suite" if len(eval_suites) == 1 else "suites" console.print( - f"\nFound {len(eval_suites)} {suite_label} in the evaluation files.", style="bold" + f"\nFound {len(eval_suites)} {suite_label} in the evaluation files.", + style="bold", ) async def run_evaluations() -> None: @@ -466,7 +475,9 @@ def dev( @cli.command(help="Start a local Arcade Actor server", rich_help_panel="Launch", hidden=True) def actorup( host: str = typer.Option( - "127.0.0.1", help="Host for the app, from settings by default.", show_default=True + "127.0.0.1", + help="Host for the app, from settings by default.", + show_default=True, ), port: int = typer.Option( "8002", "-p", "--port", help="Port for the app, defaults to ", show_default=True diff --git a/arcade/arcade/cli/utils.py b/arcade/arcade/cli/utils.py index d78b3beb..f8a4c004 100644 --- a/arcade/arcade/cli/utils.py +++ b/arcade/arcade/cli/utils.py @@ -127,7 +127,7 @@ def handle_streaming_content(stream: Stream[ChatCompletionChunk], model: str) -> if role == "": role = choice.delta.role or "" if role == "assistant": - console.print(f"\n[bold blue]Assistant ({model}):[/bold blue] ") + console.print(f"\n[blue][bold]Assistant[/bold] ({model}):[/blue] ") if chunk_message: full_message += chunk_message markdown_chunk = Markdown(full_message) @@ -292,10 +292,10 @@ def handle_chat_interaction( if role == "assistant": message_content = markdownify_urls(message_content) console.print( - f"\n[bold blue]Assistant ({model}):[/bold blue] ", Markdown(message_content) + f"\n[blue][bold]Assistant[/bold] ({model}):[/blue] ", Markdown(message_content) ) else: - console.print(f"\n[bold magenta]{role}:[/bold magenta] {message_content}") + console.print(f"\n[bold]{role}:[/bold] {message_content}") history += tool_messages history.append({"role": role, "content": message_content})