@langchain/community
Version:
Third-party integrations for LangChain.js
236 lines (234 loc) • 4.61 kB
JavaScript
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
const __langchain_core_tools = require_rolldown_runtime.__toESM(require("@langchain/core/tools"));
const pyodide = require_rolldown_runtime.__toESM(require("pyodide"));
//#region src/experimental/tools/pyinterpreter.ts
var pyinterpreter_exports = {};
require_rolldown_runtime.__export(pyinterpreter_exports, { PythonInterpreterTool: () => PythonInterpreterTool });
var PythonInterpreterTool = class extends __langchain_core_tools.Tool {
static lc_name() {
return "PythonInterpreterTool";
}
name = "python_interpreter";
description = `Evaluates python code in a sandbox environment. The environment resets on every execution. You must send the whole script every time and print your outputs. Script should be pure python code that can be evaluated. Packages available:
${this.availableDefaultPackages}`;
pyodideInstance;
stdout = "";
stderr = "";
constructor(options) {
super(options);
this.pyodideInstance = options.instance;
this.pyodideInstance.setStderr({ batched: (text) => {
this.stderr += text;
} });
this.pyodideInstance.setStdout({ batched: (text) => {
this.stdout += text;
} });
}
async addPackage(packageName) {
await this.pyodideInstance.loadPackage(packageName);
this.description += `, ${packageName}`;
}
get availableDefaultPackages() {
return [
"asciitree",
"astropy",
"atomicwrites",
"attrs",
"autograd",
"awkward-cpp",
"bcrypt",
"beautifulsoup4",
"biopython",
"bitarray",
"bitstring",
"bleach",
"bokeh",
"boost-histogram",
"brotli",
"cachetools",
"Cartopy",
"cbor-diag",
"certifi",
"cffi",
"cffi_example",
"cftime",
"click",
"cligj",
"cloudpickle",
"cmyt",
"colorspacious",
"contourpy",
"coolprop",
"coverage",
"cramjam",
"cryptography",
"cssselect",
"cycler",
"cytoolz",
"decorator",
"demes",
"deprecation",
"distlib",
"docutils",
"exceptiongroup",
"fastparquet",
"fiona",
"fonttools",
"freesasa",
"fsspec",
"future",
"galpy",
"gensim",
"geopandas",
"gmpy2",
"gsw",
"h5py",
"html5lib",
"idna",
"igraph",
"imageio",
"iniconfig",
"jedi",
"Jinja2",
"joblib",
"jsonschema",
"kiwisolver",
"lazy-object-proxy",
"lazy_loader",
"lightgbm",
"logbook",
"lxml",
"MarkupSafe",
"matplotlib",
"matplotlib-pyodide",
"micropip",
"mne",
"more-itertools",
"mpmath",
"msgpack",
"msprime",
"multidict",
"munch",
"mypy",
"netcdf4",
"networkx",
"newick",
"nlopt",
"nltk",
"nose",
"numcodecs",
"numpy",
"opencv-python",
"optlang",
"orjson",
"packaging",
"pandas",
"parso",
"patsy",
"peewee",
"Pillow",
"pillow_heif",
"pkgconfig",
"pluggy",
"protobuf",
"py",
"pyb2d",
"pyclipper",
"pycparser",
"pycryptodome",
"pydantic",
"pyerfa",
"Pygments",
"pyheif",
"pyinstrument",
"pynacl",
"pyodide-http",
"pyodide-tblib",
"pyparsing",
"pyproj",
"pyrsistent",
"pyshp",
"pytest",
"pytest-benchmark",
"python-dateutil",
"python-magic",
"python-sat",
"python_solvespace",
"pytz",
"pywavelets",
"pyxel",
"pyyaml",
"rebound",
"reboundx",
"regex",
"retrying",
"RobotRaconteur",
"ruamel.yaml",
"rust-panic-test",
"scikit-image",
"scikit-learn",
"scipy",
"screed",
"setuptools",
"shapely",
"simplejson",
"six",
"smart_open",
"soupsieve",
"sourmash",
"sparseqr",
"sqlalchemy",
"statsmodels",
"svgwrite",
"swiglpk",
"sympy",
"termcolor",
"texttable",
"threadpoolctl",
"tomli",
"tomli-w",
"toolz",
"tqdm",
"traits",
"tskit",
"typing-extensions",
"uncertainties",
"unyt",
"webencodings",
"wordcloud",
"wrapt",
"xarray",
"xgboost",
"xlrd",
"xyzservices",
"yarl",
"yt",
"zarr"
].join(", ");
}
static async initialize(options) {
const instance = await (0, pyodide.loadPyodide)(options);
return new this({
...options,
instance
});
}
async _call(script) {
this.stdout = "";
this.stderr = "";
await this.pyodideInstance.runPythonAsync(script);
return JSON.stringify({
stdout: this.stdout,
stderr: this.stderr
});
}
};
//#endregion
exports.PythonInterpreterTool = PythonInterpreterTool;
Object.defineProperty(exports, 'pyinterpreter_exports', {
enumerable: true,
get: function () {
return pyinterpreter_exports;
}
});
//# sourceMappingURL=pyinterpreter.cjs.map