Skip to content

Commit d06cc0f

Browse files
authored
Merge pull request #109 from Serverless-Devs/fix-ots-endpoint
refactor(memory_collection): update VPC endpoint conversion logic to …
2 parents a26d8b6 + 972a714 commit d06cc0f

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

agentrun/memory_collection/__memory_collection_async_template.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,20 +283,27 @@ async def to_mem0_memory_async(
283283

284284
@staticmethod
285285
def _convert_vpc_endpoint_to_public(endpoint: str) -> str:
286-
"""将 VPC 内网地址转换为公网地址
286+
"""根据运行环境决定是否将 VPC 内网地址转换为公网地址
287+
288+
在云上(FC_REGION 环境变量存在)保持 VPC 地址不变,
289+
在本地(FC_REGION 不存在)将 VPC 地址转换为公网地址。
287290
288291
Args:
289292
endpoint: 原始 endpoint,可能是 VPC 内网地址
290293
291294
Returns:
292-
str: 公网地址
295+
str: 根据环境返回 VPC 地址或公网地址
293296
294297
Example:
295298
>>> _convert_vpc_endpoint_to_public("https://jiuqing.cn-hangzhou.vpc.tablestore.aliyuncs.com")
296-
"https://jiuqing.cn-hangzhou.ots.aliyuncs.com"
299+
"https://jiuqing.cn-hangzhou.ots.aliyuncs.com" # 本地环境
297300
"""
301+
import os
302+
303+
is_running_on_fc = os.getenv("FC_REGION") is not None
304+
if is_running_on_fc:
305+
return endpoint
298306
if ".vpc.tablestore.aliyuncs.com" in endpoint:
299-
# 将 .vpc.tablestore.aliyuncs.com 替换为 .ots.aliyuncs.com
300307
return endpoint.replace(
301308
".vpc.tablestore.aliyuncs.com", ".ots.aliyuncs.com"
302309
)

agentrun/memory_collection/memory_collection.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,20 +521,27 @@ def to_mem0_memory(
521521

522522
@staticmethod
523523
def _convert_vpc_endpoint_to_public(endpoint: str) -> str:
524-
"""将 VPC 内网地址转换为公网地址
524+
"""根据运行环境决定是否将 VPC 内网地址转换为公网地址
525+
526+
在云上(FC_REGION 环境变量存在)保持 VPC 地址不变,
527+
在本地(FC_REGION 不存在)将 VPC 地址转换为公网地址。
525528
526529
Args:
527530
endpoint: 原始 endpoint,可能是 VPC 内网地址
528531
529532
Returns:
530-
str: 公网地址
533+
str: 根据环境返回 VPC 地址或公网地址
531534
532535
Example:
533536
>>> _convert_vpc_endpoint_to_public("https://jiuqing.cn-hangzhou.vpc.tablestore.aliyuncs.com")
534-
"https://jiuqing.cn-hangzhou.ots.aliyuncs.com"
537+
"https://jiuqing.cn-hangzhou.ots.aliyuncs.com" # 本地环境
535538
"""
539+
import os
540+
541+
is_running_on_fc = os.getenv("FC_REGION") is not None
542+
if is_running_on_fc:
543+
return endpoint
536544
if ".vpc.tablestore.aliyuncs.com" in endpoint:
537-
# 将 .vpc.tablestore.aliyuncs.com 替换为 .ots.aliyuncs.com
538545
return endpoint.replace(
539546
".vpc.tablestore.aliyuncs.com", ".ots.aliyuncs.com"
540547
)

0 commit comments

Comments
 (0)