diff --git a/agentrun/memory_collection/__memory_collection_async_template.py b/agentrun/memory_collection/__memory_collection_async_template.py index 2823516..7df79b0 100644 --- a/agentrun/memory_collection/__memory_collection_async_template.py +++ b/agentrun/memory_collection/__memory_collection_async_template.py @@ -283,20 +283,27 @@ async def to_mem0_memory_async( @staticmethod def _convert_vpc_endpoint_to_public(endpoint: str) -> str: - """将 VPC 内网地址转换为公网地址 + """根据运行环境决定是否将 VPC 内网地址转换为公网地址 + + 在云上(FC_REGION 环境变量存在)保持 VPC 地址不变, + 在本地(FC_REGION 不存在)将 VPC 地址转换为公网地址。 Args: endpoint: 原始 endpoint,可能是 VPC 内网地址 Returns: - str: 公网地址 + str: 根据环境返回 VPC 地址或公网地址 Example: >>> _convert_vpc_endpoint_to_public("https://jiuqing.cn-hangzhou.vpc.tablestore.aliyuncs.com") - "https://jiuqing.cn-hangzhou.ots.aliyuncs.com" + "https://jiuqing.cn-hangzhou.ots.aliyuncs.com" # 本地环境 """ + import os + + is_running_on_fc = os.getenv("FC_REGION") is not None + if is_running_on_fc: + return endpoint if ".vpc.tablestore.aliyuncs.com" in endpoint: - # 将 .vpc.tablestore.aliyuncs.com 替换为 .ots.aliyuncs.com return endpoint.replace( ".vpc.tablestore.aliyuncs.com", ".ots.aliyuncs.com" ) diff --git a/agentrun/memory_collection/memory_collection.py b/agentrun/memory_collection/memory_collection.py index e12903e..38a6674 100644 --- a/agentrun/memory_collection/memory_collection.py +++ b/agentrun/memory_collection/memory_collection.py @@ -521,20 +521,27 @@ def to_mem0_memory( @staticmethod def _convert_vpc_endpoint_to_public(endpoint: str) -> str: - """将 VPC 内网地址转换为公网地址 + """根据运行环境决定是否将 VPC 内网地址转换为公网地址 + + 在云上(FC_REGION 环境变量存在)保持 VPC 地址不变, + 在本地(FC_REGION 不存在)将 VPC 地址转换为公网地址。 Args: endpoint: 原始 endpoint,可能是 VPC 内网地址 Returns: - str: 公网地址 + str: 根据环境返回 VPC 地址或公网地址 Example: >>> _convert_vpc_endpoint_to_public("https://jiuqing.cn-hangzhou.vpc.tablestore.aliyuncs.com") - "https://jiuqing.cn-hangzhou.ots.aliyuncs.com" + "https://jiuqing.cn-hangzhou.ots.aliyuncs.com" # 本地环境 """ + import os + + is_running_on_fc = os.getenv("FC_REGION") is not None + if is_running_on_fc: + return endpoint if ".vpc.tablestore.aliyuncs.com" in endpoint: - # 将 .vpc.tablestore.aliyuncs.com 替换为 .ots.aliyuncs.com return endpoint.replace( ".vpc.tablestore.aliyuncs.com", ".ots.aliyuncs.com" )