Skip to content

Commit b271fb7

Browse files
authored
feat(vefaas): get application endpoint (#35)
1 parent b689fa4 commit b271fb7

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
veadk-python[eval] @ git+https://github.com/volcengine/veadk-python.git # extra eval for prompt optimization in veadk studio
22
opensearch-py==2.8.0
33
agent-pilot-sdk>=0.0.9 # extra dep for prompt optimization in veadk studio
4+
typer>=0.16.0
45
uvicorn[standard]
56
fastapi

veadk/cli/services/vefaas/vefaas.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ def _list_application(self):
202202
)
203203
return response["Result"]["Items"]
204204

205+
def get_application_details(self, app_id: str = None, app_name: str = None):
206+
if not app_id and not app_name:
207+
raise ValueError("app_id and app_name cannot be both empty.")
208+
apps = self._list_application()
209+
if app_id:
210+
for app in apps:
211+
if app["Id"] == app_id:
212+
return app
213+
return None
214+
else:
215+
for app in apps:
216+
if app["Name"] == app_name:
217+
return app
218+
205219
def find_app_id_by_name(self, name: str):
206220
apps = self._list_application()
207221
for app in apps:

veadk/cloud/cloud_app.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import Any
1616
from uuid import uuid4
1717

18+
import json
1819
import httpx
1920
from a2a.client import A2ACardResolver, A2AClient
2021
from a2a.types import AgentCard, Message, MessageSendParams, SendMessageRequest
@@ -36,9 +37,9 @@ class CloudApp:
3637

3738
def __init__(
3839
self,
39-
vefaas_application_name: str,
40-
vefaas_endpoint: str,
41-
vefaas_application_id: str,
40+
vefaas_application_name: str = "",
41+
vefaas_endpoint: str = "",
42+
vefaas_application_id: str = "",
4243
use_agent_card: bool = False,
4344
):
4445
self.vefaas_endpoint = vefaas_endpoint
@@ -73,18 +74,24 @@ def __init__(
7374

7475
self.httpx_client = httpx.AsyncClient()
7576

76-
def _get_vefaas_endpoint(self) -> str:
77-
vefaas_endpoint = ""
78-
79-
if self.vefaas_application_id:
80-
# TODO(zakahan): get endpoint from vefaas
81-
vefaas_endpoint = ...
82-
return vefaas_endpoint
77+
def _get_vefaas_endpoint(
78+
self,
79+
volcengine_ak: str = getenv("VOLCENGINE_ACCESS_KEY"),
80+
volcengine_sk: str = getenv("VOLCENGINE_SECRET_KEY"),
81+
) -> str:
82+
from veadk.cli.services.vefaas.vefaas import VeFaaS
8383

84-
if self.vefaas_application_name:
85-
# TODO(zakahan): get endpoint from vefaas
86-
vefaas_endpoint = ...
87-
return vefaas_endpoint
84+
vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
85+
app = vefaas_client.get_application_details(
86+
app_id=self.vefaas_application_id,
87+
app_name=self.vefaas_application_name,
88+
)
89+
cloud_resource = json.loads(app["CloudResource"])
90+
try:
91+
vefaas_endpoint = cloud_resource["framework"]["url"]["system_url"]
92+
except Exception as e:
93+
raise ValueError(f"VeFaaS cloudAPP could not get endpoint. Error: {e}")
94+
return vefaas_endpoint
8895

8996
def _get_vefaas_application_id_by_name(self) -> str:
9097
if not self.vefaas_application_name:

0 commit comments

Comments
 (0)