Skip to content

Commit 9c06652

Browse files
committed
feat(viking_url): viking mem and db envs (DATABASE_VIKINGMEM_BASE_URL and DATABASE_VIKING_BASE_URL) only for http private
1 parent 6ef687a commit 9c06652

File tree

3 files changed

+10
-45
lines changed

3 files changed

+10
-45
lines changed

veadk/consts.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,3 @@
7272
DEFAULT_IMAGE_GENERATE_MODEL_API_BASE = "https://ark.cn-beijing.volces.com/api/v3/"
7373

7474
VEFAAS_IAM_CRIDENTIAL_PATH = "/var/run/secrets/iam/credential"
75-
76-
DEFAULT_VIKING_BASE_URL = "api-knowledgebase.mlp.cn-beijing.volces.com"
77-
DEFAULT_VIKINGMEM_BASE_URL = "api-knowledgebase.mlp.cn-beijing.volces.com"

veadk/integrations/ve_viking_db_memory/ve_viking_db_memory.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,9 @@ def __init__(
5555
connection_timeout=30,
5656
socket_timeout=30,
5757
):
58-
env_host = getenv(
59-
"DATABASE_VIKINGMEM_BASE_URL", "api-knowledgebase.mlp.cn-beijing.volces.com"
60-
)
61-
# check if the environment variable contains protocol
58+
env_host = getenv("DATABASE_VIKINGMEM_BASE_URL", host)
6259
if env_host.startswith("http://"):
63-
host = env_host.replace("http://", "")
64-
scheme = "http"
65-
elif env_host.startswith("https://"):
66-
host = env_host.replace("https://", "")
67-
scheme = "https"
68-
else:
69-
# default http
70-
host = env_host
71-
scheme = "http"
72-
60+
env_host = env_host.replace("http://", "")
7361
self.service_info = VikingDBMemoryClient.get_service_info(
7462
host, region, scheme, connection_timeout, socket_timeout
7563
)

veadk/knowledgebase/backends/vikingdb_knowledge_backend.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,6 @@ def get_files_in_directory(directory: str):
5858
return file_paths
5959

6060

61-
def _normalize_base_url(base_url: str) -> str:
62-
"""Normalize base URL: if already has scheme, return as-is; otherwise add http://
63-
64-
Args:
65-
base_url: Base URL string
66-
67-
Returns:
68-
Normalized URL with scheme
69-
"""
70-
if not base_url:
71-
return base_url
72-
if base_url.startswith(("http://", "https://")):
73-
return base_url
74-
# PrivateLink URLs use http only
75-
return f"http://{base_url}"
76-
77-
7861
class VikingDBKnowledgeBackend(BaseKnowledgebaseBackend):
7962
"""Volcengine Viking DB knowledgebase backend.
8063
@@ -574,18 +557,16 @@ def _do_request(
574557
path: str,
575558
method: Literal["GET", "POST", "PUT", "DELETE"] = "POST",
576559
) -> dict:
577-
base_url = getenv(
560+
VIKINGDB_KNOWLEDGEBASE_BASE_URL = getenv(
578561
"DATABASE_VIKING_BASE_URL", "api-knowledgebase.mlp.cn-beijing.volces.com"
579562
)
580-
if base_url.startswith(("http://", "https://")):
581-
full_url = f"{base_url}{path}"
582-
else:
583-
scheme = (
584-
"https"
585-
if base_url == "api-knowledgebase.mlp.cn-beijing.volces.com"
586-
else "http"
563+
if VIKINGDB_KNOWLEDGEBASE_BASE_URL.startswith("http://"):
564+
VIKINGDB_KNOWLEDGEBASE_BASE_URL = VIKINGDB_KNOWLEDGEBASE_BASE_URL.replace(
565+
"http://", ""
587566
)
588-
full_url = f"{scheme}://{base_url}{path}"
567+
full_path = f"http://{VIKINGDB_KNOWLEDGEBASE_BASE_URL}{path}"
568+
else:
569+
full_path = f"https://{VIKINGDB_KNOWLEDGEBASE_BASE_URL}{path}"
589570

590571
volcengine_access_key = self.volcengine_access_key
591572
volcengine_secret_key = self.volcengine_secret_key
@@ -605,10 +586,9 @@ def _do_request(
605586
method=method,
606587
data=body,
607588
)
608-
609589
response = requests.request(
610590
method=method,
611-
url=full_url,
591+
url=full_path,
612592
headers=request.headers,
613593
data=request.body,
614594
)

0 commit comments

Comments
 (0)