Skip to content

Commit

Permalink
feat: add container_configs argument for docker session
Browse files Browse the repository at this point in the history
  • Loading branch information
vndee committed Nov 18, 2024
1 parent ab4d31f commit 272c262
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion llm_sandbox/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
commit_container: bool = True,
verbose: bool = False,
mounts: Optional[list[Mount]] = None,
container_configs: Optional[dict] = None,
):
"""
Create a new sandbox session
Expand All @@ -44,6 +45,8 @@ def __init__(
:param keep_template: if True, the image and container will not be removed after the session ends
:param commit_container: if True, the Docker container will be commited after the session ends
:param verbose: if True, print messages
:param mounts: List of mounts to be mounted to the container
:param container_configs: Additional configurations for the container, i.e. resources limits (cpu_count, mem_limit), etc.
"""
super().__init__(lang, verbose)
if image and dockerfile:
Expand Down Expand Up @@ -77,6 +80,7 @@ def __init__(
self.is_create_template: bool = False
self.verbose = verbose
self.mounts = mounts
self.container_configs = container_configs

def open(self):
warning_str = (
Expand Down Expand Up @@ -112,7 +116,11 @@ def open(self):
print(f"Using image {self.image.tags[-1]}")

self.container = self.client.containers.run(
self.image, detach=True, tty=True, mounts=self.mounts
self.image,
detach=True,
tty=True,
mounts=self.mounts,
**self.container_configs,
)

def close(self):
Expand Down
3 changes: 3 additions & 0 deletions llm_sandbox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __new__(
verbose: bool = False,
use_kubernetes: bool = False,
kube_namespace: Optional[str] = "default",
container_configs: Optional[dict] = None,
):
"""
Create a new sandbox session
Expand All @@ -30,6 +31,7 @@ def __new__(
:param verbose: if True, print messages (default is True)
:param use_kubernetes: if True, use Kubernetes instead of Docker (default is False)
:param kube_namespace: Kubernetes namespace to use (only if 'use_kubernetes' is True), default is 'default'
:param container_configs: Additional configurations for the Docker container, i.e. resources limits (cpu_count, mem_limit), etc.
"""
if use_kubernetes:
return SandboxKubernetesSession(
Expand All @@ -50,4 +52,5 @@ def __new__(
keep_template=keep_template,
commit_container=commit_container,
verbose=verbose,
container_configs=container_configs,
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "llm-sandbox"
version = "0.1.2-alpha"
version = "0.1.4"
description = "Lightweight and portable LLM sandbox runtime (code interpreter) Python library"
authors = ["Duy Huynh <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 272c262

Please sign in to comment.