8000 chore:Extract common options for `adk web` and `adk api_server`. · google/adk-python@01965bd · GitHub
[go: up one dir, main page]

Skip to content

Commit 01965bd

Browse files
DeanChensjcopybara-github
authored andcommitted
chore:Extract common options for adk web and adk api_server.
PiperOrigin-RevId: 765326316
1 parent ccd05e0 commit 01965bd

File tree

1 file changed

+62
-98
lines changed

1 file changed

+62
-98
lines changed

src/google/adk/cli/cli_tools_click.py

Lines changed: 62 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import collections
1919
from contextlib import asynccontextmanager
2020
from datetime import datetime
21+
import functools
2122
import logging
2223
import os
2324
import tempfile
@@ -416,57 +417,69 @@ async def _collect_eval_results() -> list[EvalCaseResult]:
416417
print(eval_result.model_dump_json(indent=2))
417418

418419

419-
@main.command("web")
420-
@click.option(
421-
"--session_db_url",
422-
help=(
423-
"""Optional. The database URL to store the session.
420+
def fast_api_common_options():
421+
"""Decorator to add common fast api options to click commands."""
424422

425-
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
423+
def decorator(func):
424+
@click.option(
425+
"--session_db_url",
426+
help=(
427+
"""Optional. The database URL to store the session.
428+
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
429+
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
430+
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
431+
),
432+
)
433+
@click.option(
434+
"--host",
435+
type=str,
436+
help="Optional. The binding host of the server",
437+
default="127.0.0.1",
438+
show_default=True,
439+
)
440+
@click.option(
441+
"--port",
442+
type=int,
443+
help="Optional. The port of the server",
444+
default=8000,
445+
)
446+
@click.option(
447+
"--allow_origins",
448+
help="Optional. Any additional origins to allow for CORS.",
449+
multiple=True,
450+
)
451+
@click.option(
452+
"--log_level",
453+
type=click.Choice(
454+
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
455+
case_sensitive=False,
456+
),
457+
default="INFO",
458+
help="Optional. Set the logging level",
459+
)
460+
@click.option(
461+
"--trace_to_cloud",
462+
is_flag=True,
463+
show_default=True,
464+
default=False,
465+
help="Optional. Whether to enable cloud trace for telemetry.",
466+
)
467+
@click.option(
468+
"--reload/--no-reload",
469+
default=True,
470+
help="Optional. Whether to enable auto reload for server.",
471+
)
472+
@functools.wraps(func)
473+
def wrapper(*args, **kwargs):
474+
return func(*args, **kwargs)
426475

427-
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
476+
return wrapper
428477

429-
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
430-
),
431-
)
432-
@click.option(
433-
"--host",
434-
type=str,
435-
help="Optional. The binding host of the server",
436-
default="127.0.0.1",
437-
show_default=True,
438-
)
439-
@click.option(
440-
"--port",
441-
type=int,
442-
help="Optional. The port of the server",
443-
default=8000,
444-
)
445-
@click.option(
446-
"--allow_origins",
447-
help="Optional. Any additional origins to allow for CORS.",
448-
multiple=True,
449-
)
450-
@click.option(
451-
"--log_level",
452-
type=click.Choice(
453-
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], case_sensitive=False
454-
),
455-
default="INFO",
456-
help="Optional. Set the logging level",
457-
)
458-
@click.option(
459-
"--trace_to_cloud",
460-
is_flag=True,
461-
show_default=True,
462-
default=False,
463-
help="Optional. Whether to enable cloud trace for telemetry.",
464-
)
465-
@click.option(
466-
"--reload/--no-reload",
467-
default=True,
468-
help="Optional. Whether to enable auto reload for server.",
469-
)
478+
return decorator
479+
480+
481+
@main.command("web")
482+
@fast_api_common_options()
470483
@click.argument(
471484
"agents_dir",
472485
type=click.Path(
@@ -537,56 +550,6 @@ async def _lifespan(app: FastAPI):
537550

538551

539552
@main.command("api_server")
540-
@click.option(
541-
"--session_db_url",
542-
help=(
543-
"""Optional. The database URL to store the session.
544-
545-
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
546-
547-
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
548-
549-
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
550-
),
551-
)
552-
@click.option(
553-
"--host",
554-
type=str,
555-
help="Optional. The binding host of the server",
556-
default="127.0.0.1",
557-
show_default=True,
558-
)
559-
@click.option(
560-
"--port",
561-
type=int,
562-
help="Optional. The port of the server",
563-
default=8000,
564-
)
565-
@click.option(
566-
"--allow_origins",
567-
help="Optional. Any additional origins to allow for CORS.",
568-
multiple=True,
569-
)
570-
@click.option(
571-
"--log_level",
572-
type=click.Choice(
573-
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], case_sensitive=False
574-
),
575-
default="INFO",
576-
help="Optional. Set the logging level",
577-
)
578-
@click.option(
579-
"--trace_to_cloud",
580-
is_flag=True,
581-
show_default=True,
582-
default=False,
583-
help="Optional. Whether to enable cloud trace for telemetry.",
584-
)
585-
@click.option(
586-
"--reload/--no-reload",
587-
default=True,
588-
help="Optional. Whether to enable auto reload for server.",
589-
)
590553
# The directory of agents, where each sub-directory is a single agent.
591554
# By default, it is the current working directory
592555
@click.argument(
@@ -596,6 +559,7 @@ async def _lifespan(app: FastAPI):
596559
),
597560
default=os.getcwd(),
598561
)
562+
@fast_api_common_options()
599563
def cli_api_server(
600564
agents_dir: str,
601565
session_db_url: str = "",

0 commit comments

Comments
 (0)
0