mirror of
https://github.com/langgenius/dify.git
synced 2026-02-15 15:34:26 +08:00
refactor: rename construct_environment method to _construct_environment for consistency across virtual environment providers
This commit is contained in:
parent
932be0ad64
commit
43daf4f82c
@ -18,10 +18,10 @@ class VirtualEnvironment(ABC):
|
||||
"""
|
||||
|
||||
self.options = options
|
||||
self.metadata = self.construct_environment(options, environments or {})
|
||||
self.metadata = self._construct_environment(options, environments or {})
|
||||
|
||||
@abstractmethod
|
||||
def construct_environment(self, options: Mapping[str, Any], environments: Mapping[str, str]) -> Metadata:
|
||||
def _construct_environment(self, options: Mapping[str, Any], environments: Mapping[str, str]) -> Metadata:
|
||||
"""
|
||||
Construct the unique identifier for the virtual environment.
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ class DockerDaemonEnvironment(VirtualEnvironment):
|
||||
DOCKER_IMAGE = "docker_image"
|
||||
DOCKER_COMMAND = "docker_command"
|
||||
|
||||
def construct_environment(self, options: Mapping[str, Any], environments: Mapping[str, str]) -> Metadata:
|
||||
def _construct_environment(self, options: Mapping[str, Any], environments: Mapping[str, str]) -> Metadata:
|
||||
"""
|
||||
Construct the Docker daemon virtual environment.
|
||||
"""
|
||||
|
||||
@ -85,7 +85,7 @@ class E2BEnvironment(VirtualEnvironment):
|
||||
class StoreKey(StrEnum):
|
||||
SANDBOX = "sandbox"
|
||||
|
||||
def construct_environment(self, options: Mapping[str, Any], environments: Mapping[str, str]) -> Metadata:
|
||||
def _construct_environment(self, options: Mapping[str, Any], environments: Mapping[str, str]) -> Metadata:
|
||||
"""
|
||||
Construct a new E2B virtual environment.
|
||||
"""
|
||||
|
||||
@ -65,7 +65,7 @@ class LocalVirtualEnvironment(VirtualEnvironment):
|
||||
NEVER USE IT IN PRODUCTION ENVIRONMENTS.
|
||||
"""
|
||||
|
||||
def construct_environment(self, options: Mapping[str, Any], environments: Mapping[str, str]) -> Metadata:
|
||||
def _construct_environment(self, options: Mapping[str, Any], environments: Mapping[str, str]) -> Metadata:
|
||||
"""
|
||||
Construct the local virtual environment.
|
||||
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
from .sandbox_session import SandboxProvider, SandboxSession, SandboxSessionManager
|
||||
|
||||
__all__ = ["SandboxProvider", "SandboxSession", "SandboxSessionManager"]
|
||||
@ -1,47 +0,0 @@
|
||||
from enum import StrEnum
|
||||
from typing import Any
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from core.session import BaseSession, SessionManager
|
||||
from core.virtual_environment.__base.entities import Arch
|
||||
|
||||
|
||||
class SandboxProvider(StrEnum):
|
||||
E2B = "e2b"
|
||||
DOCKER = "docker"
|
||||
LOCAL = "local"
|
||||
|
||||
|
||||
class SandboxSession(BaseSession):
|
||||
provider: SandboxProvider
|
||||
sandbox_id: str
|
||||
arch: Arch
|
||||
connection_config: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class SandboxSessionManager(SessionManager[SandboxSession]):
|
||||
def __init__(self, ttl: int | None = None):
|
||||
super().__init__(key_prefix="sandbox_session", session_class=SandboxSession, ttl=ttl)
|
||||
|
||||
def create(
|
||||
self,
|
||||
tenant_id: str,
|
||||
user_id: str,
|
||||
provider: SandboxProvider,
|
||||
sandbox_id: str,
|
||||
arch: Arch,
|
||||
connection_config: dict[str, Any] | None = None,
|
||||
context: dict[str, Any] | None = None,
|
||||
) -> SandboxSession:
|
||||
session = SandboxSession(
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
provider=provider,
|
||||
sandbox_id=sandbox_id,
|
||||
arch=arch,
|
||||
connection_config=connection_config or {},
|
||||
context=context or {},
|
||||
)
|
||||
self.save(session)
|
||||
return session
|
||||
Loading…
Reference in New Issue
Block a user