langchain 0.0.197 → 0.0.199
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/index.d.ts +1 -1
- package/dist/chains/conversational_retrieval_chain.cjs +16 -2
- package/dist/chains/conversational_retrieval_chain.d.ts +2 -0
- package/dist/chains/conversational_retrieval_chain.js +16 -2
- package/dist/chat_models/llama_cpp.cjs +45 -0
- package/dist/chat_models/llama_cpp.d.ts +4 -1
- package/dist/chat_models/llama_cpp.js +45 -0
- package/dist/document_loaders/fs/chatgpt.cjs +85 -0
- package/dist/document_loaders/fs/chatgpt.d.ts +8 -0
- package/dist/document_loaders/fs/chatgpt.js +81 -0
- package/dist/document_loaders/fs/pptx.cjs +39 -0
- package/dist/document_loaders/fs/pptx.d.ts +23 -0
- package/dist/document_loaders/fs/pptx.js +35 -0
- package/dist/document_loaders/web/confluence.cjs +31 -7
- package/dist/document_loaders/web/confluence.d.ts +12 -5
- package/dist/document_loaders/web/confluence.js +31 -7
- package/dist/experimental/openai_assistant/index.cjs +32 -0
- package/dist/experimental/openai_assistant/index.d.ts +26 -0
- package/dist/experimental/openai_assistant/index.js +32 -0
- package/dist/experimental/tools/pyinterpreter.cjs +248 -0
- package/dist/experimental/tools/pyinterpreter.d.ts +18 -0
- package/dist/experimental/tools/pyinterpreter.js +244 -0
- package/dist/graphs/neo4j_graph.cjs +49 -14
- package/dist/graphs/neo4j_graph.d.ts +30 -0
- package/dist/graphs/neo4j_graph.js +49 -14
- package/dist/llms/gradient_ai.cjs +98 -0
- package/dist/llms/gradient_ai.d.ts +50 -0
- package/dist/llms/gradient_ai.js +94 -0
- package/dist/llms/hf.cjs +13 -2
- package/dist/llms/hf.d.ts +5 -0
- package/dist/llms/hf.js +13 -2
- package/dist/llms/llama_cpp.cjs +17 -3
- package/dist/llms/llama_cpp.d.ts +4 -1
- package/dist/llms/llama_cpp.js +17 -3
- package/dist/llms/watsonx_ai.cjs +154 -0
- package/dist/llms/watsonx_ai.d.ts +72 -0
- package/dist/llms/watsonx_ai.js +150 -0
- package/dist/load/import_constants.cjs +6 -0
- package/dist/load/import_constants.js +6 -0
- package/dist/load/import_map.cjs +4 -3
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/output_parsers/json.cjs +4 -0
- package/dist/output_parsers/json.js +4 -0
- package/dist/tools/google_places.cjs +81 -0
- package/dist/tools/google_places.d.ts +21 -0
- package/dist/tools/google_places.js +77 -0
- package/dist/vectorstores/clickhouse.cjs +286 -0
- package/dist/vectorstores/clickhouse.d.ts +126 -0
- package/dist/vectorstores/clickhouse.js +259 -0
- package/dist/vectorstores/elasticsearch.cjs +16 -3
- package/dist/vectorstores/elasticsearch.d.ts +6 -2
- package/dist/vectorstores/elasticsearch.js +16 -3
- package/dist/vectorstores/pgvector.cjs +142 -18
- package/dist/vectorstores/pgvector.d.ts +21 -0
- package/dist/vectorstores/pgvector.js +142 -18
- package/dist/vectorstores/prisma.cjs +1 -1
- package/dist/vectorstores/prisma.js +1 -1
- package/dist/vectorstores/weaviate.cjs +45 -2
- package/dist/vectorstores/weaviate.d.ts +27 -1
- package/dist/vectorstores/weaviate.js +45 -2
- package/dist/vectorstores/xata.cjs +3 -2
- package/dist/vectorstores/xata.js +3 -2
- package/document_loaders/fs/chatgpt.cjs +1 -0
- package/document_loaders/fs/chatgpt.d.ts +1 -0
- package/document_loaders/fs/chatgpt.js +1 -0
- package/document_loaders/fs/pptx.cjs +1 -0
- package/document_loaders/fs/pptx.d.ts +1 -0
- package/document_loaders/fs/pptx.js +1 -0
- package/experimental/tools/pyinterpreter.cjs +1 -0
- package/experimental/tools/pyinterpreter.d.ts +1 -0
- package/experimental/tools/pyinterpreter.js +1 -0
- package/llms/gradient_ai.cjs +1 -0
- package/llms/gradient_ai.d.ts +1 -0
- package/llms/gradient_ai.js +1 -0
- package/llms/watsonx_ai.cjs +1 -0
- package/llms/watsonx_ai.d.ts +1 -0
- package/llms/watsonx_ai.js +1 -0
- package/package.json +87 -13
- package/tools/google_places.cjs +1 -0
- package/tools/google_places.d.ts +1 -0
- package/tools/google_places.js +1 -0
- package/vectorstores/clickhouse.cjs +1 -0
- package/vectorstores/clickhouse.d.ts +1 -0
- package/vectorstores/clickhouse.js +1 -0
|
@@ -16,7 +16,7 @@ import { BaseDocumentLoader } from "../base.js";
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
export class ConfluencePagesLoader extends BaseDocumentLoader {
|
|
19
|
-
constructor({ baseUrl, spaceKey, username, accessToken, limit = 25, }) {
|
|
19
|
+
constructor({ baseUrl, spaceKey, username, accessToken, limit = 25, personalAccessToken, }) {
|
|
20
20
|
super();
|
|
21
21
|
Object.defineProperty(this, "baseUrl", {
|
|
22
22
|
enumerable: true,
|
|
@@ -48,11 +48,32 @@ export class ConfluencePagesLoader extends BaseDocumentLoader {
|
|
|
48
48
|
writable: true,
|
|
49
49
|
value: void 0
|
|
50
50
|
});
|
|
51
|
+
Object.defineProperty(this, "personalAccessToken", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
51
57
|
this.baseUrl = baseUrl;
|
|
52
58
|
this.spaceKey = spaceKey;
|
|
53
59
|
this.username = username;
|
|
54
60
|
this.accessToken = accessToken;
|
|
55
61
|
this.limit = limit;
|
|
62
|
+
this.personalAccessToken = personalAccessToken;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the authorization header for the request.
|
|
66
|
+
* @returns The authorization header as a string, or undefined if no credentials were provided.
|
|
67
|
+
*/
|
|
68
|
+
get authorizationHeader() {
|
|
69
|
+
if (this.personalAccessToken) {
|
|
70
|
+
return `Bearer ${this.personalAccessToken}`;
|
|
71
|
+
}
|
|
72
|
+
else if (this.username && this.accessToken) {
|
|
73
|
+
const authToken = Buffer.from(`${this.username}:${this.accessToken}`).toString("base64");
|
|
74
|
+
return `Basic ${authToken}`;
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
56
77
|
}
|
|
57
78
|
/**
|
|
58
79
|
* Fetches all the pages in the specified space and converts each page to
|
|
@@ -76,13 +97,16 @@ export class ConfluencePagesLoader extends BaseDocumentLoader {
|
|
|
76
97
|
*/
|
|
77
98
|
async fetchConfluenceData(url) {
|
|
78
99
|
try {
|
|
79
|
-
const
|
|
100
|
+
const initialHeaders = {
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
Accept: "application/json",
|
|
103
|
+
};
|
|
104
|
+
const authHeader = this.authorizationHeader;
|
|
105
|
+
if (authHeader) {
|
|
106
|
+
initialHeaders.Authorization = authHeader;
|
|
107
|
+
}
|
|
80
108
|
const response = await fetch(url, {
|
|
81
|
-
headers:
|
|
82
|
-
Authorization: `Basic ${authToken}`,
|
|
83
|
-
"Content-Type": "application/json",
|
|
84
|
-
Accept: "application/json",
|
|
85
|
-
},
|
|
109
|
+
headers: initialHeaders,
|
|
86
110
|
});
|
|
87
111
|
if (!response.ok) {
|
|
88
112
|
throw new Error(`Failed to fetch ${url} from Confluence: ${response.status}`);
|
|
@@ -109,6 +109,38 @@ class OpenAIAssistantRunnable extends base_js_1.Runnable {
|
|
|
109
109
|
}
|
|
110
110
|
return this._getResponse(run.id, run.thread_id);
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Delete an assistant.
|
|
114
|
+
*
|
|
115
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/deleteAssistant}
|
|
116
|
+
* @returns {Promise<AssistantDeleted>}
|
|
117
|
+
*/
|
|
118
|
+
async deleteAssistant() {
|
|
119
|
+
return await this.client.beta.assistants.del(this.assistantId);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves an assistant.
|
|
123
|
+
*
|
|
124
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/getAssistant}
|
|
125
|
+
* @returns {Promise<OpenAIClient.Beta.Assistants.Assistant>}
|
|
126
|
+
*/
|
|
127
|
+
async getAssistant() {
|
|
128
|
+
return await this.client.beta.assistants.retrieve(this.assistantId);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Modifies an assistant.
|
|
132
|
+
*
|
|
133
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/modifyAssistant}
|
|
134
|
+
* @returns {Promise<OpenAIClient.Beta.Assistants.Assistant>}
|
|
135
|
+
*/
|
|
136
|
+
async modifyAssistant({ model, name, instructions, fileIds, }) {
|
|
137
|
+
return await this.client.beta.assistants.update(this.assistantId, {
|
|
138
|
+
name,
|
|
139
|
+
instructions,
|
|
140
|
+
model,
|
|
141
|
+
file_ids: fileIds,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
112
144
|
async _parseStepsInput(input) {
|
|
113
145
|
const { action: { runId, threadId }, } = input.steps[input.steps.length - 1];
|
|
114
146
|
const run = await this._waitForRun(runId, threadId);
|
|
@@ -28,6 +28,32 @@ export declare class OpenAIAssistantRunnable<AsAgent extends boolean | undefined
|
|
|
28
28
|
fileIds?: string[];
|
|
29
29
|
}): Promise<OpenAIAssistantRunnable<AsAgent, Record<string, any>>>;
|
|
30
30
|
invoke(input: RunInput, _options?: RunnableConfig): Promise<ExtractRunOutput<AsAgent>>;
|
|
31
|
+
/**
|
|
32
|
+
* Delete an assistant.
|
|
33
|
+
*
|
|
34
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/deleteAssistant}
|
|
35
|
+
* @returns {Promise<AssistantDeleted>}
|
|
36
|
+
*/
|
|
37
|
+
deleteAssistant(): Promise<OpenAIClient.Beta.Assistants.AssistantDeleted>;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves an assistant.
|
|
40
|
+
*
|
|
41
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/getAssistant}
|
|
42
|
+
* @returns {Promise<OpenAIClient.Beta.Assistants.Assistant>}
|
|
43
|
+
*/
|
|
44
|
+
getAssistant(): Promise<OpenAIClient.Beta.Assistants.Assistant>;
|
|
45
|
+
/**
|
|
46
|
+
* Modifies an assistant.
|
|
47
|
+
*
|
|
48
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/modifyAssistant}
|
|
49
|
+
* @returns {Promise<OpenAIClient.Beta.Assistants.Assistant>}
|
|
50
|
+
*/
|
|
51
|
+
modifyAssistant<AsAgent extends boolean>({ model, name, instructions, fileIds, }: Omit<OpenAIAssistantRunnableInput<AsAgent>, "assistantId" | "tools"> & {
|
|
52
|
+
model?: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
instructions?: string;
|
|
55
|
+
fileIds?: string[];
|
|
56
|
+
}): Promise<OpenAIClient.Beta.Assistants.Assistant>;
|
|
31
57
|
private _parseStepsInput;
|
|
32
58
|
private _createRun;
|
|
33
59
|
private _createThreadAndRun;
|
|
@@ -106,6 +106,38 @@ export class OpenAIAssistantRunnable extends Runnable {
|
|
|
106
106
|
}
|
|
107
107
|
return this._getResponse(run.id, run.thread_id);
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Delete an assistant.
|
|
111
|
+
*
|
|
112
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/deleteAssistant}
|
|
113
|
+
* @returns {Promise<AssistantDeleted>}
|
|
114
|
+
*/
|
|
115
|
+
async deleteAssistant() {
|
|
116
|
+
return await this.client.beta.assistants.del(this.assistantId);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Retrieves an assistant.
|
|
120
|
+
*
|
|
121
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/getAssistant}
|
|
122
|
+
* @returns {Promise<OpenAIClient.Beta.Assistants.Assistant>}
|
|
123
|
+
*/
|
|
124
|
+
async getAssistant() {
|
|
125
|
+
return await this.client.beta.assistants.retrieve(this.assistantId);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Modifies an assistant.
|
|
129
|
+
*
|
|
130
|
+
* @link {https://platform.openai.com/docs/api-reference/assistants/modifyAssistant}
|
|
131
|
+
* @returns {Promise<OpenAIClient.Beta.Assistants.Assistant>}
|
|
132
|
+
*/
|
|
133
|
+
async modifyAssistant({ model, name, instructions, fileIds, }) {
|
|
134
|
+
return await this.client.beta.assistants.update(this.assistantId, {
|
|
135
|
+
name,
|
|
136
|
+
instructions,
|
|
137
|
+
model,
|
|
138
|
+
file_ids: fileIds,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
109
141
|
async _parseStepsInput(input) {
|
|
110
142
|
const { action: { runId, threadId }, } = input.steps[input.steps.length - 1];
|
|
111
143
|
const run = await this._waitForRun(runId, threadId);
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PythonInterpreterTool = void 0;
|
|
4
|
+
const pyodide_1 = require("pyodide");
|
|
5
|
+
const base_js_1 = require("../../tools/base.cjs");
|
|
6
|
+
class PythonInterpreterTool extends base_js_1.Tool {
|
|
7
|
+
static lc_name() {
|
|
8
|
+
return "PythonInterpreterTool";
|
|
9
|
+
}
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(options);
|
|
12
|
+
Object.defineProperty(this, "name", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: "python_interpreter"
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "description", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: `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:
|
|
23
|
+
${this.availableDefaultPackages}`
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "pyodideInstance", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "stdout", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: ""
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "stderr", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: ""
|
|
42
|
+
});
|
|
43
|
+
this.pyodideInstance = options.instance;
|
|
44
|
+
this.pyodideInstance.setStderr({
|
|
45
|
+
batched: (text) => {
|
|
46
|
+
this.stderr += text;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
this.pyodideInstance.setStdout({
|
|
50
|
+
batched: (text) => {
|
|
51
|
+
this.stdout += text;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async addPackage(packageName) {
|
|
56
|
+
await this.pyodideInstance.loadPackage(packageName);
|
|
57
|
+
this.description += `, ${packageName}`;
|
|
58
|
+
}
|
|
59
|
+
get availableDefaultPackages() {
|
|
60
|
+
return [
|
|
61
|
+
"asciitree",
|
|
62
|
+
"astropy",
|
|
63
|
+
"atomicwrites",
|
|
64
|
+
"attrs",
|
|
65
|
+
"autograd",
|
|
66
|
+
"awkward-cpp",
|
|
67
|
+
"bcrypt",
|
|
68
|
+
"beautifulsoup4",
|
|
69
|
+
"biopython",
|
|
70
|
+
"bitarray",
|
|
71
|
+
"bitstring",
|
|
72
|
+
"bleach",
|
|
73
|
+
"bokeh",
|
|
74
|
+
"boost-histogram",
|
|
75
|
+
"brotli",
|
|
76
|
+
"cachetools",
|
|
77
|
+
"Cartopy",
|
|
78
|
+
"cbor-diag",
|
|
79
|
+
"certifi",
|
|
80
|
+
"cffi",
|
|
81
|
+
"cffi_example",
|
|
82
|
+
"cftime",
|
|
83
|
+
"click",
|
|
84
|
+
"cligj",
|
|
85
|
+
"cloudpickle",
|
|
86
|
+
"cmyt",
|
|
87
|
+
"colorspacious",
|
|
88
|
+
"contourpy",
|
|
89
|
+
"coolprop",
|
|
90
|
+
"coverage",
|
|
91
|
+
"cramjam",
|
|
92
|
+
"cryptography",
|
|
93
|
+
"cssselect",
|
|
94
|
+
"cycler",
|
|
95
|
+
"cytoolz",
|
|
96
|
+
"decorator",
|
|
97
|
+
"demes",
|
|
98
|
+
"deprecation",
|
|
99
|
+
"distlib",
|
|
100
|
+
"docutils",
|
|
101
|
+
"exceptiongroup",
|
|
102
|
+
"fastparquet",
|
|
103
|
+
"fiona",
|
|
104
|
+
"fonttools",
|
|
105
|
+
"freesasa",
|
|
106
|
+
"fsspec",
|
|
107
|
+
"future",
|
|
108
|
+
"galpy",
|
|
109
|
+
"gensim",
|
|
110
|
+
"geopandas",
|
|
111
|
+
"gmpy2",
|
|
112
|
+
"gsw",
|
|
113
|
+
"h5py",
|
|
114
|
+
"html5lib",
|
|
115
|
+
"idna",
|
|
116
|
+
"igraph",
|
|
117
|
+
"imageio",
|
|
118
|
+
"iniconfig",
|
|
119
|
+
"jedi",
|
|
120
|
+
"Jinja2",
|
|
121
|
+
"joblib",
|
|
122
|
+
"jsonschema",
|
|
123
|
+
"kiwisolver",
|
|
124
|
+
"lazy-object-proxy",
|
|
125
|
+
"lazy_loader",
|
|
126
|
+
"lightgbm",
|
|
127
|
+
"logbook",
|
|
128
|
+
"lxml",
|
|
129
|
+
"MarkupSafe",
|
|
130
|
+
"matplotlib",
|
|
131
|
+
"matplotlib-pyodide",
|
|
132
|
+
"micropip",
|
|
133
|
+
"mne",
|
|
134
|
+
"more-itertools",
|
|
135
|
+
"mpmath",
|
|
136
|
+
"msgpack",
|
|
137
|
+
"msprime",
|
|
138
|
+
"multidict",
|
|
139
|
+
"munch",
|
|
140
|
+
"mypy",
|
|
141
|
+
"netcdf4",
|
|
142
|
+
"networkx",
|
|
143
|
+
"newick",
|
|
144
|
+
"nlopt",
|
|
145
|
+
"nltk",
|
|
146
|
+
"nose",
|
|
147
|
+
"numcodecs",
|
|
148
|
+
"numpy",
|
|
149
|
+
"opencv-python",
|
|
150
|
+
"optlang",
|
|
151
|
+
"orjson",
|
|
152
|
+
"packaging",
|
|
153
|
+
"pandas",
|
|
154
|
+
"parso",
|
|
155
|
+
"patsy",
|
|
156
|
+
"peewee",
|
|
157
|
+
"Pillow",
|
|
158
|
+
"pillow_heif",
|
|
159
|
+
"pkgconfig",
|
|
160
|
+
"pluggy",
|
|
161
|
+
"protobuf",
|
|
162
|
+
"py",
|
|
163
|
+
"pyb2d",
|
|
164
|
+
"pyclipper",
|
|
165
|
+
"pycparser",
|
|
166
|
+
"pycryptodome",
|
|
167
|
+
"pydantic",
|
|
168
|
+
"pyerfa",
|
|
169
|
+
"Pygments",
|
|
170
|
+
"pyheif",
|
|
171
|
+
"pyinstrument",
|
|
172
|
+
"pynacl",
|
|
173
|
+
"pyodide-http",
|
|
174
|
+
"pyodide-tblib",
|
|
175
|
+
"pyparsing",
|
|
176
|
+
"pyproj",
|
|
177
|
+
"pyrsistent",
|
|
178
|
+
"pyshp",
|
|
179
|
+
"pytest",
|
|
180
|
+
"pytest-benchmark",
|
|
181
|
+
"python-dateutil",
|
|
182
|
+
"python-magic",
|
|
183
|
+
"python-sat",
|
|
184
|
+
"python_solvespace",
|
|
185
|
+
"pytz",
|
|
186
|
+
"pywavelets",
|
|
187
|
+
"pyxel",
|
|
188
|
+
"pyyaml",
|
|
189
|
+
"rebound",
|
|
190
|
+
"reboundx",
|
|
191
|
+
"regex",
|
|
192
|
+
"retrying",
|
|
193
|
+
"RobotRaconteur",
|
|
194
|
+
"ruamel.yaml",
|
|
195
|
+
"rust-panic-test",
|
|
196
|
+
"scikit-image",
|
|
197
|
+
"scikit-learn",
|
|
198
|
+
"scipy",
|
|
199
|
+
"screed",
|
|
200
|
+
"setuptools",
|
|
201
|
+
"shapely",
|
|
202
|
+
"simplejson",
|
|
203
|
+
"six",
|
|
204
|
+
"smart_open",
|
|
205
|
+
"soupsieve",
|
|
206
|
+
"sourmash",
|
|
207
|
+
"sparseqr",
|
|
208
|
+
"sqlalchemy",
|
|
209
|
+
"statsmodels",
|
|
210
|
+
"svgwrite",
|
|
211
|
+
"swiglpk",
|
|
212
|
+
"sympy",
|
|
213
|
+
"termcolor",
|
|
214
|
+
"texttable",
|
|
215
|
+
"threadpoolctl",
|
|
216
|
+
"tomli",
|
|
217
|
+
"tomli-w",
|
|
218
|
+
"toolz",
|
|
219
|
+
"tqdm",
|
|
220
|
+
"traits",
|
|
221
|
+
"tskit",
|
|
222
|
+
"typing-extensions",
|
|
223
|
+
"uncertainties",
|
|
224
|
+
"unyt",
|
|
225
|
+
"webencodings",
|
|
226
|
+
"wordcloud",
|
|
227
|
+
"wrapt",
|
|
228
|
+
"xarray",
|
|
229
|
+
"xgboost",
|
|
230
|
+
"xlrd",
|
|
231
|
+
"xyzservices",
|
|
232
|
+
"yarl",
|
|
233
|
+
"yt",
|
|
234
|
+
"zarr",
|
|
235
|
+
].join(", ");
|
|
236
|
+
}
|
|
237
|
+
static async initialize(options) {
|
|
238
|
+
const instance = await (0, pyodide_1.loadPyodide)(options);
|
|
239
|
+
return new this({ ...options, instance });
|
|
240
|
+
}
|
|
241
|
+
async _call(script) {
|
|
242
|
+
this.stdout = "";
|
|
243
|
+
this.stderr = "";
|
|
244
|
+
await this.pyodideInstance.runPythonAsync(script);
|
|
245
|
+
return JSON.stringify({ stdout: this.stdout, stderr: this.stderr });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.PythonInterpreterTool = PythonInterpreterTool;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { loadPyodide, type PyodideInterface } from "pyodide";
|
|
2
|
+
import { Tool, ToolParams } from "../../tools/base.js";
|
|
3
|
+
export type PythonInterpreterToolParams = Parameters<typeof loadPyodide>[0] & ToolParams & {
|
|
4
|
+
instance: PyodideInterface;
|
|
5
|
+
};
|
|
6
|
+
export declare class PythonInterpreterTool extends Tool {
|
|
7
|
+
static lc_name(): string;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
pyodideInstance: PyodideInterface;
|
|
11
|
+
stdout: string;
|
|
12
|
+
stderr: string;
|
|
13
|
+
constructor(options: PythonInterpreterToolParams);
|
|
14
|
+
addPackage(packageName: string): Promise<void>;
|
|
15
|
+
get availableDefaultPackages(): string;
|
|
16
|
+
static initialize(options: Omit<PythonInterpreterToolParams, "instance">): Promise<PythonInterpreterTool>;
|
|
17
|
+
_call(script: string): Promise<string>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { loadPyodide } from "pyodide";
|
|
2
|
+
import { Tool } from "../../tools/base.js";
|
|
3
|
+
export class PythonInterpreterTool extends Tool {
|
|
4
|
+
static lc_name() {
|
|
5
|
+
return "PythonInterpreterTool";
|
|
6
|
+
}
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options);
|
|
9
|
+
Object.defineProperty(this, "name", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: "python_interpreter"
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "description", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: `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:
|
|
20
|
+
${this.availableDefaultPackages}`
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "pyodideInstance", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "stdout", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: ""
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "stderr", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: ""
|
|
39
|
+
});
|
|
40
|
+
this.pyodideInstance = options.instance;
|
|
41
|
+
this.pyodideInstance.setStderr({
|
|
42
|
+
batched: (text) => {
|
|
43
|
+
this.stderr += text;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
this.pyodideInstance.setStdout({
|
|
47
|
+
batched: (text) => {
|
|
48
|
+
this.stdout += text;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async addPackage(packageName) {
|
|
53
|
+
await this.pyodideInstance.loadPackage(packageName);
|
|
54
|
+
this.description += `, ${packageName}`;
|
|
55
|
+
}
|
|
56
|
+
get availableDefaultPackages() {
|
|
57
|
+
return [
|
|
58
|
+
"asciitree",
|
|
59
|
+
"astropy",
|
|
60
|
+
"atomicwrites",
|
|
61
|
+
"attrs",
|
|
62
|
+
"autograd",
|
|
63
|
+
"awkward-cpp",
|
|
64
|
+
"bcrypt",
|
|
65
|
+
"beautifulsoup4",
|
|
66
|
+
"biopython",
|
|
67
|
+
"bitarray",
|
|
68
|
+
"bitstring",
|
|
69
|
+
"bleach",
|
|
70
|
+
"bokeh",
|
|
71
|
+
"boost-histogram",
|
|
72
|
+
"brotli",
|
|
73
|
+
"cachetools",
|
|
74
|
+
"Cartopy",
|
|
75
|
+
"cbor-diag",
|
|
76
|
+
"certifi",
|
|
77
|
+
"cffi",
|
|
78
|
+
"cffi_example",
|
|
79
|
+
"cftime",
|
|
80
|
+
"click",
|
|
81
|
+
"cligj",
|
|
82
|
+
"cloudpickle",
|
|
83
|
+
"cmyt",
|
|
84
|
+
"colorspacious",
|
|
85
|
+
"contourpy",
|
|
86
|
+
"coolprop",
|
|
87
|
+
"coverage",
|
|
88
|
+
"cramjam",
|
|
89
|
+
"cryptography",
|
|
90
|
+
"cssselect",
|
|
91
|
+
"cycler",
|
|
92
|
+
"cytoolz",
|
|
93
|
+
"decorator",
|
|
94
|
+
"demes",
|
|
95
|
+
"deprecation",
|
|
96
|
+
"distlib",
|
|
97
|
+
"docutils",
|
|
98
|
+
"exceptiongroup",
|
|
99
|
+
"fastparquet",
|
|
100
|
+
"fiona",
|
|
101
|
+
"fonttools",
|
|
102
|
+
"freesasa",
|
|
103
|
+
"fsspec",
|
|
104
|
+
"future",
|
|
105
|
+
"galpy",
|
|
106
|
+
"gensim",
|
|
107
|
+
"geopandas",
|
|
108
|
+
"gmpy2",
|
|
109
|
+
"gsw",
|
|
110
|
+
"h5py",
|
|
111
|
+
"html5lib",
|
|
112
|
+
"idna",
|
|
113
|
+
"igraph",
|
|
114
|
+
"imageio",
|
|
115
|
+
"iniconfig",
|
|
116
|
+
"jedi",
|
|
117
|
+
"Jinja2",
|
|
118
|
+
"joblib",
|
|
119
|
+
"jsonschema",
|
|
120
|
+
"kiwisolver",
|
|
121
|
+
"lazy-object-proxy",
|
|
122
|
+
"lazy_loader",
|
|
123
|
+
"lightgbm",
|
|
124
|
+
"logbook",
|
|
125
|
+
"lxml",
|
|
126
|
+
"MarkupSafe",
|
|
127
|
+
"matplotlib",
|
|
128
|
+
"matplotlib-pyodide",
|
|
129
|
+
"micropip",
|
|
130
|
+
"mne",
|
|
131
|
+
"more-itertools",
|
|
132
|
+
"mpmath",
|
|
133
|
+
"msgpack",
|
|
134
|
+
"msprime",
|
|
135
|
+
"multidict",
|
|
136
|
+
"munch",
|
|
137
|
+
"mypy",
|
|
138
|
+
"netcdf4",
|
|
139
|
+
"networkx",
|
|
140
|
+
"newick",
|
|
141
|
+
"nlopt",
|
|
142
|
+
"nltk",
|
|
143
|
+
"nose",
|
|
144
|
+
"numcodecs",
|
|
145
|
+
"numpy",
|
|
146
|
+
"opencv-python",
|
|
147
|
+
"optlang",
|
|
148
|
+
"orjson",
|
|
149
|
+
"packaging",
|
|
150
|
+
"pandas",
|
|
151
|
+
"parso",
|
|
152
|
+
"patsy",
|
|
153
|
+
"peewee",
|
|
154
|
+
"Pillow",
|
|
155
|
+
"pillow_heif",
|
|
156
|
+
"pkgconfig",
|
|
157
|
+
"pluggy",
|
|
158
|
+
"protobuf",
|
|
159
|
+
"py",
|
|
160
|
+
"pyb2d",
|
|
161
|
+
"pyclipper",
|
|
162
|
+
"pycparser",
|
|
163
|
+
"pycryptodome",
|
|
164
|
+
"pydantic",
|
|
165
|
+
"pyerfa",
|
|
166
|
+
"Pygments",
|
|
167
|
+
"pyheif",
|
|
168
|
+
"pyinstrument",
|
|
169
|
+
"pynacl",
|
|
170
|
+
"pyodide-http",
|
|
171
|
+
"pyodide-tblib",
|
|
172
|
+
"pyparsing",
|
|
173
|
+
"pyproj",
|
|
174
|
+
"pyrsistent",
|
|
175
|
+
"pyshp",
|
|
176
|
+
"pytest",
|
|
177
|
+
"pytest-benchmark",
|
|
178
|
+
"python-dateutil",
|
|
179
|
+
"python-magic",
|
|
180
|
+
"python-sat",
|
|
181
|
+
"python_solvespace",
|
|
182
|
+
"pytz",
|
|
183
|
+
"pywavelets",
|
|
184
|
+
"pyxel",
|
|
185
|
+
"pyyaml",
|
|
186
|
+
"rebound",
|
|
187
|
+
"reboundx",
|
|
188
|
+
"regex",
|
|
189
|
+
"retrying",
|
|
190
|
+
"RobotRaconteur",
|
|
191
|
+
"ruamel.yaml",
|
|
192
|
+
"rust-panic-test",
|
|
193
|
+
"scikit-image",
|
|
194
|
+
"scikit-learn",
|
|
195
|
+
"scipy",
|
|
196
|
+
"screed",
|
|
197
|
+
"setuptools",
|
|
198
|
+
"shapely",
|
|
199
|
+
"simplejson",
|
|
200
|
+
"six",
|
|
201
|
+
"smart_open",
|
|
202
|
+
"soupsieve",
|
|
203
|
+
"sourmash",
|
|
204
|
+
"sparseqr",
|
|
205
|
+
"sqlalchemy",
|
|
206
|
+
"statsmodels",
|
|
207
|
+
"svgwrite",
|
|
208
|
+
"swiglpk",
|
|
209
|
+
"sympy",
|
|
210
|
+
"termcolor",
|
|
211
|
+
"texttable",
|
|
212
|
+
"threadpoolctl",
|
|
213
|
+
"tomli",
|
|
214
|
+
"tomli-w",
|
|
215
|
+
"toolz",
|
|
216
|
+
"tqdm",
|
|
217
|
+
"traits",
|
|
218
|
+
"tskit",
|
|
219
|
+
"typing-extensions",
|
|
220
|
+
"uncertainties",
|
|
221
|
+
"unyt",
|
|
222
|
+
"webencodings",
|
|
223
|
+
"wordcloud",
|
|
224
|
+
"wrapt",
|
|
225
|
+
"xarray",
|
|
226
|
+
"xgboost",
|
|
227
|
+
"xlrd",
|
|
228
|
+
"xyzservices",
|
|
229
|
+
"yarl",
|
|
230
|
+
"yt",
|
|
231
|
+
"zarr",
|
|
232
|
+
].join(", ");
|
|
233
|
+
}
|
|
234
|
+
static async initialize(options) {
|
|
235
|
+
const instance = await loadPyodide(options);
|
|
236
|
+
return new this({ ...options, instance });
|
|
237
|
+
}
|
|
238
|
+
async _call(script) {
|
|
239
|
+
this.stdout = "";
|
|
240
|
+
this.stderr = "";
|
|
241
|
+
await this.pyodideInstance.runPythonAsync(script);
|
|
242
|
+
return JSON.stringify({ stdout: this.stdout, stderr: this.stderr });
|
|
243
|
+
}
|
|
244
|
+
}
|