@@ -40,71 +40,54 @@ def model_post_init(self, context: Any, /) -> None:
4040 )
4141
4242 def _prepare (self , path : str , name : str ):
43- # VeFaaS path check
44- if "_" in name :
45- raise ValueError (
46- f"Invalid Volcengine FaaS function name `{ name } `, please use lowercase letters and numbers, or replace it with a `-` char."
47- )
48-
49- # project path check
43+ # basic check
5044 assert os .path .exists (path ), f"Local agent project path `{ path } ` not exists."
5145 assert os .path .isdir (path ), (
5246 f"Local agent project path `{ path } ` is not a directory."
5347 )
5448
55- assert os .path .exists (os .path .join (path , "agent.py" )), (
56- f"Local agent project path `{ path } ` does not contain `agent.py` file. Please prepare it according to veadk-python/cloud/template/agent.py.example"
57- )
58-
59- if os .path .exists (os .path .join (path , "app.py" )):
60- logger .warning (
61- f"Local agent project path `{ path } ` contains an `app.py` file. Use your own `app.py` file may cause unexpected behavior."
62- )
63- else :
64- logger .info (
65- f"No `app.py` detected in local agent project path `{ path } `. Prepare it."
66- )
67- template_app_py = (
68- f"{ Path (__file__ ).resolve ().parent .resolve ()} /template/app.py"
69- )
70- import shutil
71-
72- shutil .copy (template_app_py , os .path .join (path , "app.py" ))
73-
74- if os .path .exists (os .path .join (path , "studio_app.py" )):
75- logger .warning (
76- f"Local agent project path `{ path } ` contains an `studio_app.py` file. Use your own `studio_app.py` file may cause unexpected behavior."
77- )
78- else :
79- logger .info (
80- f"No `studio_app.py` detected in local agent project path `{ path } `. Prepare it."
81- )
82- template_studio_app_py = (
83- f"{ Path (__file__ ).resolve ().parent .resolve ()} /template/studio_app.py"
49+ # VeFaaS application/function name check
50+ if "_" in name :
51+ raise ValueError (
52+ f"Invalid Volcengine FaaS function name `{ name } `, please use lowercase letters and numbers, or replace it with a `-` char."
8453 )
85- import shutil
8654
87- shutil .copy (template_studio_app_py , os .path .join (path , "studio_app.py" ))
55+ # project structure check
56+ assert os .path .exists (os .path .join (path , "agent.py" )), (
57+ f"Local agent project path `{ path } ` does not contain `agent.py` file. Please prepare it according to our document https://volcengine.github.io/veadk-python/deploy.html"
58+ )
8859
89- if os .path .exists (os .path .join (path , "run.sh " )):
60+ if not os .path .exists (os .path .join (path , "config.yaml " )):
9061 logger .warning (
91- f"Local agent project path `{ path } ` contains a `run.sh` file. Use your own `run.sh` file may cause unexpected behavior."
92- )
93- else :
94- logger .info (
95- f"No `run.sh` detected in local agent project path `{ path } `. Prepare it."
96- )
97- template_run_sh = (
98- f"{ Path (__file__ ).resolve ().parent .resolve ()} /template/run.sh"
62+ f"Local agent project path `{ path } ` does not contain `config.yaml` file. Some important config items may not be set."
9963 )
100- import shutil
10164
102- shutil .copy (template_run_sh , os .path .join (path , "run.sh" ))
65+ # prepare template files if not have
66+ template_files = [
67+ "app.py" ,
68+ "studio_app.py" ,
69+ "run.sh" ,
70+ "requirements.txt" ,
71+ "__init__.py" ,
72+ ]
73+ for template_file in template_files :
74+ if os .path .exists (os .path .join (path , template_file )):
75+ logger .warning (
76+ f"Local agent project path `{ path } ` contains a `{ template_file } ` file. Use your own `{ template_file } ` file may cause unexpected behavior."
77+ )
78+ else :
79+ logger .info (
80+ f"No `{ template_file } ` detected in local agent project path `{ path } `. Prepare it."
81+ )
82+ template_file_path = f"{ Path (__file__ ).resolve ().parent .resolve ().parent .resolve ()} /cli/services/vefaas/template/src/{ template_file } "
83+ import shutil
84+
85+ shutil .copy (template_file_path , os .path .join (path , template_file ))
10386
10487 def deploy (
10588 self ,
89+ application_name : str ,
10690 path : str ,
107- name : str ,
10891 gateway_name : str = "" ,
10992 gateway_service_name : str = "" ,
11093 gateway_upstream_name : str = "" ,
@@ -123,14 +106,13 @@ def deploy(
123106 assert not (use_studio and use_adk_web ), (
124107 "use_studio and use_adk_web can not be True at the same time."
125108 )
109+
126110 # prevent deepeval writing operations
127111 import veadk .config
128112
129113 veadk .config .veadk_environments ["DEEPEVAL_TELEMETRY_OPT_OUT" ] = "YES"
130114
131115 if use_studio :
132- import veadk .config
133-
134116 veadk .config .veadk_environments ["USE_STUDIO" ] = "True"
135117 else :
136118 import veadk .config
@@ -148,29 +130,29 @@ def deploy(
148130
149131 # convert `path` to absolute path
150132 path = str (Path (path ).resolve ())
151- self ._prepare (path , name )
133+ self ._prepare (path , application_name )
152134
153135 if not gateway_name :
154- gateway_name = f"{ name } -gw-{ formatted_timestamp ()} "
136+ gateway_name = f"{ application_name } -gw-{ formatted_timestamp ()} "
155137 if not gateway_service_name :
156- gateway_service_name = f"{ name } -gw-svr-{ formatted_timestamp ()} "
138+ gateway_service_name = f"{ application_name } -gw-svr-{ formatted_timestamp ()} "
157139 if not gateway_upstream_name :
158- gateway_upstream_name = f"{ name } -gw-us-{ formatted_timestamp ()} "
140+ gateway_upstream_name = f"{ application_name } -gw-us-{ formatted_timestamp ()} "
159141
160142 try :
161143 vefaas_application_url , app_id , function_id = self ._vefaas_service .deploy (
162144 path = path ,
163- name = name ,
145+ name = application_name ,
164146 gateway_name = gateway_name ,
165147 gateway_service_name = gateway_service_name ,
166148 gateway_upstream_name = gateway_upstream_name ,
167149 )
168150 _ = function_id # for future use
169151
170152 return CloudApp (
171- name = name ,
172- endpoint = vefaas_application_url ,
173- app_id = app_id ,
153+ vefaas_application_name = application_name ,
154+ vefaas_endpoint = vefaas_application_url ,
155+ vefaas_application_id = app_id ,
174156 )
175157 except Exception as e :
176158 raise ValueError (
0 commit comments