langchain 0.0.197-rc.1 → 0.0.198

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.
Files changed (92) hide show
  1. package/dist/chains/openai_moderation.cjs +2 -2
  2. package/dist/chains/openai_moderation.d.ts +1 -1
  3. package/dist/chains/openai_moderation.js +1 -1
  4. package/dist/chat_models/anthropic.cjs +351 -15
  5. package/dist/chat_models/anthropic.d.ts +157 -1
  6. package/dist/chat_models/anthropic.js +348 -1
  7. package/dist/chat_models/cloudflare_workersai.cjs +5 -0
  8. package/dist/chat_models/cloudflare_workersai.d.ts +3 -0
  9. package/dist/chat_models/cloudflare_workersai.js +5 -0
  10. package/dist/chat_models/fireworks.d.ts +1 -1
  11. package/dist/chat_models/iflytek_xinghuo/common.d.ts +1 -1
  12. package/dist/chat_models/llama_cpp.cjs +24 -0
  13. package/dist/chat_models/llama_cpp.d.ts +3 -1
  14. package/dist/chat_models/llama_cpp.js +24 -0
  15. package/dist/chat_models/minimax.d.ts +1 -1
  16. package/dist/chat_models/openai.cjs +698 -4
  17. package/dist/chat_models/openai.d.ts +137 -4
  18. package/dist/chat_models/openai.js +695 -2
  19. package/dist/document_loaders/fs/openai_whisper_audio.cjs +2 -2
  20. package/dist/document_loaders/fs/openai_whisper_audio.d.ts +1 -1
  21. package/dist/document_loaders/fs/openai_whisper_audio.js +1 -1
  22. package/dist/document_loaders/fs/pptx.cjs +39 -0
  23. package/dist/document_loaders/fs/pptx.d.ts +23 -0
  24. package/dist/document_loaders/fs/pptx.js +35 -0
  25. package/dist/embeddings/openai.cjs +240 -2
  26. package/dist/embeddings/openai.d.ts +82 -1
  27. package/dist/embeddings/openai.js +239 -1
  28. package/dist/experimental/openai_assistant/index.cjs +35 -3
  29. package/dist/experimental/openai_assistant/index.d.ts +27 -1
  30. package/dist/experimental/openai_assistant/index.js +33 -1
  31. package/dist/experimental/openai_assistant/schema.d.ts +1 -1
  32. package/dist/experimental/openai_files/index.cjs +2 -2
  33. package/dist/experimental/openai_files/index.d.ts +1 -1
  34. package/dist/experimental/openai_files/index.js +1 -1
  35. package/dist/experimental/tools/pyinterpreter.cjs +248 -0
  36. package/dist/experimental/tools/pyinterpreter.d.ts +18 -0
  37. package/dist/experimental/tools/pyinterpreter.js +244 -0
  38. package/dist/graphs/neo4j_graph.cjs +49 -14
  39. package/dist/graphs/neo4j_graph.d.ts +30 -0
  40. package/dist/graphs/neo4j_graph.js +49 -14
  41. package/dist/llms/fireworks.d.ts +1 -1
  42. package/dist/llms/hf.cjs +13 -2
  43. package/dist/llms/hf.d.ts +5 -0
  44. package/dist/llms/hf.js +13 -2
  45. package/dist/llms/llama_cpp.cjs +17 -3
  46. package/dist/llms/llama_cpp.d.ts +4 -1
  47. package/dist/llms/llama_cpp.js +17 -3
  48. package/dist/llms/openai-chat.cjs +445 -3
  49. package/dist/llms/openai-chat.d.ts +123 -4
  50. package/dist/llms/openai-chat.js +443 -2
  51. package/dist/llms/openai.cjs +530 -6
  52. package/dist/llms/openai.d.ts +123 -4
  53. package/dist/llms/openai.js +525 -2
  54. package/dist/load/import_constants.cjs +3 -0
  55. package/dist/load/import_constants.js +3 -0
  56. package/dist/output_parsers/json.cjs +4 -0
  57. package/dist/output_parsers/json.js +4 -0
  58. package/dist/schema/index.d.ts +1 -1
  59. package/dist/tools/convert_to_openai.cjs +38 -4
  60. package/dist/tools/convert_to_openai.d.ts +11 -1
  61. package/dist/tools/convert_to_openai.js +35 -1
  62. package/dist/types/openai-types.d.ts +133 -1
  63. package/dist/util/env.cjs +9 -70
  64. package/dist/util/env.d.ts +1 -21
  65. package/dist/util/env.js +1 -62
  66. package/dist/util/openai-format-fndef.cjs +81 -0
  67. package/dist/util/openai-format-fndef.d.ts +44 -0
  68. package/dist/util/openai-format-fndef.js +77 -0
  69. package/dist/util/openai.cjs +18 -2
  70. package/dist/util/openai.d.ts +1 -1
  71. package/dist/util/openai.js +17 -1
  72. package/dist/util/openapi.d.ts +2 -2
  73. package/dist/util/prompt-layer.d.ts +1 -1
  74. package/dist/vectorstores/clickhouse.cjs +286 -0
  75. package/dist/vectorstores/clickhouse.d.ts +126 -0
  76. package/dist/vectorstores/clickhouse.js +259 -0
  77. package/dist/vectorstores/pgvector.cjs +142 -18
  78. package/dist/vectorstores/pgvector.d.ts +21 -0
  79. package/dist/vectorstores/pgvector.js +142 -18
  80. package/dist/vectorstores/weaviate.cjs +45 -2
  81. package/dist/vectorstores/weaviate.d.ts +27 -1
  82. package/dist/vectorstores/weaviate.js +45 -2
  83. package/document_loaders/fs/pptx.cjs +1 -0
  84. package/document_loaders/fs/pptx.d.ts +1 -0
  85. package/document_loaders/fs/pptx.js +1 -0
  86. package/experimental/tools/pyinterpreter.cjs +1 -0
  87. package/experimental/tools/pyinterpreter.d.ts +1 -0
  88. package/experimental/tools/pyinterpreter.js +1 -0
  89. package/package.json +41 -9
  90. package/vectorstores/clickhouse.cjs +1 -0
  91. package/vectorstores/clickhouse.d.ts +1 -0
  92. package/vectorstores/clickhouse.js +1 -0
@@ -1 +1,239 @@
1
- export { OpenAIEmbeddings, } from "@langchain/openai";
1
+ import { OpenAI as OpenAIClient } from "openai";
2
+ import { getEnvironmentVariable } from "../util/env.js";
3
+ import { chunkArray } from "../util/chunk.js";
4
+ import { Embeddings } from "./base.js";
5
+ import { getEndpoint } from "../util/azure.js";
6
+ import { wrapOpenAIClientError } from "../util/openai.js";
7
+ /**
8
+ * Class for generating embeddings using the OpenAI API. Extends the
9
+ * Embeddings class and implements OpenAIEmbeddingsParams and
10
+ * AzureOpenAIInput.
11
+ * @example
12
+ * ```typescript
13
+ * // Embed a query using OpenAIEmbeddings to generate embeddings for a given text
14
+ * const model = new OpenAIEmbeddings();
15
+ * const res = await model.embedQuery(
16
+ * "What would be a good company name for a company that makes colorful socks?",
17
+ * );
18
+ * console.log({ res });
19
+ *
20
+ * ```
21
+ */
22
+ export class OpenAIEmbeddings extends Embeddings {
23
+ constructor(fields, configuration) {
24
+ const fieldsWithDefaults = { maxConcurrency: 2, ...fields };
25
+ super(fieldsWithDefaults);
26
+ Object.defineProperty(this, "modelName", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: "text-embedding-ada-002"
31
+ });
32
+ Object.defineProperty(this, "batchSize", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: 512
37
+ });
38
+ Object.defineProperty(this, "stripNewLines", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: true
43
+ });
44
+ Object.defineProperty(this, "timeout", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
50
+ Object.defineProperty(this, "azureOpenAIApiVersion", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: void 0
55
+ });
56
+ Object.defineProperty(this, "azureOpenAIApiKey", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: void 0
61
+ });
62
+ Object.defineProperty(this, "azureOpenAIApiInstanceName", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
68
+ Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: void 0
73
+ });
74
+ Object.defineProperty(this, "azureOpenAIBasePath", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: void 0
79
+ });
80
+ Object.defineProperty(this, "organization", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: void 0
85
+ });
86
+ Object.defineProperty(this, "client", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: void 0
91
+ });
92
+ Object.defineProperty(this, "clientConfig", {
93
+ enumerable: true,
94
+ configurable: true,
95
+ writable: true,
96
+ value: void 0
97
+ });
98
+ let apiKey = fieldsWithDefaults?.openAIApiKey ??
99
+ getEnvironmentVariable("OPENAI_API_KEY");
100
+ const azureApiKey = fieldsWithDefaults?.azureOpenAIApiKey ??
101
+ getEnvironmentVariable("AZURE_OPENAI_API_KEY");
102
+ if (!azureApiKey && !apiKey) {
103
+ throw new Error("OpenAI or Azure OpenAI API key not found");
104
+ }
105
+ const azureApiInstanceName = fieldsWithDefaults?.azureOpenAIApiInstanceName ??
106
+ getEnvironmentVariable("AZURE_OPENAI_API_INSTANCE_NAME");
107
+ const azureApiDeploymentName = (fieldsWithDefaults?.azureOpenAIApiEmbeddingsDeploymentName ||
108
+ fieldsWithDefaults?.azureOpenAIApiDeploymentName) ??
109
+ (getEnvironmentVariable("AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME") ||
110
+ getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME"));
111
+ const azureApiVersion = fieldsWithDefaults?.azureOpenAIApiVersion ??
112
+ getEnvironmentVariable("AZURE_OPENAI_API_VERSION");
113
+ this.azureOpenAIBasePath =
114
+ fieldsWithDefaults?.azureOpenAIBasePath ??
115
+ getEnvironmentVariable("AZURE_OPENAI_BASE_PATH");
116
+ this.organization =
117
+ fieldsWithDefaults?.configuration?.organization ??
118
+ getEnvironmentVariable("OPENAI_ORGANIZATION");
119
+ this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
120
+ this.batchSize =
121
+ fieldsWithDefaults?.batchSize ?? (azureApiKey ? 1 : this.batchSize);
122
+ this.stripNewLines =
123
+ fieldsWithDefaults?.stripNewLines ?? this.stripNewLines;
124
+ this.timeout = fieldsWithDefaults?.timeout;
125
+ this.azureOpenAIApiVersion = azureApiVersion;
126
+ this.azureOpenAIApiKey = azureApiKey;
127
+ this.azureOpenAIApiInstanceName = azureApiInstanceName;
128
+ this.azureOpenAIApiDeploymentName = azureApiDeploymentName;
129
+ if (this.azureOpenAIApiKey) {
130
+ if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
131
+ throw new Error("Azure OpenAI API instance name not found");
132
+ }
133
+ if (!this.azureOpenAIApiDeploymentName) {
134
+ throw new Error("Azure OpenAI API deployment name not found");
135
+ }
136
+ if (!this.azureOpenAIApiVersion) {
137
+ throw new Error("Azure OpenAI API version not found");
138
+ }
139
+ apiKey = apiKey ?? "";
140
+ }
141
+ this.clientConfig = {
142
+ apiKey,
143
+ organization: this.organization,
144
+ baseURL: configuration?.basePath,
145
+ dangerouslyAllowBrowser: true,
146
+ defaultHeaders: configuration?.baseOptions?.headers,
147
+ defaultQuery: configuration?.baseOptions?.params,
148
+ ...configuration,
149
+ ...fields?.configuration,
150
+ };
151
+ }
152
+ /**
153
+ * Method to generate embeddings for an array of documents. Splits the
154
+ * documents into batches and makes requests to the OpenAI API to generate
155
+ * embeddings.
156
+ * @param texts Array of documents to generate embeddings for.
157
+ * @returns Promise that resolves to a 2D array of embeddings for each document.
158
+ */
159
+ async embedDocuments(texts) {
160
+ const batches = chunkArray(this.stripNewLines ? texts.map((t) => t.replace(/\n/g, " ")) : texts, this.batchSize);
161
+ const batchRequests = batches.map((batch) => this.embeddingWithRetry({
162
+ model: this.modelName,
163
+ input: batch,
164
+ }));
165
+ const batchResponses = await Promise.all(batchRequests);
166
+ const embeddings = [];
167
+ for (let i = 0; i < batchResponses.length; i += 1) {
168
+ const batch = batches[i];
169
+ const { data: batchResponse } = batchResponses[i];
170
+ for (let j = 0; j < batch.length; j += 1) {
171
+ embeddings.push(batchResponse[j].embedding);
172
+ }
173
+ }
174
+ return embeddings;
175
+ }
176
+ /**
177
+ * Method to generate an embedding for a single document. Calls the
178
+ * embeddingWithRetry method with the document as the input.
179
+ * @param text Document to generate an embedding for.
180
+ * @returns Promise that resolves to an embedding for the document.
181
+ */
182
+ async embedQuery(text) {
183
+ const { data } = await this.embeddingWithRetry({
184
+ model: this.modelName,
185
+ input: this.stripNewLines ? text.replace(/\n/g, " ") : text,
186
+ });
187
+ return data[0].embedding;
188
+ }
189
+ /**
190
+ * Private method to make a request to the OpenAI API to generate
191
+ * embeddings. Handles the retry logic and returns the response from the
192
+ * API.
193
+ * @param request Request to send to the OpenAI API.
194
+ * @returns Promise that resolves to the response from the API.
195
+ */
196
+ async embeddingWithRetry(request) {
197
+ if (!this.client) {
198
+ const openAIEndpointConfig = {
199
+ azureOpenAIApiDeploymentName: this.azureOpenAIApiDeploymentName,
200
+ azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
201
+ azureOpenAIApiKey: this.azureOpenAIApiKey,
202
+ azureOpenAIBasePath: this.azureOpenAIBasePath,
203
+ baseURL: this.clientConfig.baseURL,
204
+ };
205
+ const endpoint = getEndpoint(openAIEndpointConfig);
206
+ const params = {
207
+ ...this.clientConfig,
208
+ baseURL: endpoint,
209
+ timeout: this.timeout,
210
+ maxRetries: 0,
211
+ };
212
+ if (!params.baseURL) {
213
+ delete params.baseURL;
214
+ }
215
+ this.client = new OpenAIClient(params);
216
+ }
217
+ const requestOptions = {};
218
+ if (this.azureOpenAIApiKey) {
219
+ requestOptions.headers = {
220
+ "api-key": this.azureOpenAIApiKey,
221
+ ...requestOptions.headers,
222
+ };
223
+ requestOptions.query = {
224
+ "api-version": this.azureOpenAIApiVersion,
225
+ ...requestOptions.query,
226
+ };
227
+ }
228
+ return this.caller.call(async () => {
229
+ try {
230
+ const res = await this.client.embeddings.create(request, requestOptions);
231
+ return res;
232
+ }
233
+ catch (e) {
234
+ const error = wrapOpenAIClientError(e);
235
+ throw error;
236
+ }
237
+ });
238
+ }
239
+ }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpenAIAssistantRunnable = void 0;
4
- const openai_1 = require("@langchain/openai");
4
+ const openai_1 = require("openai");
5
5
  const base_js_1 = require("../../schema/runnable/base.cjs");
6
6
  const time_js_1 = require("../../util/time.cjs");
7
7
  const base_js_2 = require("../../tools/base.cjs");
@@ -39,7 +39,7 @@ class OpenAIAssistantRunnable extends base_js_1.Runnable {
39
39
  writable: true,
40
40
  value: void 0
41
41
  });
42
- this.client = fields.client ?? new openai_1.OpenAIClient(fields?.clientOptions);
42
+ this.client = fields.client ?? new openai_1.OpenAI(fields?.clientOptions);
43
43
  this.assistantId = fields.assistantId;
44
44
  this.asAgent = fields.asAgent ?? this.asAgent;
45
45
  }
@@ -51,7 +51,7 @@ class OpenAIAssistantRunnable extends base_js_1.Runnable {
51
51
  }
52
52
  return tool;
53
53
  }) ?? [];
54
- const oaiClient = client ?? new openai_1.OpenAIClient(clientOptions);
54
+ const oaiClient = client ?? new openai_1.OpenAI(clientOptions);
55
55
  const assistant = await oaiClient.beta.assistants.create({
56
56
  name,
57
57
  instructions,
@@ -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);
@@ -1,4 +1,4 @@
1
- import { type ClientOptions, OpenAIClient } from "@langchain/openai";
1
+ import { type ClientOptions, OpenAI as OpenAIClient } from "openai";
2
2
  import { Runnable } from "../../schema/runnable/base.js";
3
3
  import type { RunnableConfig } from "../../schema/runnable/config.js";
4
4
  import type { OpenAIAssistantFinish, OpenAIAssistantAction, OpenAIToolType } from "./schema.js";
@@ -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;
@@ -1,4 +1,4 @@
1
- import { OpenAIClient } from "@langchain/openai";
1
+ import { OpenAI as OpenAIClient } from "openai";
2
2
  import { Runnable } from "../../schema/runnable/base.js";
3
3
  import { sleep } from "../../util/time.js";
4
4
  import { StructuredTool } from "../../tools/base.js";
@@ -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);
@@ -1,4 +1,4 @@
1
- import type { OpenAIClient } from "@langchain/openai";
1
+ import type { OpenAI as OpenAIClient } from "openai";
2
2
  import type { AgentFinish, AgentAction } from "../../schema/index.js";
3
3
  export type OpenAIAssistantFinish = AgentFinish & {
4
4
  runId: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpenAIFiles = void 0;
4
- const openai_1 = require("@langchain/openai");
4
+ const openai_1 = require("openai");
5
5
  const serializable_js_1 = require("../../load/serializable.cjs");
6
6
  class OpenAIFiles extends serializable_js_1.Serializable {
7
7
  constructor(fields) {
@@ -18,7 +18,7 @@ class OpenAIFiles extends serializable_js_1.Serializable {
18
18
  writable: true,
19
19
  value: void 0
20
20
  });
21
- this.oaiClient = fields?.client ?? new openai_1.OpenAIClient(fields?.clientOptions);
21
+ this.oaiClient = fields?.client ?? new openai_1.OpenAI(fields?.clientOptions);
22
22
  }
23
23
  /**
24
24
  * Upload file
@@ -1,4 +1,4 @@
1
- import { OpenAIClient, type ClientOptions } from "@langchain/openai";
1
+ import { OpenAI as OpenAIClient, type ClientOptions } from "openai";
2
2
  import { Serializable } from "../../load/serializable.js";
3
3
  export type OpenAIFilesInput = {
4
4
  client?: OpenAIClient;
@@ -1,4 +1,4 @@
1
- import { OpenAIClient } from "@langchain/openai";
1
+ import { OpenAI as OpenAIClient } from "openai";
2
2
  import { Serializable } from "../../load/serializable.js";
3
3
  export class OpenAIFiles extends Serializable {
4
4
  constructor(fields) {
@@ -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;