Skip to content

Commit 15a149e

Browse files
committed
merge(vefaas): resolve conflicts in vefaas.py
2 parents 537f21f + 16dd35a commit 15a149e

File tree

7 files changed

+200
-19
lines changed

7 files changed

+200
-19
lines changed

.github/hooks/pre-commit

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/sh
2+
3+
if git rev-parse --verify HEAD >/dev/null 2>&1
4+
then
5+
against=HEAD
6+
else
7+
# Initial commit: diff against an empty tree object
8+
EMPTY_TREE=$(git hash-object -t tree /dev/null)
9+
against=$EMPTY_TREE
10+
fi
11+
12+
# Redirect output to stderr.
13+
exec 1>&2
14+
15+
echo "======================================================="
16+
echo "Running Verification for tokens, secret keys, etc..."
17+
echo "======================================================="
18+
echo ""
19+
20+
PROJECT_ROOT=$(git rev-parse --show-toplevel)
21+
PATTERNS_FILE=".secret-key-patterns"
22+
PATTERNS_PATH="$PROJECT_ROOT/$PATTERNS_FILE"
23+
24+
if [ ! -f "$PATTERNS_PATH" ]; then
25+
echo "========================= ERROR ========================="
26+
echo "Secret key patterns file not found at: $PATTERNS_PATH"
27+
echo "Please create this file in your project root to define the secret patterns."
28+
echo "Commit aborted."
29+
echo "======================================================="
30+
exit 1
31+
fi
32+
33+
34+
source "$PATTERNS_PATH"
35+
36+
#FILES_MODIFIED=$(git diff --cached --name-only -z $against)
37+
FILES_MODIFIED=$(git diff --cached --name-only)
38+
39+
NUM_FILES_CHECKED=0
40+
NUM_FILES_OFFENCES=0
41+
42+
exec < /dev/tty
43+
44+
for F in $FILES_MODIFIED
45+
do
46+
47+
for i in "${!git_verification_patterns[@]}"; do
48+
49+
MATCH=$(cat $F | egrep -i --line-number "${git_verification_patterns[$i]}")
50+
51+
if [ ! -z "$MATCH" ]; then
52+
echo "\t FILE: $F"
53+
echo "\tPATTERN: ${git_verification_patterns[$i]}"
54+
echo "\t DESC: ${git_verification_patterns_desc[$i]}"
55+
echo "\tLINE(S):"
56+
for L in $MATCH; do
57+
echo "\t\t$L"
58+
done
59+
60+
while true; do
61+
read -p "Commit file anyway? (y/N): " yn
62+
case $yn in
63+
[Yy] ) break;;
64+
[Nn] ) NUM_FILES_OFFENCES=$((NUM_FILES_OFFENCES+1)); break;;
65+
* ) echo "Answer y or n."; continue;;
66+
esac
67+
done
68+
69+
echo "\t---------------------------"
70+
fi
71+
72+
done
73+
74+
# Now also do a verification pattern for an SSH private key file
75+
MATCH=$(cat $F | egrep -i --line-number "${git_verification_patterns_ssh_key}")
76+
NUM_SSH_PK_LINES_FOUND=$(cat $F | egrep -i --line-number ${git_verification_patterns_ssh_key} | wc -l | awk '{print $1}')
77+
78+
if (( $NUM_SSH_PK_LINES_FOUND >= 3 )); then
79+
echo "\t FILE: $F"
80+
echo "\tPATTERN: ${git_verification_patterns_ssh_key}"
81+
echo "\t DESC: ${git_verification_patterns_desc[$i]}"
82+
echo "\tLINE(S):"
83+
for L in $MATCH; do
84+
echo "\t\t$L"
85+
done
86+
87+
while true; do
88+
read -p "Commit file anyway? (y/N): " yn
89+
case $yn in
90+
[Yy] ) break;;
91+
[Nn] ) NUM_FILES_OFFENCES=$((NUM_FILES_OFFENCES+1)); break;;
92+
* ) echo "Answer y or n."; continue;;
93+
esac
94+
done
95+
96+
echo "\t---------------------------"
97+
fi
98+
99+
NUM_FILES_CHECKED=$((NUM_FILES_CHECKED+1))
100+
101+
done
102+
103+
exec <&- # Release input
104+
105+
echo "======================= SUMMARY ======================="
106+
echo " Files Checked: $NUM_FILES_CHECKED"
107+
echo " Num File Offences: $NUM_FILES_OFFENCES"
108+
if [ $NUM_FILES_OFFENCES -gt 0 ]; then
109+
echo " Status: FAIL"
110+
else
111+
echo " Status: OK"
112+
fi
113+
echo "-------------------------------------------------------"
114+
echo ""
115+
116+
117+
# Exit code based on if > 0 offences found
118+
if [ $NUM_FILES_OFFENCES -gt 0 ]; then
119+
exit 1
120+
else
121+
exit 0
122+
fi

.secret-key-patterns

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# List of the patterns to search for
2+
declare -a git_verification_patterns # Create an associative array
3+
git_verification_patterns[0]="(\"|')?(AWS|aws|Aws|alibaba|aliyun)?_?(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key)(\"|')?\s*(:|=>|=)\s*(\"|')?[A-Za-z0-9/\+=]{40}(\"|'|\s)?"
4+
git_verification_patterns[1]="(\"|')?(AWS|aws|Aws|alibaba|aliyun)?_?(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key)?_?(ID|id|Id)?(\"|')?\s*(:|=>|=)\s*(\"|')?[A-Za-z0-9/\+=]{20}(\"|'|\s)?"
5+
git_verification_patterns[2]="(\s+|=|:)[a-z0-9]{64}(\s+|\|)" # DigitalOcean Personal Access Token
6+
git_verification_patterns[3]='Authorization\s+"?Basic\s+[a-zA-Z0-9+/]+={0,2}'
7+
git_verification_patterns[4]="BEGIN RSA PRIVATE KEY"
8+
git_verification_patterns[5]="END RSA PRIVATE KEY"
9+
git_verification_patterns[6]="(\s+|=|:)?(LTAI)" # LTAI Access Token
10+
git_verification_patterns[7]="(\s+|=|:)?(AK)" # AK Access Token
11+
12+
# List of the pattern descriptions (in same order)
13+
declare -a git_verification_patterns_desc
14+
git_verification_patterns_desc[0]="AWS Secret Key, Github Personal Access Token"
15+
git_verification_patterns_desc[1]="AWS Access Key ID"
16+
git_verification_patterns_desc[2]="DigitalOcean Personal Access Token"
17+
git_verification_patterns_desc[3]="Base64 Encoded HTTP Auth header"
18+
git_verification_patterns_desc[4]="SSH Private Key File"
19+
git_verification_patterns_desc[5]="SSH Private Key File"
20+
21+
# List of the white-list exceptions for the above patterns (in same order)
22+
declare -a git_verification_patterns_whitelist
23+
git_verification_patterns_whitelist[0]="(\s+|=)00000000000000000000(\s+|\|)"
24+
git_verification_patterns_whitelist[1]="(\s+|=)0000000000000000000000000000000000000000(\s+|\|)"
25+
git_verification_patterns_whitelist[2]="(\s+|=)0000000000000000000000000000000000000000000000000000000000000000(\s+|\|)"
26+
git_verification_patterns_whitelist[3]='Authorization "Basic MDAwMDAwMDAwMDAwMDowMDAwMDAwMDAwMAo="' # 0000000000000:00000000000"
27+
git_verification_patterns_whitelist[4]=""
28+
git_verification_patterns_whitelist[5]=""
29+
30+
git_verification_patterns_ssh_key='^.{65}$'
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
@@ -285,6 +285,20 @@ def _update_function_code(
285285

286286
return url, app_id, function_id
287287

288+
def get_application_details(self, app_id: str = None, app_name: str = None):
289+
if not app_id and not app_name:
290+
raise ValueError("app_id and app_name cannot be both empty.")
291+
apps = self._list_application()
292+
if app_id:
293+
for app in apps:
294+
if app["Id"] == app_id:
295+
return app
296+
return None
297+
else:
298+
for app in apps:
299+
if app["Name"] == app_name:
300+
return app
301+
288302
def find_app_id_by_name(self, name: str):
289303
apps = self._list_application()
290304
for app in apps:

veadk/cli/studio/fast_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from fastapi.staticfiles import StaticFiles
2323
from google.adk.agents.run_config import RunConfig, StreamingMode
2424
from google.genai import types
25+
from pydantic import BaseModel
2526

2627
from veadk.cli.studio.models import (
2728
GetAgentResponse,
@@ -151,6 +152,14 @@ async def runner_run_sse(user_text: str):
151152
yield f"data: {json.dumps(TOOL_INPUT_AVAILABLE)}\n\n"
152153

153154
for function_response in event.get_function_responses():
155+
# for load_memory and load_knowledgebase tools, the output is based BaseModel
156+
# we have to convert it
157+
for key, value in function_response.response.items():
158+
if isinstance(value, BaseModel):
159+
function_response.response[key] = value.model_dump(
160+
exclude_none=False
161+
)
162+
154163
TOOL_OUTPUT_AVAILABLE = {
155164
"type": "tool-output-available",
156165
"toolCallId": function_response.id,

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:

veadk/tools/load_knowledgebase_tool.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class SearchKnowledgebaseResponse(BaseModel):
5151

5252

5353
async def search_knowledgebase(
54-
self, query: str, app_name: str, user_id: str
54+
self, query: str, app_name: str
5555
) -> SearchKnowledgebaseResponse:
5656
"""Searches the knowledgebase of the current user."""
5757
if isinstance(knowledgebase, KnowledgeBase):
58-
res = knowledgebase.search(query, app_name=app_name, user_id=user_id)
58+
res = knowledgebase.search(query, app_name=app_name)
5959
entry_list = []
6060
for r in res:
6161
entry_list.append(KnowledgebaseEntry(content=r))
@@ -86,9 +86,7 @@ async def load_knowledgebase(
8686
A list of knowledgebase results.
8787
"""
8888
search_knowledgebase_response = await tool_context.search_knowledgebase(
89-
query,
90-
tool_context._invocation_context.app_name,
91-
tool_context._invocation_context.user_id,
89+
query, tool_context._invocation_context.app_name
9290
)
9391
return LoadKnowledgebaseResponse(
9492
knowledges=search_knowledgebase_response.knowledges

0 commit comments

Comments
 (0)