forked from volcengine/veadk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_init.py
More file actions
202 lines (164 loc) · 7.07 KB
/
cli_init.py
File metadata and controls
202 lines (164 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings
from typing import Any
import click
from veadk.version import VERSION
warnings.filterwarnings(
"ignore", category=UserWarning, module="pydantic._internal._fields"
)
def _render_prompts() -> dict[str, Any]:
"""Render interactive prompts to collect user configuration for project initialization.
This function prompts the user for various configuration options including
Volcengine FaaS application name, API Gateway settings, and deployment mode.
Returns:
dict[str, Any]: A dictionary containing all the collected configuration values
"""
vefaas_application_name = click.prompt(
"Volcengine FaaS application name", default="veadk-cloud-agent"
)
veapig_instance_name = click.prompt(
"Volcengine API Gateway instance name", default="", show_default=True
)
veapig_service_name = click.prompt(
"Volcengine API Gateway service name", default="", show_default=True
)
veapig_upstream_name = click.prompt(
"Volcengine API Gateway upstream name", default="", show_default=True
)
deploy_mode_options = {
"1": "A2A/MCP Server",
"2": "VeADK Web / Google ADK Web",
}
click.echo("Choose a deploy mode:")
for key, value in deploy_mode_options.items():
click.echo(f" {key}. {value}")
deploy_mode = click.prompt(
"Enter your choice", type=click.Choice(deploy_mode_options.keys())
)
use_adk_web = deploy_mode == "2"
auth_method_options = {
"1": "None",
"2": "API key",
"3": "OAuth2",
}
auth_methods = {
"1": "none",
"2": "api-key",
"3": "oauth2",
}
click.echo("Choose an authentication method:")
for key, value in auth_method_options.items():
click.echo(f" {key}. {value}")
auth_method_idx = click.prompt(
"Enter your choice", type=click.Choice(auth_method_options.keys())
)
auth_method = auth_methods[auth_method_idx]
veidentity_user_pool_name = ""
veidentity_client_name = ""
if auth_method == "oauth2":
veidentity_user_pool_name = click.prompt(
"Volcengine Identity user pool name", default="", show_default=True
)
if use_adk_web:
veidentity_client_name = click.prompt(
"Volcengine Identity client name", default="", show_default=True
)
return {
"vefaas_application_name": vefaas_application_name,
"veapig_instance_name": veapig_instance_name,
"veapig_service_name": veapig_service_name,
"veapig_upstream_name": veapig_upstream_name,
"use_adk_web": use_adk_web,
"auth_method": auth_method,
"veidentity_user_pool_name": veidentity_user_pool_name,
"veidentity_client_name": veidentity_client_name,
"veadk_version": VERSION,
}
@click.command()
@click.option(
"--vefaas-template-type", default="template", help="Expected template type"
)
def init(
vefaas_template_type: str,
) -> None:
"""Initialize a new VeADK project that can be deployed to Volcengine FaaS.
This command creates a new VeADK project from predefined templates using an interactive
setup process. It generates a complete project structure with all necessary files,
configurations, and deployment scripts ready for Volcengine cloud deployment.
The initialization process includes:
1. Interactive prompts for collecting deployment configuration
2. Template selection based on the specified template type
3. Project directory creation with proper structure
4. Configuration file generation with user preferences
5. Ready-to-use deployment scripts and source code structure
Available template types:
- 'template' (default): Creates an A2A/MCP/Web server template with a weather-reporter
example application. Suitable for most agent development scenarios.
- 'web_template': Creates a web application template with a simple-blog example.
Designed for web-based agent applications with UI components.
The generated project structure includes:
- src/ directory containing agent source code
- deploy.py script for cloud deployment
- Configuration files for various deployment scenarios
- Example implementations based on the selected template
Args:
vefaas_template_type: The type of template to use for project initialization.
Defaults to 'template'. Valid options are:
- 'template': Standard agent template (weather-reporter example)
- 'web_template': Web application template (simple-blog example)
Note:
- If the target directory already exists, you will be prompted to confirm overwrite
- The generated project includes example code that can be modified for your use case
- All deployment configurations can be customized after project creation
- The deploy.py script provides automated deployment to Volcengine FaaS platform
"""
import shutil
from pathlib import Path
from cookiecutter.main import cookiecutter
import veadk.integrations.ve_faas as vefaas
if vefaas_template_type == "web_template":
click.echo(
"Welcome use VeADK to create your project. We will generate a `simple-blog` web application for you."
)
else:
click.echo(
"Welcome use VeADK to create your project. We will generate a `weather-reporter` application for you."
)
cwd = Path.cwd()
local_dir_name = click.prompt("Local directory name", default="veadk-cloud-proj")
target_dir_path = cwd / local_dir_name
if target_dir_path.exists():
click.confirm(
f"Directory '{target_dir_path}' already exists, do you want to overwrite it",
abort=True,
)
shutil.rmtree(target_dir_path)
settings = _render_prompts()
settings["local_dir_name"] = local_dir_name
if not vefaas_template_type:
vefaas_template_type = "template"
template_dir_path = Path(vefaas.__file__).parent / vefaas_template_type
cookiecutter(
template=str(template_dir_path),
output_dir=str(cwd),
extra_context=settings,
no_input=True,
)
click.echo(f"Template project has been generated at {target_dir_path}")
click.echo(f"Edit {target_dir_path / 'src/'} to define your agents")
click.echo(
f"Edit {target_dir_path / 'deploy.py'} to define your deployment attributes"
)
click.echo("Run python `deploy.py` for deployment on Volcengine FaaS platform.")