|
| 1 | +# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import warnings |
| 16 | +from typing import Any |
| 17 | + |
| 18 | +import click |
| 19 | + |
| 20 | +from veadk.version import VERSION |
| 21 | + |
| 22 | +warnings.filterwarnings( |
| 23 | + "ignore", category=UserWarning, module="pydantic._internal._fields" |
| 24 | +) |
| 25 | + |
| 26 | + |
| 27 | +def _render_prompts() -> dict[str, Any]: |
| 28 | + vefaas_application_name = click.prompt( |
| 29 | + "Volcengine FaaS application name", default="veadk-cloud-agent" |
| 30 | + ) |
| 31 | + |
| 32 | + veapig_instance_name = click.prompt( |
| 33 | + "Volcengine API Gateway instance name", default="", show_default=True |
| 34 | + ) |
| 35 | + |
| 36 | + veapig_service_name = click.prompt( |
| 37 | + "Volcengine API Gateway service name", default="", show_default=True |
| 38 | + ) |
| 39 | + |
| 40 | + veapig_upstream_name = click.prompt( |
| 41 | + "Volcengine API Gateway upstream name", default="", show_default=True |
| 42 | + ) |
| 43 | + |
| 44 | + deploy_mode_options = { |
| 45 | + "1": "A2A/MCP Server", |
| 46 | + "2": "VeADK Web / Google ADK Web", |
| 47 | + } |
| 48 | + |
| 49 | + click.echo("Choose a deploy mode:") |
| 50 | + for key, value in deploy_mode_options.items(): |
| 51 | + click.echo(f" {key}. {value}") |
| 52 | + |
| 53 | + deploy_mode = click.prompt( |
| 54 | + "Enter your choice", type=click.Choice(deploy_mode_options.keys()) |
| 55 | + ) |
| 56 | + |
| 57 | + return { |
| 58 | + "vefaas_application_name": vefaas_application_name, |
| 59 | + "veapig_instance_name": veapig_instance_name, |
| 60 | + "veapig_service_name": veapig_service_name, |
| 61 | + "veapig_upstream_name": veapig_upstream_name, |
| 62 | + "use_adk_web": deploy_mode == "2", |
| 63 | + "veadk_version": VERSION, |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | +@click.command() |
| 68 | +@click.option( |
| 69 | + "--vefaas-template-type", default="template", help="Expected template type" |
| 70 | +) |
| 71 | +def blog( |
| 72 | + vefaas_template_type: str, |
| 73 | +) -> None: |
| 74 | + """Init a veadk project that can be deployed to Volcengine VeFaaS. |
| 75 | +
|
| 76 | + `template` is A2A/MCP/Web server template, `web_template` is for web applications (i.e., a simple blog). |
| 77 | + """ |
| 78 | + import shutil |
| 79 | + from pathlib import Path |
| 80 | + |
| 81 | + from cookiecutter.main import cookiecutter |
| 82 | + |
| 83 | + import veadk.integrations.ve_faas as vefaas |
| 84 | + |
| 85 | + if vefaas_template_type == "web_template": |
| 86 | + click.echo( |
| 87 | + "Welcome use VeADK to create your project. We will generate a `simple-blog` web application for you." |
| 88 | + ) |
| 89 | + else: |
| 90 | + click.echo( |
| 91 | + "Welcome use VeADK to create your project. We will generate a `weather-reporter` application for you." |
| 92 | + ) |
| 93 | + |
| 94 | + cwd = Path.cwd() |
| 95 | + local_dir_name = click.prompt("Local directory name", default="veadk-cloud-proj") |
| 96 | + target_dir_path = cwd / local_dir_name |
| 97 | + |
| 98 | + if target_dir_path.exists(): |
| 99 | + click.confirm( |
| 100 | + f"Directory '{target_dir_path}' already exists, do you want to overwrite it", |
| 101 | + abort=True, |
| 102 | + ) |
| 103 | + shutil.rmtree(target_dir_path) |
| 104 | + |
| 105 | + settings = _render_prompts() |
| 106 | + settings["local_dir_name"] = local_dir_name |
| 107 | + |
| 108 | + if not vefaas_template_type: |
| 109 | + vefaas_template_type = "template" |
| 110 | + |
| 111 | + template_dir_path = Path(vefaas.__file__).parent / vefaas_template_type |
| 112 | + |
| 113 | + cookiecutter( |
| 114 | + template=str(template_dir_path), |
| 115 | + output_dir=str(cwd), |
| 116 | + extra_context=settings, |
| 117 | + no_input=True, |
| 118 | + ) |
| 119 | + |
| 120 | + click.echo(f"Template project has been generated at {target_dir_path}") |
| 121 | + click.echo(f"Edit {target_dir_path / 'src/'} to define your agents") |
| 122 | + click.echo( |
| 123 | + f"Edit {target_dir_path / 'deploy.py'} to define your deployment attributes" |
| 124 | + ) |
| 125 | + click.echo("Run python `deploy.py` for deployment on Volcengine FaaS platform.") |
0 commit comments