39
39
from .utils import envs
40
40
from .utils import logs
41
41
42
+ LOG_LEVELS = click .Choice (
43
+ ["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ],
44
+ case_sensitive = False ,
45
+ )
46
+
42
47
43
48
class HelpfulCommand (click .Command ):
44
49
"""Command that shows full help on error instead of just the error message.
@@ -498,13 +503,6 @@ def fast_api_common_options():
498
503
"""Decorator to add common fast api options to click commands."""
499
504
500
505
def decorator (func ):
501
- @click .option (
502
- "--host" ,
503
- type = str ,
504
- help = "Optional. The binding host of the server" ,
505
- default = "127.0.0.1" ,
506
- show_default = True ,
507
- )
508
506
@click .option (
509
507
"--port" ,
510
508
type = int ,
@@ -518,10 +516,7 @@ def decorator(func):
518
516
)
519
517
@click .option (
520
518
"--log_level" ,
521
- type = click .Choice (
522
- ["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ],
523
- case_sensitive = False ,
524
- ),
519
+ type = LOG_LEVELS ,
525
520
default = "INFO" ,
526
521
help = "Optional. Set the logging level" ,
527
522
)
@@ -535,7 +530,10 @@ def decorator(func):
535
530
@click .option (
536
531
"--reload/--no-reload" ,
537
532
default = True ,
538
- help = "Optional. Whether to enable auto reload for server." ,
533
+ help = (
534
+ "Optional. Whether to enable auto reload for server. Not supported"
535
+ " for Cloud Run."
536
+ ),
539
537
)
540
538
@functools .wraps (func )
541
539
def wrapper (* args , ** kwargs ):
@@ -547,6 +545,13 @@ def wrapper(*args, **kwargs):
547
545
548
546
549
547
@main .command ("web" )
548
+ @click .option (
549
+ "--host" ,
550
+ type = str ,
551
+ help = "Optional. The binding host of the server" ,
552
+ default = "127.0.0.1" ,
553
+ show_default = True ,
554
+ )
550
555
@fast_api_common_options ()
551
556
@adk_services_options ()
552
557
@deprecated_adk_services_options ()
@@ -578,7 +583,7 @@ def cli_web(
578
583
579
584
Example:
580
585
581
- adk web --session_service_uri=[uri] -- port=[port] path/to/agents_dir
586
+ adk web --port=[port] path/to/agents_dir
582
587
"""
583
588
logs .setup_adk_logger (getattr (logging , log_level .upper ()))
584
589
@@ -628,6 +633,16 @@ async def _lifespan(app: FastAPI):
628
633
629
634
630
635
@main .command ("api_server" )
636
+ @click .option (
637
+ "--host" ,
638
+ type = str ,
639
+ help = "Optional. The binding host of the server" ,
640
+ default = "127.0.0.1" ,
641
+ show_default = True ,
642
+ )
643
+ @fast_api_common_options ()
644
+ @adk_services_options ()
645
+ @deprecated_adk_services_options ()
631
646
# The directory of agents, where each sub-directory is a single agent.
632
647
# By default, it is the current working directory
633
648
@click .argument (
@@ -637,9 +652,6 @@ async def _lifespan(app: FastAPI):
637
652
),
638
653
default = os .getcwd (),
639
654
)
640
- @fast_api_common_options ()
641
- @adk_services_options ()
642
- @deprecated_adk_services_options ()
643
655
def cli_api_server (
644
656
agents_dir : str ,
645
657
log_level : str = "INFO" ,
@@ -661,7 +673,7 @@ def cli_api_server(
661
673
662
674
Example:
663
675
664
- adk api_server --session_service_uri=[uri] -- port=[port] path/to/agents_dir
676
+ adk api_server --port=[port] path/to/agents_dir
665
677
"""
666
678
logs .setup_adk_logger (getattr (logging , log_level .upper ()))
667
679
@@ -720,19 +732,7 @@ def cli_api_server(
720
732
" of the AGENT source code)."
721
733
),
722
734
)
723
- @click .option (
724
- "--port" ,
725
- type = int ,
726
- default = 8000 ,
727
- help = "Optional. The port of the ADK API server (default: 8000)." ,
728
- )
729
- @click .option (
730
- "--trace_to_cloud" ,
731
- is_flag = True ,
732
- show_default = True ,
733
- default = False ,
734
- help = "Optional. Whether to enable Cloud Trace for cloud run." ,
735
- )
735
+ @fast_api_common_options ()
736
736
@click .option (
737
737
"--with_ui" ,
738
738
is_flag = True ,
@@ -743,6 +743,11 @@ def cli_api_server(
743
743
" only)"
744
744
),
745
745
)
746
+ @click .option (
747
+ "--verbosity" ,
748
+ type = LOG_LEVELS ,
749
+ help = "Deprecated. Use --log_level instead." ,
750
+ )
746
751
@click .option (
747
752
"--temp_folder" ,
748
753
type = str ,
@@ -756,20 +761,6 @@ def cli_api_server(
756
761
" (default: a timestamped folder in the system temp directory)."
757
762
),
758
763
)
759
- @click .option (
760
- "--verbosity" ,
761
- type = click .Choice (
762
- ["debug" , "info" , "warning" , "error" , "critical" ], case_sensitive = False
763
- ),
764
- default = "WARNING" ,
765
- help = "Optional. Override the default verbosity level." ,
766
- )
767
- @click .argument (
768
- "agent" ,
769
- type = click .Path (
770
- exists = True , dir_okay = True , file_okay = False , resolve_path = True
771
- ),
772
- )
773
764
@click .option (
774
765
"--adk_version" ,
775
766
type = str ,
@@ -782,6 +773,12 @@ def cli_api_server(
782
773
)
783
774
@adk_services_options ()
784
775
@deprecated_adk_services_options ()
776
+ @click .argument (
777
+ "agent" ,
778
+ type = click .Path (
779
+ exists = True , dir_okay = True , file_okay = False , resolve_path = True
780
+ ),
781
+ )
785
782
def cli_deploy_cloud_run (
786
783
agent : str ,
787
784
project : Optional [str ],
@@ -792,8 +789,11 @@ def cli_deploy_cloud_run(
792
789
port : int ,
793
790
trace_to_cloud : bool ,
794
791
with_ui : bool ,
795
- verbosity : str ,
796
792
adk_version : str ,
793
+ log_level : Optional [str ] = None ,
794
+ verbosity : str = "WARNING" ,
795
+ reload : bool = True ,
796
+ allow_origins : Optional [list [str ]] = None ,
797
797
session_service_uri : Optional [str ] = None ,
798
798
artifact_service_uri : Optional [str ] = None ,
799
799
memory_service_uri : Optional [str ] = None ,
@@ -808,6 +808,7 @@ def cli_deploy_cloud_run(
808
808
809
809
adk deploy cloud_run --project=[project] --region=[region] path/to/my_agent
810
810
"""
811
+ log_level = log_level or verbosity
811
812
session_service_uri = session_service_uri or session_db_url
812
813
artifact_service_uri = artifact_service_uri or artifact_storage_uri
813
814
try :
@@ -820,7 +821,9 @@ def cli_deploy_cloud_run(
820
821
temp_folder = temp_folder ,
821
822
port = port ,
822
823
trace_to_cloud = trace_to_cloud ,
824
+ allow_origins = allow_origins ,
823
825
with_ui = with_ui ,
826
+ log_level = log_level ,
824
827
verbosity = verbosity ,
825
828
adk_version = adk_version ,
826
829
session_service_uri = session_service_uri ,
0 commit comments