mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-16 04:02:55 -06:00
chore:Extract common options for adk web
and adk api_server
.
PiperOrigin-RevId: 765326316
This commit is contained in:
parent
ccd05e0b00
commit
01965bdd74
@ -18,6 +18,7 @@ import asyncio
|
|||||||
import collections
|
import collections
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -416,57 +417,69 @@ def cli_eval(
|
|||||||
print(eval_result.model_dump_json(indent=2))
|
print(eval_result.model_dump_json(indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
def fast_api_common_options():
|
||||||
|
"""Decorator to add common fast api options to click commands."""
|
||||||
|
|
||||||
|
def decorator(func):
|
||||||
|
@click.option(
|
||||||
|
"--session_db_url",
|
||||||
|
help=(
|
||||||
|
"""Optional. The database URL to store the session.
|
||||||
|
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
|
||||||
|
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
|
||||||
|
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
|
||||||
|
),
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--host",
|
||||||
|
type=str,
|
||||||
|
help="Optional. The binding host of the server",
|
||||||
|
default="127.0.0.1",
|
||||||
|
show_default=True,
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--port",
|
||||||
|
type=int,
|
||||||
|
help="Optional. The port of the server",
|
||||||
|
default=8000,
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--allow_origins",
|
||||||
|
help="Optional. Any additional origins to allow for CORS.",
|
||||||
|
multiple=True,
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--log_level",
|
||||||
|
type=click.Choice(
|
||||||
|
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
||||||
|
case_sensitive=False,
|
||||||
|
),
|
||||||
|
default="INFO",
|
||||||
|
help="Optional. Set the logging level",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--trace_to_cloud",
|
||||||
|
is_flag=True,
|
||||||
|
show_default=True,
|
||||||
|
default=False,
|
||||||
|
help="Optional. Whether to enable cloud trace for telemetry.",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--reload/--no-reload",
|
||||||
|
default=True,
|
||||||
|
help="Optional. Whether to enable auto reload for server.",
|
||||||
|
)
|
||||||
|
@functools.wraps(func)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
@main.command("web")
|
@main.command("web")
|
||||||
@click.option(
|
@fast_api_common_options()
|
||||||
"--session_db_url",
|
|
||||||
help=(
|
|
||||||
"""Optional. The database URL to store the session.
|
|
||||||
|
|
||||||
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
|
|
||||||
|
|
||||||
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
|
|
||||||
|
|
||||||
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
|
|
||||||
),
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--host",
|
|
||||||
type=str,
|
|
||||||
help="Optional. The binding host of the server",
|
|
||||||
default="127.0.0.1",
|
|
||||||
show_default=True,
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--port",
|
|
||||||
type=int,
|
|
||||||
help="Optional. The port of the server",
|
|
||||||
default=8000,
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--allow_origins",
|
|
||||||
help="Optional. Any additional origins to allow for CORS.",
|
|
||||||
multiple=True,
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--log_level",
|
|
||||||
type=click.Choice(
|
|
||||||
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], case_sensitive=False
|
|
||||||
),
|
|
||||||
default="INFO",
|
|
||||||
help="Optional. Set the logging level",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--trace_to_cloud",
|
|
||||||
is_flag=True,
|
|
||||||
show_default=True,
|
|
||||||
default=False,
|
|
||||||
help="Optional. Whether to enable cloud trace for telemetry.",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--reload/--no-reload",
|
|
||||||
default=True,
|
|
||||||
help="Optional. Whether to enable auto reload for server.",
|
|
||||||
)
|
|
||||||
@click.argument(
|
@click.argument(
|
||||||
"agents_dir",
|
"agents_dir",
|
||||||
type=click.Path(
|
type=click.Path(
|
||||||
@ -537,56 +550,6 @@ def cli_web(
|
|||||||
|
|
||||||
|
|
||||||
@main.command("api_server")
|
@main.command("api_server")
|
||||||
@click.option(
|
|
||||||
"--session_db_url",
|
|
||||||
help=(
|
|
||||||
"""Optional. The database URL to store the session.
|
|
||||||
|
|
||||||
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
|
|
||||||
|
|
||||||
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
|
|
||||||
|
|
||||||
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
|
|
||||||
),
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--host",
|
|
||||||
type=str,
|
|
||||||
help="Optional. The binding host of the server",
|
|
||||||
default="127.0.0.1",
|
|
||||||
show_default=True,
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--port",
|
|
||||||
type=int,
|
|
||||||
help="Optional. The port of the server",
|
|
||||||
default=8000,
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--allow_origins",
|
|
||||||
help="Optional. Any additional origins to allow for CORS.",
|
|
||||||
multiple=True,
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--log_level",
|
|
||||||
type=click.Choice(
|
|
||||||
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], case_sensitive=False
|
|
||||||
),
|
|
||||||
default="INFO",
|
|
||||||
help="Optional. Set the logging level",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--trace_to_cloud",
|
|
||||||
is_flag=True,
|
|
||||||
show_default=True,
|
|
||||||
default=False,
|
|
||||||
help="Optional. Whether to enable cloud trace for telemetry.",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--reload/--no-reload",
|
|
||||||
default=True,
|
|
||||||
help="Optional. Whether to enable auto reload for server.",
|
|
||||||
)
|
|
||||||
# The directory of agents, where each sub-directory is a single agent.
|
# The directory of agents, where each sub-directory is a single agent.
|
||||||
# By default, it is the current working directory
|
# By default, it is the current working directory
|
||||||
@click.argument(
|
@click.argument(
|
||||||
@ -596,6 +559,7 @@ def cli_web(
|
|||||||
),
|
),
|
||||||
default=os.getcwd(),
|
default=os.getcwd(),
|
||||||
)
|
)
|
||||||
|
@fast_api_common_options()
|
||||||
def cli_api_server(
|
def cli_api_server(
|
||||||
agents_dir: str,
|
agents_dir: str,
|
||||||
session_db_url: str = "",
|
session_db_url: str = "",
|
||||||
|
Loading…
Reference in New Issue
Block a user