Skip to content

Commit 1b72178

Browse files
authored
feat(viking_url): viking mem and db envs (DATABASE_VIKINGMEM_BASE_URL and DATABASE_VIKING_BASE_URL) (#313)
1 parent 4a92b15 commit 1b72178

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

veadk/integrations/ve_viking_db_memory/ve_viking_db_memory.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import json
1616
import threading
17-
17+
from veadk.utils.misc import getenv
1818
from volcengine.ApiInfo import ApiInfo
1919
from volcengine.auth.SignerV4 import SignerV4
2020
from volcengine.base.Service import Service
@@ -51,10 +51,25 @@ def __init__(
5151
ak="",
5252
sk="",
5353
sts_token="",
54-
scheme="http",
54+
scheme="https",
5555
connection_timeout=30,
5656
socket_timeout=30,
5757
):
58+
env_host = getenv(
59+
"DATABASE_VIKINGMEM_BASE_URL", default_value=None, allow_false_values=True
60+
)
61+
if env_host:
62+
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+
raise ValueError(
70+
"DATABASE_VIKINGMEM_BASE_URL must start with http:// or https://"
71+
)
72+
5873
self.service_info = VikingDBMemoryClient.get_service_info(
5974
host, region, scheme, connection_timeout, socket_timeout
6075
)

veadk/knowledgebase/backends/vikingdb_knowledge_backend.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import requests
2323
from pydantic import Field
2424
from typing_extensions import override
25-
25+
from veadk.utils.misc import getenv
2626
import veadk.config # noqa E401
2727
from veadk.auth.veauth.utils import get_credential_from_vefaas_iam
2828
from veadk.configs.database_configs import NormalTOSConfig, TOSConfig
@@ -557,7 +557,21 @@ def _do_request(
557557
path: str,
558558
method: Literal["GET", "POST", "PUT", "DELETE"] = "POST",
559559
) -> dict:
560-
VIKINGDB_KNOWLEDGEBASE_BASE_URL = "api-knowledgebase.mlp.cn-beijing.volces.com"
560+
VIKINGDB_KNOWLEDGEBASE_BASE_URL = (
561+
"https://api-knowledgebase.mlp.cn-beijing.volces.com"
562+
)
563+
full_path = f"{VIKINGDB_KNOWLEDGEBASE_BASE_URL}{path}"
564+
565+
env_host = getenv(
566+
"DATABASE_VIKING_BASE_URL", default_value=None, allow_false_values=True
567+
)
568+
if env_host:
569+
if env_host.startswith("http://") or env_host.startswith("https://"):
570+
full_path = f"{env_host}{path}"
571+
else:
572+
raise ValueError(
573+
"DATABASE_VIKING_BASE_URL must start with http:// or https://"
574+
)
561575

562576
volcengine_access_key = self.volcengine_access_key
563577
volcengine_secret_key = self.volcengine_secret_key
@@ -579,7 +593,7 @@ def _do_request(
579593
)
580594
response = requests.request(
581595
method=method,
582-
url=f"https://{VIKINGDB_KNOWLEDGEBASE_BASE_URL}{path}",
596+
url=full_path,
583597
headers=request.headers,
584598
data=request.body,
585599
)

0 commit comments

Comments
 (0)