Spaces:
Paused
Paused
File size: 2,294 Bytes
4a1b917 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
"""Python sandbox tool for executing Python code in a secure environment.
This module provides a pre-configured PyodideSandboxTool instance for the medical agent.
Note: Deno must be installed on the host system for this tool to work.
https://docs.deno.com/runtime/getting_started/installation
The python_sandbox instance is configured with:
- pip_packages: Pre-installs a list of common data analysis packages for efficiency.
- stateful=True: Enables the sandbox to maintain variables, functions, and
imports between calls. The agent state must be configured to handle the
session_bytes and session_metadata for this to work.
- allow_net=True: Allows the sandbox to make network requests, which is
necessary for `micropip` to install packages from PyPI. This should be
used with caution in production environments.
"""
from langchain_sandbox import PyodideSandboxTool
from typing import Optional, List
def create_python_sandbox(
pip_packages: Optional[List[str]] = None,
stateful: bool = True,
allow_net: bool = True,
**kwargs,
) -> PyodideSandboxTool:
"""Create a pre-configured PyodideSandboxTool instance for the medical agent.
Args:
pip_packages (list, optional): List of pip packages to pre-install.
Defaults to common medical analysis packages.
stateful (bool, optional): Whether to maintain state between calls.
Defaults to True.
allow_net (bool, optional): Whether to allow network requests.
Defaults to True.
deno_path (str, optional): Path to the Deno executable.
Defaults to "/home/adib/deno-2.1.0-x86_64-unknown-linux-gnu/bin/deno".
**kwargs: Additional keyword arguments passed to PyodideSandboxTool.
Returns:
PyodideSandboxTool: Configured sandbox with medical analysis packages
"""
if pip_packages is None:
pip_packages = [
"pandas",
"numpy",
"pydicom",
"SimpleITK",
"scikit-image",
"Pillow",
"scikit-learn",
"matplotlib",
"seaborn",
"openpyxl",
]
return PyodideSandboxTool(
pip_packages=pip_packages,
stateful=stateful,
allow_net=allow_net,
**kwargs,
)
|