Skip to content

Commit 1ab8149

Browse files
authored
chore(docstring): update docstring (evaluation and cloud) (#268)
* update(docstring): update docstring (evaluation and cloud) * update(docstring): update docstring (evaluation and cloud)
1 parent 43239a4 commit 1ab8149

File tree

9 files changed

+914
-45
lines changed

9 files changed

+914
-45
lines changed

veadk/cloud/cloud_agent_engine.py

Lines changed: 138 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,77 @@
3131

3232

3333
class CloudAgentEngine(BaseModel):
34+
"""Manages cloud agent deployment and operations on Volcengine FaaS platform.
35+
36+
This class handles authentication with Volcengine, deploys local projects to FaaS,
37+
updates function code, removes applications, and supports local testing.
38+
39+
Attributes:
40+
volcengine_access_key (str): Access key for Volcengine authentication.
41+
Defaults to VOLCENGINE_ACCESS_KEY environment variable.
42+
volcengine_secret_key (str): Secret key for Volcengine authentication.
43+
Defaults to VOLCENGINE_SECRET_KEY environment variable.
44+
region (str): Region for Volcengine services. Defaults to "cn-beijing".
45+
_vefaas_service (VeFaaS): Internal VeFaaS client instance, initialized post-creation.
46+
47+
Note:
48+
Credentials must be set via environment variables for default behavior.
49+
This class performs interactive confirmations for destructive operations like removal.
50+
51+
Examples:
52+
```python
53+
from veadk.cloud.cloud_agent_engine import CloudAgentEngine
54+
engine = CloudAgentEngine()
55+
app = engine.deploy("test-app", "/path/to/local/project")
56+
print(app.vefaas_endpoint)
57+
```
58+
"""
59+
3460
volcengine_access_key: str = getenv("VOLCENGINE_ACCESS_KEY")
3561
volcengine_secret_key: str = getenv("VOLCENGINE_SECRET_KEY")
3662
region: str = "cn-beijing"
3763

3864
def model_post_init(self, context: Any, /) -> None:
65+
"""Initializes the internal VeFaaS service after Pydantic model validation.
66+
67+
Creates a VeFaaS instance using the configured access key, secret key, and region.
68+
69+
Args:
70+
self: The CloudAgentEngine instance.
71+
context: Pydantic post-init context parameter (not used).
72+
73+
Returns:
74+
None
75+
76+
Note:
77+
This is a Pydantic lifecycle method, ensuring service readiness after init.
78+
"""
3979
self._vefaas_service = VeFaaS(
4080
access_key=self.volcengine_access_key,
4181
secret_key=self.volcengine_secret_key,
4282
region=self.region,
4383
)
4484

4585
def _prepare(self, path: str, name: str):
86+
"""Prepares the local project for deployment by validating path and name.
87+
88+
Checks if the path exists and is a directory, validates application name format.
89+
90+
Args:
91+
path (str): Full or relative path to the local agent project directory.
92+
name (str): Intended VeFaaS application name.
93+
94+
Returns:
95+
None
96+
97+
Raises:
98+
AssertionError: If path does not exist or is not a directory.
99+
ValueError: If name contains invalid characters like underscores.
100+
101+
Note:
102+
Includes commented code for handling requirements.txt; not executed currently.
103+
Called internally by deploy and update methods.
104+
"""
46105
# basic check
47106
assert os.path.exists(path), f"Local agent project path `{path}` not exists."
48107
assert os.path.isdir(path), (
@@ -73,10 +132,23 @@ def _prepare(self, path: str, name: str):
73132
# )
74133

75134
def _try_launch_fastapi_server(self, path: str):
76-
"""Try to launch a fastapi server for tests according to user's configuration.
135+
"""Tries to start a FastAPI server locally for testing deployment readiness.
136+
137+
Runs the project's run.sh script and checks connectivity on port 8000.
77138
78139
Args:
79-
path (str): Local agent project path.
140+
path (str): Path to the local project containing run.sh.
141+
142+
Returns:
143+
None
144+
145+
Raises:
146+
RuntimeError: If server startup times out after 30 seconds.
147+
148+
Note:
149+
Sets _FAAS_FUNC_TIMEOUT environment to 900 seconds.
150+
Streams output to console and terminates process after successful check.
151+
Assumes run.sh launches server on 0.0.0.0:8000.
80152
"""
81153
RUN_SH = f"{path}/run.sh"
82154

@@ -128,19 +200,34 @@ def deploy(
128200
use_adk_web: bool = False,
129201
local_test: bool = False,
130202
) -> CloudApp:
131-
"""Deploy local agent project to Volcengine FaaS platform.
203+
"""Deploys a local agent project to Volcengine FaaS, creating necessary resources.
204+
205+
Prepares project, optionally tests locally, deploys via VeFaaS, and returns app instance.
132206
133207
Args:
134-
application_name (str): Expected VeFaaS application name.
135-
path (str): Local agent project path.
136-
gateway_name (str): Gateway name.
137-
gateway_service_name (str): Gateway service name.
138-
gateway_upstream_name (str): Gateway upstream name.
139-
use_adk_web (bool): Whether to use ADK Web.
140-
local_test (bool): Whether to run local test for FastAPI Server.
208+
application_name (str): Unique name for the VeFaaS application.
209+
path (str): Local directory path of the agent project.
210+
gateway_name (str, optional): Custom gateway resource name. Defaults to timestamped.
211+
gateway_service_name (str, optional): Custom service name. Defaults to timestamped.
212+
gateway_upstream_name (str, optional): Custom upstream name. Defaults to timestamped.
213+
use_adk_web (bool): Enable ADK Web configuration. Defaults to False.
214+
local_test (bool): Perform FastAPI server test before deploy. Defaults to False.
141215
142216
Returns:
143-
CloudApp: The deployed cloud application instance.
217+
CloudApp: Deployed application with endpoint, name, and ID.
218+
219+
Raises:
220+
ValueError: On deployment failure, such as invalid config or VeFaaS errors.
221+
222+
Note:
223+
Converts path to absolute; sets telemetry opt-out and ADK Web env vars.
224+
Generates default gateway names if not specified.
225+
226+
Examples:
227+
```python
228+
app = engine.deploy("my-agent", "./agent-project", local_test=True)
229+
print(f"Deployed at: {app.vefaas_endpoint}")
230+
```
144231
"""
145232
# prevent deepeval writing operations
146233
veadk_environments["DEEPEVAL_TELEMETRY_OPT_OUT"] = "YES"
@@ -185,6 +272,28 @@ def deploy(
185272
)
186273

187274
def remove(self, app_name: str):
275+
"""Deletes a deployed cloud application after user confirmation.
276+
277+
Locates app by name, confirms, and issues delete via VeFaaS.
278+
279+
Args:
280+
app_name (str): Name of the application to remove.
281+
282+
Returns:
283+
None
284+
285+
Raises:
286+
ValueError: If application not found by name.
287+
288+
Note:
289+
Interactive prompt required; cancels on non-'y' input.
290+
Deletion is processed asynchronously by VeFaaS.
291+
292+
Examples:
293+
```python
294+
engine.remove("my-agent")
295+
```
296+
"""
188297
confirm = input(f"Confirm delete cloud app {app_name}? (y/N): ")
189298
if confirm.lower() != "y":
190299
print("Delete cancelled.")
@@ -202,14 +311,28 @@ def update_function_code(
202311
application_name: str,
203312
path: str,
204313
) -> CloudApp:
205-
"""Update existing agent project code while keeping the same URL.
314+
"""Updates the code in an existing VeFaaS application without changing endpoint.
315+
316+
Prepares new code from local path and updates function via VeFaaS.
206317
207318
Args:
208-
application_name (str): Existing application name to update.
209-
path (str): Local agent project path.
319+
application_name (str): Name of the existing application to update.
320+
path (str): Local path containing updated project files.
210321
211322
Returns:
212-
CloudApp: Updated cloud app with same endpoint.
323+
CloudApp: Updated application instance with same endpoint.
324+
325+
Raises:
326+
ValueError: If update fails due to preparation or VeFaaS issues.
327+
328+
Note:
329+
Preserves gateway and other resources; only function code is updated.
330+
Path is resolved to absolute before processing.
331+
332+
Examples:
333+
```python
334+
updated_app = engine.update_function_code("my-agent", "./updated-project")
335+
```
213336
"""
214337
# convert `path` to absolute path
215338
path = str(Path(path).resolve())

0 commit comments

Comments
 (0)