@langchain/openai 1.1.2 → 1.2.0-dev-1765431816670
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/CHANGELOG.md +6 -0
- package/README.md +583 -2
- package/dist/azure/chat_models/common.d.cts.map +1 -1
- package/dist/azure/chat_models/common.d.ts +1 -0
- package/dist/azure/chat_models/common.d.ts.map +1 -1
- package/dist/azure/chat_models/completions.d.cts.map +1 -1
- package/dist/azure/chat_models/completions.d.ts.map +1 -1
- package/dist/azure/chat_models/index.d.cts +1 -1
- package/dist/azure/chat_models/index.d.cts.map +1 -1
- package/dist/azure/chat_models/index.d.ts.map +1 -1
- package/dist/azure/chat_models/responses.d.cts.map +1 -1
- package/dist/azure/chat_models/responses.d.ts.map +1 -1
- package/dist/azure/embeddings.d.cts.map +1 -1
- package/dist/azure/embeddings.d.ts.map +1 -1
- package/dist/azure/llms.d.cts +0 -1
- package/dist/azure/llms.d.cts.map +1 -1
- package/dist/azure/llms.d.ts +0 -1
- package/dist/azure/llms.d.ts.map +1 -1
- package/dist/chat_models/base.cjs +5 -1
- package/dist/chat_models/base.cjs.map +1 -1
- package/dist/chat_models/base.d.cts +8 -22
- package/dist/chat_models/base.d.cts.map +1 -1
- package/dist/chat_models/base.d.ts +6 -20
- package/dist/chat_models/base.d.ts.map +1 -1
- package/dist/chat_models/base.js +6 -2
- package/dist/chat_models/base.js.map +1 -1
- package/dist/chat_models/completions.cjs.map +1 -1
- package/dist/chat_models/completions.d.cts +1 -3
- package/dist/chat_models/completions.d.cts.map +1 -1
- package/dist/chat_models/completions.d.ts +1 -3
- package/dist/chat_models/completions.d.ts.map +1 -1
- package/dist/chat_models/completions.js.map +1 -1
- package/dist/chat_models/index.d.cts +42 -4
- package/dist/chat_models/index.d.cts.map +1 -1
- package/dist/chat_models/index.d.ts +42 -4
- package/dist/chat_models/index.d.ts.map +1 -1
- package/dist/chat_models/responses.d.cts +2 -2
- package/dist/chat_models/responses.d.cts.map +1 -1
- package/dist/chat_models/responses.d.ts +2 -2
- package/dist/chat_models/responses.d.ts.map +1 -1
- package/dist/converters/completions.cjs +22 -12
- package/dist/converters/completions.cjs.map +1 -1
- package/dist/converters/completions.d.cts +0 -1
- package/dist/converters/completions.d.cts.map +1 -1
- package/dist/converters/completions.d.ts +0 -1
- package/dist/converters/completions.d.ts.map +1 -1
- package/dist/converters/completions.js +23 -13
- package/dist/converters/completions.js.map +1 -1
- package/dist/converters/index.d.ts +2 -0
- package/dist/converters/responses.cjs +37 -4
- package/dist/converters/responses.cjs.map +1 -1
- package/dist/converters/responses.d.cts.map +1 -1
- package/dist/converters/responses.d.ts.map +1 -1
- package/dist/converters/responses.js +39 -6
- package/dist/converters/responses.js.map +1 -1
- package/dist/embeddings.d.cts +0 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +0 -1
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +2 -2
- package/dist/llms.d.cts +0 -1
- package/dist/llms.d.cts.map +1 -1
- package/dist/llms.d.ts +0 -1
- package/dist/llms.d.ts.map +1 -1
- package/dist/tools/applyPatch.cjs +116 -0
- package/dist/tools/applyPatch.cjs.map +1 -0
- package/dist/tools/applyPatch.d.cts +148 -0
- package/dist/tools/applyPatch.d.cts.map +1 -0
- package/dist/tools/applyPatch.d.ts +148 -0
- package/dist/tools/applyPatch.d.ts.map +1 -0
- package/dist/tools/applyPatch.js +115 -0
- package/dist/tools/applyPatch.js.map +1 -0
- package/dist/tools/codeInterpreter.cjs +95 -0
- package/dist/tools/codeInterpreter.cjs.map +1 -0
- package/dist/tools/codeInterpreter.d.cts +125 -0
- package/dist/tools/codeInterpreter.d.cts.map +1 -0
- package/dist/tools/codeInterpreter.d.ts +125 -0
- package/dist/tools/codeInterpreter.d.ts.map +1 -0
- package/dist/tools/codeInterpreter.js +94 -0
- package/dist/tools/codeInterpreter.js.map +1 -0
- package/dist/tools/computerUse.cjs +240 -0
- package/dist/tools/computerUse.cjs.map +1 -0
- package/dist/tools/computerUse.d.cts +234 -0
- package/dist/tools/computerUse.d.cts.map +1 -0
- package/dist/tools/computerUse.d.ts +234 -0
- package/dist/tools/computerUse.d.ts.map +1 -0
- package/dist/tools/computerUse.js +239 -0
- package/dist/tools/computerUse.js.map +1 -0
- package/dist/tools/custom.d.cts +1 -1
- package/dist/tools/custom.d.cts.map +1 -1
- package/dist/tools/custom.d.ts.map +1 -1
- package/dist/tools/dalle.d.cts +1 -2
- package/dist/tools/dalle.d.cts.map +1 -1
- package/dist/tools/dalle.d.ts +1 -2
- package/dist/tools/dalle.d.ts.map +1 -1
- package/dist/tools/fileSearch.cjs +137 -0
- package/dist/tools/fileSearch.cjs.map +1 -0
- package/dist/tools/fileSearch.d.cts +224 -0
- package/dist/tools/fileSearch.d.cts.map +1 -0
- package/dist/tools/fileSearch.d.ts +224 -0
- package/dist/tools/fileSearch.d.ts.map +1 -0
- package/dist/tools/fileSearch.js +136 -0
- package/dist/tools/fileSearch.js.map +1 -0
- package/dist/tools/imageGeneration.cjs +128 -0
- package/dist/tools/imageGeneration.cjs.map +1 -0
- package/dist/tools/imageGeneration.d.cts +199 -0
- package/dist/tools/imageGeneration.d.cts.map +1 -0
- package/dist/tools/imageGeneration.d.ts +199 -0
- package/dist/tools/imageGeneration.d.ts.map +1 -0
- package/dist/tools/imageGeneration.js +127 -0
- package/dist/tools/imageGeneration.js.map +1 -0
- package/dist/tools/index.cjs +26 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.d.cts +27 -0
- package/dist/tools/index.d.cts.map +1 -0
- package/dist/tools/index.d.ts +27 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +26 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/localShell.cjs +145 -0
- package/dist/tools/localShell.cjs.map +1 -0
- package/dist/tools/localShell.d.cts +167 -0
- package/dist/tools/localShell.d.cts.map +1 -0
- package/dist/tools/localShell.d.ts +167 -0
- package/dist/tools/localShell.d.ts.map +1 -0
- package/dist/tools/localShell.js +144 -0
- package/dist/tools/localShell.js.map +1 -0
- package/dist/tools/mcp.cjs +53 -0
- package/dist/tools/mcp.cjs.map +1 -0
- package/dist/tools/mcp.d.cts +177 -0
- package/dist/tools/mcp.d.cts.map +1 -0
- package/dist/tools/mcp.d.ts +177 -0
- package/dist/tools/mcp.d.ts.map +1 -0
- package/dist/tools/mcp.js +52 -0
- package/dist/tools/mcp.js.map +1 -0
- package/dist/tools/shell.cjs +163 -0
- package/dist/tools/shell.cjs.map +1 -0
- package/dist/tools/shell.d.cts +221 -0
- package/dist/tools/shell.d.cts.map +1 -0
- package/dist/tools/shell.d.ts +221 -0
- package/dist/tools/shell.d.ts.map +1 -0
- package/dist/tools/shell.js +162 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/tools/webSearch.cjs +73 -0
- package/dist/tools/webSearch.cjs.map +1 -0
- package/dist/tools/webSearch.d.cts +130 -0
- package/dist/tools/webSearch.d.cts.map +1 -0
- package/dist/tools/webSearch.d.ts +130 -0
- package/dist/tools/webSearch.d.ts.map +1 -0
- package/dist/tools/webSearch.js +72 -0
- package/dist/tools/webSearch.js.map +1 -0
- package/dist/types.d.cts +2 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +1 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/azure.d.cts +1 -5
- package/dist/utils/azure.d.cts.map +1 -1
- package/dist/utils/azure.d.ts +1 -5
- package/dist/utils/azure.d.ts.map +1 -1
- package/dist/utils/client.d.cts.map +1 -1
- package/dist/utils/client.d.ts.map +1 -1
- package/dist/utils/misc.cjs +6 -0
- package/dist/utils/misc.cjs.map +1 -1
- package/dist/utils/misc.d.cts +1 -1
- package/dist/utils/misc.d.cts.map +1 -1
- package/dist/utils/misc.d.ts +1 -1
- package/dist/utils/misc.d.ts.map +1 -1
- package/dist/utils/misc.js +6 -1
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/prompts.d.cts +0 -1
- package/dist/utils/prompts.d.cts.map +1 -1
- package/dist/utils/prompts.d.ts +0 -1
- package/dist/utils/prompts.d.ts.map +1 -1
- package/dist/utils/tools.cjs +39 -1
- package/dist/utils/tools.cjs.map +1 -1
- package/dist/utils/tools.d.cts.map +1 -1
- package/dist/utils/tools.d.ts.map +1 -1
- package/dist/utils/tools.js +37 -2
- package/dist/utils/tools.js.map +1 -1
- package/package.json +18 -15
- package/dist/langchain-core/dist/callbacks/base.d.ts +0 -1
- package/dist/langchain-core/dist/callbacks/manager.d.ts +0 -2
- package/dist/langchain-core/dist/language_models/base.d.ts +0 -5
- package/dist/langchain-core/dist/language_models/chat_models.d.cts +0 -13
- package/dist/langchain-core/dist/language_models/chat_models.d.cts.map +0 -1
- package/dist/langchain-core/dist/language_models/chat_models.d.ts +0 -20
- package/dist/langchain-core/dist/language_models/chat_models.d.ts.map +0 -1
- package/dist/langchain-core/dist/runnables/base.d.ts +0 -7
- package/dist/langchain-core/dist/runnables/graph.d.ts +0 -1
- package/dist/langchain-core/dist/runnables/types.d.ts +0 -2
- package/dist/langchain-core/dist/tools/types.d.ts +0 -5
- package/dist/langchain-core/dist/tracers/base.d.ts +0 -2
- package/dist/langchain-core/dist/tracers/event_stream.d.ts +0 -1
- package/dist/langchain-core/dist/tracers/log_stream.d.ts +0 -3
- package/dist/langchain-core/dist/types/_internal.d.cts +0 -11
- package/dist/langchain-core/dist/types/_internal.d.cts.map +0 -1
- package/dist/langchain-core/dist/types/_internal.d.ts +0 -11
- package/dist/langchain-core/dist/types/_internal.d.ts.map +0 -1
- package/dist/langchain-core/dist/utils/stream.d.cts +0 -26
- package/dist/langchain-core/dist/utils/stream.d.cts.map +0 -1
- package/dist/langchain-core/dist/utils/stream.d.ts +0 -26
- package/dist/langchain-core/dist/utils/stream.d.ts.map +0 -1
- package/dist/langchain-core/dist/utils/types/index.d.ts +0 -1
- package/dist/langchain-core/dist/utils/types/zod.d.ts +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/tools/codeInterpreter.ts
|
|
3
|
+
/**
|
|
4
|
+
* Converts container options to the API format.
|
|
5
|
+
*/
|
|
6
|
+
function convertContainer(container) {
|
|
7
|
+
if (typeof container === "string") return container;
|
|
8
|
+
return {
|
|
9
|
+
type: "auto",
|
|
10
|
+
file_ids: container?.fileIds,
|
|
11
|
+
memory_limit: container?.memoryLimit
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Code Interpreter tool that allows models to write and run Python code
|
|
16
|
+
* in a sandboxed environment to solve complex problems.
|
|
17
|
+
*
|
|
18
|
+
* Use Code Interpreter for:
|
|
19
|
+
* - **Data analysis**: Processing files with diverse data and formatting
|
|
20
|
+
* - **File generation**: Creating files with data and images of graphs
|
|
21
|
+
* - **Iterative coding**: Writing and running code iteratively to solve problems
|
|
22
|
+
* - **Visual intelligence**: Cropping, zooming, rotating, and transforming images
|
|
23
|
+
*
|
|
24
|
+
* The tool runs in a container, which is a fully sandboxed virtual machine.
|
|
25
|
+
* Containers can be created automatically (auto mode) or explicitly via the
|
|
26
|
+
* `/v1/containers` endpoint.
|
|
27
|
+
*
|
|
28
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}
|
|
29
|
+
*
|
|
30
|
+
* @param options - Configuration options for the Code Interpreter tool
|
|
31
|
+
* @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
36
|
+
*
|
|
37
|
+
* const model = new ChatOpenAI({ model: "gpt-4.1" });
|
|
38
|
+
*
|
|
39
|
+
* // Basic usage with auto container (default 1GB memory)
|
|
40
|
+
* const response = await model.invoke(
|
|
41
|
+
* "Solve the equation 3x + 11 = 14",
|
|
42
|
+
* { tools: [tools.codeInterpreter()] }
|
|
43
|
+
* );
|
|
44
|
+
*
|
|
45
|
+
* // With increased memory limit for larger computations
|
|
46
|
+
* const response = await model.invoke(
|
|
47
|
+
* "Analyze this large dataset and create visualizations",
|
|
48
|
+
* {
|
|
49
|
+
* tools: [tools.codeInterpreter({
|
|
50
|
+
* container: { memoryLimit: "4g" }
|
|
51
|
+
* })]
|
|
52
|
+
* }
|
|
53
|
+
* );
|
|
54
|
+
*
|
|
55
|
+
* // With specific files available to the code
|
|
56
|
+
* const response = await model.invoke(
|
|
57
|
+
* "Process the uploaded CSV file",
|
|
58
|
+
* {
|
|
59
|
+
* tools: [tools.codeInterpreter({
|
|
60
|
+
* container: {
|
|
61
|
+
* memoryLimit: "4g",
|
|
62
|
+
* fileIds: ["file-abc123", "file-def456"]
|
|
63
|
+
* }
|
|
64
|
+
* })]
|
|
65
|
+
* }
|
|
66
|
+
* );
|
|
67
|
+
*
|
|
68
|
+
* // Using an explicit container ID (created via /v1/containers)
|
|
69
|
+
* const response = await model.invoke(
|
|
70
|
+
* "Continue working with the data",
|
|
71
|
+
* {
|
|
72
|
+
* tools: [tools.codeInterpreter({
|
|
73
|
+
* container: "cntr_abc123"
|
|
74
|
+
* })]
|
|
75
|
+
* }
|
|
76
|
+
* );
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* - Containers expire after 20 minutes of inactivity
|
|
81
|
+
* - While called "Code Interpreter", the model knows it as the "python tool"
|
|
82
|
+
* - For explicit prompting, ask for "the python tool" in your prompts
|
|
83
|
+
* - Files in model input are automatically uploaded to the container
|
|
84
|
+
* - Generated files are returned as `container_file_citation` annotations
|
|
85
|
+
*/
|
|
86
|
+
function codeInterpreter(options) {
|
|
87
|
+
return {
|
|
88
|
+
type: "code_interpreter",
|
|
89
|
+
container: convertContainer(options?.container)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
exports.codeInterpreter = codeInterpreter;
|
|
95
|
+
//# sourceMappingURL=codeInterpreter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeInterpreter.cjs","names":["container: string | CodeInterpreterAutoContainer | undefined","options?: CodeInterpreterOptions"],"sources":["../../src/tools/codeInterpreter.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Memory limit options for the Code Interpreter container.\n * Higher tiers offer more RAM and are billed at different rates.\n */\nexport type CodeInterpreterMemoryLimit = \"1g\" | \"4g\" | \"16g\" | \"64g\";\n\n/**\n * Auto container configuration for Code Interpreter.\n * Creates a new container automatically or reuses an active one.\n */\nexport interface CodeInterpreterAutoContainer {\n /**\n * Memory limit for the container.\n * - `\"1g\"` (default): 1 GB RAM\n * - `\"4g\"`: 4 GB RAM\n * - `\"16g\"`: 16 GB RAM\n * - `\"64g\"`: 64 GB RAM\n */\n memoryLimit?: CodeInterpreterMemoryLimit;\n /**\n * Optional list of uploaded file IDs to make available to the code.\n * Files in the model input are automatically uploaded, so this is only\n * needed for additional files.\n */\n fileIds?: string[];\n}\n\n/**\n * Options for the Code Interpreter tool.\n */\nexport interface CodeInterpreterOptions {\n /**\n * The container configuration for the Code Interpreter.\n *\n * Can be either:\n * - A string container ID for explicit mode (created via `/v1/containers` endpoint)\n * - An auto configuration object that creates/reuses containers automatically\n *\n * If not provided, defaults to auto mode with default settings.\n */\n container?: string | CodeInterpreterAutoContainer;\n}\n\n/**\n * OpenAI Code Interpreter tool type for the Responses API.\n */\nexport type CodeInterpreterTool = OpenAIClient.Responses.Tool.CodeInterpreter;\n\n/**\n * Converts container options to the API format.\n */\nfunction convertContainer(\n container: string | CodeInterpreterAutoContainer | undefined\n):\n | string\n | OpenAIClient.Responses.Tool.CodeInterpreter.CodeInterpreterToolAuto {\n // If a string container ID is provided, use it directly\n if (typeof container === \"string\") {\n return container;\n }\n\n // Auto mode configuration\n return {\n type: \"auto\",\n file_ids: container?.fileIds,\n memory_limit: container?.memoryLimit,\n };\n}\n\n/**\n * Creates a Code Interpreter tool that allows models to write and run Python code\n * in a sandboxed environment to solve complex problems.\n *\n * Use Code Interpreter for:\n * - **Data analysis**: Processing files with diverse data and formatting\n * - **File generation**: Creating files with data and images of graphs\n * - **Iterative coding**: Writing and running code iteratively to solve problems\n * - **Visual intelligence**: Cropping, zooming, rotating, and transforming images\n *\n * The tool runs in a container, which is a fully sandboxed virtual machine.\n * Containers can be created automatically (auto mode) or explicitly via the\n * `/v1/containers` endpoint.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}\n *\n * @param options - Configuration options for the Code Interpreter tool\n * @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with auto container (default 1GB memory)\n * const response = await model.invoke(\n * \"Solve the equation 3x + 11 = 14\",\n * { tools: [tools.codeInterpreter()] }\n * );\n *\n * // With increased memory limit for larger computations\n * const response = await model.invoke(\n * \"Analyze this large dataset and create visualizations\",\n * {\n * tools: [tools.codeInterpreter({\n * container: { memoryLimit: \"4g\" }\n * })]\n * }\n * );\n *\n * // With specific files available to the code\n * const response = await model.invoke(\n * \"Process the uploaded CSV file\",\n * {\n * tools: [tools.codeInterpreter({\n * container: {\n * memoryLimit: \"4g\",\n * fileIds: [\"file-abc123\", \"file-def456\"]\n * }\n * })]\n * }\n * );\n *\n * // Using an explicit container ID (created via /v1/containers)\n * const response = await model.invoke(\n * \"Continue working with the data\",\n * {\n * tools: [tools.codeInterpreter({\n * container: \"cntr_abc123\"\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Containers expire after 20 minutes of inactivity\n * - While called \"Code Interpreter\", the model knows it as the \"python tool\"\n * - For explicit prompting, ask for \"the python tool\" in your prompts\n * - Files in model input are automatically uploaded to the container\n * - Generated files are returned as `container_file_citation` annotations\n */\nexport function codeInterpreter(options?: CodeInterpreterOptions): ServerTool {\n return {\n type: \"code_interpreter\",\n container: convertContainer(options?.container),\n } satisfies CodeInterpreterTool;\n}\n"],"mappings":";;;;;AAsDA,SAAS,iBACPA,WAGsE;AAEtE,KAAI,OAAO,cAAc,SACvB,QAAO;AAIT,QAAO;EACL,MAAM;EACN,UAAU,WAAW;EACrB,cAAc,WAAW;CAC1B;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0ED,SAAgB,gBAAgBC,SAA8C;AAC5E,QAAO;EACL,MAAM;EACN,WAAW,iBAAiB,SAAS,UAAU;CAChD;AACF"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { OpenAI as OpenAI$1 } from "openai";
|
|
2
|
+
import { ServerTool } from "@langchain/core/tools";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/codeInterpreter.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Memory limit options for the Code Interpreter container.
|
|
8
|
+
* Higher tiers offer more RAM and are billed at different rates.
|
|
9
|
+
*/
|
|
10
|
+
type CodeInterpreterMemoryLimit = "1g" | "4g" | "16g" | "64g";
|
|
11
|
+
/**
|
|
12
|
+
* Auto container configuration for Code Interpreter.
|
|
13
|
+
* Creates a new container automatically or reuses an active one.
|
|
14
|
+
*/
|
|
15
|
+
interface CodeInterpreterAutoContainer {
|
|
16
|
+
/**
|
|
17
|
+
* Memory limit for the container.
|
|
18
|
+
* - `"1g"` (default): 1 GB RAM
|
|
19
|
+
* - `"4g"`: 4 GB RAM
|
|
20
|
+
* - `"16g"`: 16 GB RAM
|
|
21
|
+
* - `"64g"`: 64 GB RAM
|
|
22
|
+
*/
|
|
23
|
+
memoryLimit?: CodeInterpreterMemoryLimit;
|
|
24
|
+
/**
|
|
25
|
+
* Optional list of uploaded file IDs to make available to the code.
|
|
26
|
+
* Files in the model input are automatically uploaded, so this is only
|
|
27
|
+
* needed for additional files.
|
|
28
|
+
*/
|
|
29
|
+
fileIds?: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for the Code Interpreter tool.
|
|
33
|
+
*/
|
|
34
|
+
interface CodeInterpreterOptions {
|
|
35
|
+
/**
|
|
36
|
+
* The container configuration for the Code Interpreter.
|
|
37
|
+
*
|
|
38
|
+
* Can be either:
|
|
39
|
+
* - A string container ID for explicit mode (created via `/v1/containers` endpoint)
|
|
40
|
+
* - An auto configuration object that creates/reuses containers automatically
|
|
41
|
+
*
|
|
42
|
+
* If not provided, defaults to auto mode with default settings.
|
|
43
|
+
*/
|
|
44
|
+
container?: string | CodeInterpreterAutoContainer;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* OpenAI Code Interpreter tool type for the Responses API.
|
|
48
|
+
*/
|
|
49
|
+
type CodeInterpreterTool = OpenAI$1.Responses.Tool.CodeInterpreter;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a Code Interpreter tool that allows models to write and run Python code
|
|
52
|
+
* in a sandboxed environment to solve complex problems.
|
|
53
|
+
*
|
|
54
|
+
* Use Code Interpreter for:
|
|
55
|
+
* - **Data analysis**: Processing files with diverse data and formatting
|
|
56
|
+
* - **File generation**: Creating files with data and images of graphs
|
|
57
|
+
* - **Iterative coding**: Writing and running code iteratively to solve problems
|
|
58
|
+
* - **Visual intelligence**: Cropping, zooming, rotating, and transforming images
|
|
59
|
+
*
|
|
60
|
+
* The tool runs in a container, which is a fully sandboxed virtual machine.
|
|
61
|
+
* Containers can be created automatically (auto mode) or explicitly via the
|
|
62
|
+
* `/v1/containers` endpoint.
|
|
63
|
+
*
|
|
64
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}
|
|
65
|
+
*
|
|
66
|
+
* @param options - Configuration options for the Code Interpreter tool
|
|
67
|
+
* @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
72
|
+
*
|
|
73
|
+
* const model = new ChatOpenAI({ model: "gpt-4.1" });
|
|
74
|
+
*
|
|
75
|
+
* // Basic usage with auto container (default 1GB memory)
|
|
76
|
+
* const response = await model.invoke(
|
|
77
|
+
* "Solve the equation 3x + 11 = 14",
|
|
78
|
+
* { tools: [tools.codeInterpreter()] }
|
|
79
|
+
* );
|
|
80
|
+
*
|
|
81
|
+
* // With increased memory limit for larger computations
|
|
82
|
+
* const response = await model.invoke(
|
|
83
|
+
* "Analyze this large dataset and create visualizations",
|
|
84
|
+
* {
|
|
85
|
+
* tools: [tools.codeInterpreter({
|
|
86
|
+
* container: { memoryLimit: "4g" }
|
|
87
|
+
* })]
|
|
88
|
+
* }
|
|
89
|
+
* );
|
|
90
|
+
*
|
|
91
|
+
* // With specific files available to the code
|
|
92
|
+
* const response = await model.invoke(
|
|
93
|
+
* "Process the uploaded CSV file",
|
|
94
|
+
* {
|
|
95
|
+
* tools: [tools.codeInterpreter({
|
|
96
|
+
* container: {
|
|
97
|
+
* memoryLimit: "4g",
|
|
98
|
+
* fileIds: ["file-abc123", "file-def456"]
|
|
99
|
+
* }
|
|
100
|
+
* })]
|
|
101
|
+
* }
|
|
102
|
+
* );
|
|
103
|
+
*
|
|
104
|
+
* // Using an explicit container ID (created via /v1/containers)
|
|
105
|
+
* const response = await model.invoke(
|
|
106
|
+
* "Continue working with the data",
|
|
107
|
+
* {
|
|
108
|
+
* tools: [tools.codeInterpreter({
|
|
109
|
+
* container: "cntr_abc123"
|
|
110
|
+
* })]
|
|
111
|
+
* }
|
|
112
|
+
* );
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* - Containers expire after 20 minutes of inactivity
|
|
117
|
+
* - While called "Code Interpreter", the model knows it as the "python tool"
|
|
118
|
+
* - For explicit prompting, ask for "the python tool" in your prompts
|
|
119
|
+
* - Files in model input are automatically uploaded to the container
|
|
120
|
+
* - Generated files are returned as `container_file_citation` annotations
|
|
121
|
+
*/
|
|
122
|
+
declare function codeInterpreter(options?: CodeInterpreterOptions): ServerTool;
|
|
123
|
+
//#endregion
|
|
124
|
+
export { CodeInterpreterAutoContainer, CodeInterpreterMemoryLimit, CodeInterpreterOptions, CodeInterpreterTool, codeInterpreter };
|
|
125
|
+
//# sourceMappingURL=codeInterpreter.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeInterpreter.d.cts","names":["OpenAI","OpenAIClient","ServerTool","CodeInterpreterMemoryLimit","CodeInterpreterAutoContainer","CodeInterpreterOptions","CodeInterpreterTool","Responses","Tool","CodeInterpreter","codeInterpreter"],"sources":["../../src/tools/codeInterpreter.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * Memory limit options for the Code Interpreter container.\n * Higher tiers offer more RAM and are billed at different rates.\n */\nexport type CodeInterpreterMemoryLimit = \"1g\" | \"4g\" | \"16g\" | \"64g\";\n/**\n * Auto container configuration for Code Interpreter.\n * Creates a new container automatically or reuses an active one.\n */\nexport interface CodeInterpreterAutoContainer {\n /**\n * Memory limit for the container.\n * - `\"1g\"` (default): 1 GB RAM\n * - `\"4g\"`: 4 GB RAM\n * - `\"16g\"`: 16 GB RAM\n * - `\"64g\"`: 64 GB RAM\n */\n memoryLimit?: CodeInterpreterMemoryLimit;\n /**\n * Optional list of uploaded file IDs to make available to the code.\n * Files in the model input are automatically uploaded, so this is only\n * needed for additional files.\n */\n fileIds?: string[];\n}\n/**\n * Options for the Code Interpreter tool.\n */\nexport interface CodeInterpreterOptions {\n /**\n * The container configuration for the Code Interpreter.\n *\n * Can be either:\n * - A string container ID for explicit mode (created via `/v1/containers` endpoint)\n * - An auto configuration object that creates/reuses containers automatically\n *\n * If not provided, defaults to auto mode with default settings.\n */\n container?: string | CodeInterpreterAutoContainer;\n}\n/**\n * OpenAI Code Interpreter tool type for the Responses API.\n */\nexport type CodeInterpreterTool = OpenAIClient.Responses.Tool.CodeInterpreter;\n/**\n * Creates a Code Interpreter tool that allows models to write and run Python code\n * in a sandboxed environment to solve complex problems.\n *\n * Use Code Interpreter for:\n * - **Data analysis**: Processing files with diverse data and formatting\n * - **File generation**: Creating files with data and images of graphs\n * - **Iterative coding**: Writing and running code iteratively to solve problems\n * - **Visual intelligence**: Cropping, zooming, rotating, and transforming images\n *\n * The tool runs in a container, which is a fully sandboxed virtual machine.\n * Containers can be created automatically (auto mode) or explicitly via the\n * `/v1/containers` endpoint.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}\n *\n * @param options - Configuration options for the Code Interpreter tool\n * @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with auto container (default 1GB memory)\n * const response = await model.invoke(\n * \"Solve the equation 3x + 11 = 14\",\n * { tools: [tools.codeInterpreter()] }\n * );\n *\n * // With increased memory limit for larger computations\n * const response = await model.invoke(\n * \"Analyze this large dataset and create visualizations\",\n * {\n * tools: [tools.codeInterpreter({\n * container: { memoryLimit: \"4g\" }\n * })]\n * }\n * );\n *\n * // With specific files available to the code\n * const response = await model.invoke(\n * \"Process the uploaded CSV file\",\n * {\n * tools: [tools.codeInterpreter({\n * container: {\n * memoryLimit: \"4g\",\n * fileIds: [\"file-abc123\", \"file-def456\"]\n * }\n * })]\n * }\n * );\n *\n * // Using an explicit container ID (created via /v1/containers)\n * const response = await model.invoke(\n * \"Continue working with the data\",\n * {\n * tools: [tools.codeInterpreter({\n * container: \"cntr_abc123\"\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Containers expire after 20 minutes of inactivity\n * - While called \"Code Interpreter\", the model knows it as the \"python tool\"\n * - For explicit prompting, ask for \"the python tool\" in your prompts\n * - Files in model input are automatically uploaded to the container\n * - Generated files are returned as `container_file_citation` annotations\n */\nexport declare function codeInterpreter(options?: CodeInterpreterOptions): ServerTool;\n//# sourceMappingURL=codeInterpreter.d.ts.map"],"mappings":";;;;;;;AAMA;AAKA;AAmBiBK,KAxBLF,0BAAAA,GAwB2B,IAUdC,GAAAA,IAAAA,GAAAA,KAAAA,GAAAA,KAAAA;AAKzB;AAyEA;;;UA3GiBA,4BAAAA;;;;;;;;gBAQCD;;;;;;;;;;;UAWDE,sBAAAA;;;;;;;;;;uBAUQD;;;;;KAKbE,mBAAAA,GAAsBL,QAAAA,CAAaM,SAAAA,CAAUC,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyEtCC,eAAAA,WAA0BL,yBAAyBH"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { OpenAI as OpenAI$1 } from "openai";
|
|
2
|
+
import { ServerTool } from "@langchain/core/tools";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/codeInterpreter.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Memory limit options for the Code Interpreter container.
|
|
8
|
+
* Higher tiers offer more RAM and are billed at different rates.
|
|
9
|
+
*/
|
|
10
|
+
type CodeInterpreterMemoryLimit = "1g" | "4g" | "16g" | "64g";
|
|
11
|
+
/**
|
|
12
|
+
* Auto container configuration for Code Interpreter.
|
|
13
|
+
* Creates a new container automatically or reuses an active one.
|
|
14
|
+
*/
|
|
15
|
+
interface CodeInterpreterAutoContainer {
|
|
16
|
+
/**
|
|
17
|
+
* Memory limit for the container.
|
|
18
|
+
* - `"1g"` (default): 1 GB RAM
|
|
19
|
+
* - `"4g"`: 4 GB RAM
|
|
20
|
+
* - `"16g"`: 16 GB RAM
|
|
21
|
+
* - `"64g"`: 64 GB RAM
|
|
22
|
+
*/
|
|
23
|
+
memoryLimit?: CodeInterpreterMemoryLimit;
|
|
24
|
+
/**
|
|
25
|
+
* Optional list of uploaded file IDs to make available to the code.
|
|
26
|
+
* Files in the model input are automatically uploaded, so this is only
|
|
27
|
+
* needed for additional files.
|
|
28
|
+
*/
|
|
29
|
+
fileIds?: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for the Code Interpreter tool.
|
|
33
|
+
*/
|
|
34
|
+
interface CodeInterpreterOptions {
|
|
35
|
+
/**
|
|
36
|
+
* The container configuration for the Code Interpreter.
|
|
37
|
+
*
|
|
38
|
+
* Can be either:
|
|
39
|
+
* - A string container ID for explicit mode (created via `/v1/containers` endpoint)
|
|
40
|
+
* - An auto configuration object that creates/reuses containers automatically
|
|
41
|
+
*
|
|
42
|
+
* If not provided, defaults to auto mode with default settings.
|
|
43
|
+
*/
|
|
44
|
+
container?: string | CodeInterpreterAutoContainer;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* OpenAI Code Interpreter tool type for the Responses API.
|
|
48
|
+
*/
|
|
49
|
+
type CodeInterpreterTool = OpenAI$1.Responses.Tool.CodeInterpreter;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a Code Interpreter tool that allows models to write and run Python code
|
|
52
|
+
* in a sandboxed environment to solve complex problems.
|
|
53
|
+
*
|
|
54
|
+
* Use Code Interpreter for:
|
|
55
|
+
* - **Data analysis**: Processing files with diverse data and formatting
|
|
56
|
+
* - **File generation**: Creating files with data and images of graphs
|
|
57
|
+
* - **Iterative coding**: Writing and running code iteratively to solve problems
|
|
58
|
+
* - **Visual intelligence**: Cropping, zooming, rotating, and transforming images
|
|
59
|
+
*
|
|
60
|
+
* The tool runs in a container, which is a fully sandboxed virtual machine.
|
|
61
|
+
* Containers can be created automatically (auto mode) or explicitly via the
|
|
62
|
+
* `/v1/containers` endpoint.
|
|
63
|
+
*
|
|
64
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}
|
|
65
|
+
*
|
|
66
|
+
* @param options - Configuration options for the Code Interpreter tool
|
|
67
|
+
* @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
72
|
+
*
|
|
73
|
+
* const model = new ChatOpenAI({ model: "gpt-4.1" });
|
|
74
|
+
*
|
|
75
|
+
* // Basic usage with auto container (default 1GB memory)
|
|
76
|
+
* const response = await model.invoke(
|
|
77
|
+
* "Solve the equation 3x + 11 = 14",
|
|
78
|
+
* { tools: [tools.codeInterpreter()] }
|
|
79
|
+
* );
|
|
80
|
+
*
|
|
81
|
+
* // With increased memory limit for larger computations
|
|
82
|
+
* const response = await model.invoke(
|
|
83
|
+
* "Analyze this large dataset and create visualizations",
|
|
84
|
+
* {
|
|
85
|
+
* tools: [tools.codeInterpreter({
|
|
86
|
+
* container: { memoryLimit: "4g" }
|
|
87
|
+
* })]
|
|
88
|
+
* }
|
|
89
|
+
* );
|
|
90
|
+
*
|
|
91
|
+
* // With specific files available to the code
|
|
92
|
+
* const response = await model.invoke(
|
|
93
|
+
* "Process the uploaded CSV file",
|
|
94
|
+
* {
|
|
95
|
+
* tools: [tools.codeInterpreter({
|
|
96
|
+
* container: {
|
|
97
|
+
* memoryLimit: "4g",
|
|
98
|
+
* fileIds: ["file-abc123", "file-def456"]
|
|
99
|
+
* }
|
|
100
|
+
* })]
|
|
101
|
+
* }
|
|
102
|
+
* );
|
|
103
|
+
*
|
|
104
|
+
* // Using an explicit container ID (created via /v1/containers)
|
|
105
|
+
* const response = await model.invoke(
|
|
106
|
+
* "Continue working with the data",
|
|
107
|
+
* {
|
|
108
|
+
* tools: [tools.codeInterpreter({
|
|
109
|
+
* container: "cntr_abc123"
|
|
110
|
+
* })]
|
|
111
|
+
* }
|
|
112
|
+
* );
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* - Containers expire after 20 minutes of inactivity
|
|
117
|
+
* - While called "Code Interpreter", the model knows it as the "python tool"
|
|
118
|
+
* - For explicit prompting, ask for "the python tool" in your prompts
|
|
119
|
+
* - Files in model input are automatically uploaded to the container
|
|
120
|
+
* - Generated files are returned as `container_file_citation` annotations
|
|
121
|
+
*/
|
|
122
|
+
declare function codeInterpreter(options?: CodeInterpreterOptions): ServerTool;
|
|
123
|
+
//#endregion
|
|
124
|
+
export { CodeInterpreterAutoContainer, CodeInterpreterMemoryLimit, CodeInterpreterOptions, CodeInterpreterTool, codeInterpreter };
|
|
125
|
+
//# sourceMappingURL=codeInterpreter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeInterpreter.d.ts","names":["OpenAI","OpenAIClient","ServerTool","CodeInterpreterMemoryLimit","CodeInterpreterAutoContainer","CodeInterpreterOptions","CodeInterpreterTool","Responses","Tool","CodeInterpreter","codeInterpreter"],"sources":["../../src/tools/codeInterpreter.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * Memory limit options for the Code Interpreter container.\n * Higher tiers offer more RAM and are billed at different rates.\n */\nexport type CodeInterpreterMemoryLimit = \"1g\" | \"4g\" | \"16g\" | \"64g\";\n/**\n * Auto container configuration for Code Interpreter.\n * Creates a new container automatically or reuses an active one.\n */\nexport interface CodeInterpreterAutoContainer {\n /**\n * Memory limit for the container.\n * - `\"1g\"` (default): 1 GB RAM\n * - `\"4g\"`: 4 GB RAM\n * - `\"16g\"`: 16 GB RAM\n * - `\"64g\"`: 64 GB RAM\n */\n memoryLimit?: CodeInterpreterMemoryLimit;\n /**\n * Optional list of uploaded file IDs to make available to the code.\n * Files in the model input are automatically uploaded, so this is only\n * needed for additional files.\n */\n fileIds?: string[];\n}\n/**\n * Options for the Code Interpreter tool.\n */\nexport interface CodeInterpreterOptions {\n /**\n * The container configuration for the Code Interpreter.\n *\n * Can be either:\n * - A string container ID for explicit mode (created via `/v1/containers` endpoint)\n * - An auto configuration object that creates/reuses containers automatically\n *\n * If not provided, defaults to auto mode with default settings.\n */\n container?: string | CodeInterpreterAutoContainer;\n}\n/**\n * OpenAI Code Interpreter tool type for the Responses API.\n */\nexport type CodeInterpreterTool = OpenAIClient.Responses.Tool.CodeInterpreter;\n/**\n * Creates a Code Interpreter tool that allows models to write and run Python code\n * in a sandboxed environment to solve complex problems.\n *\n * Use Code Interpreter for:\n * - **Data analysis**: Processing files with diverse data and formatting\n * - **File generation**: Creating files with data and images of graphs\n * - **Iterative coding**: Writing and running code iteratively to solve problems\n * - **Visual intelligence**: Cropping, zooming, rotating, and transforming images\n *\n * The tool runs in a container, which is a fully sandboxed virtual machine.\n * Containers can be created automatically (auto mode) or explicitly via the\n * `/v1/containers` endpoint.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}\n *\n * @param options - Configuration options for the Code Interpreter tool\n * @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with auto container (default 1GB memory)\n * const response = await model.invoke(\n * \"Solve the equation 3x + 11 = 14\",\n * { tools: [tools.codeInterpreter()] }\n * );\n *\n * // With increased memory limit for larger computations\n * const response = await model.invoke(\n * \"Analyze this large dataset and create visualizations\",\n * {\n * tools: [tools.codeInterpreter({\n * container: { memoryLimit: \"4g\" }\n * })]\n * }\n * );\n *\n * // With specific files available to the code\n * const response = await model.invoke(\n * \"Process the uploaded CSV file\",\n * {\n * tools: [tools.codeInterpreter({\n * container: {\n * memoryLimit: \"4g\",\n * fileIds: [\"file-abc123\", \"file-def456\"]\n * }\n * })]\n * }\n * );\n *\n * // Using an explicit container ID (created via /v1/containers)\n * const response = await model.invoke(\n * \"Continue working with the data\",\n * {\n * tools: [tools.codeInterpreter({\n * container: \"cntr_abc123\"\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Containers expire after 20 minutes of inactivity\n * - While called \"Code Interpreter\", the model knows it as the \"python tool\"\n * - For explicit prompting, ask for \"the python tool\" in your prompts\n * - Files in model input are automatically uploaded to the container\n * - Generated files are returned as `container_file_citation` annotations\n */\nexport declare function codeInterpreter(options?: CodeInterpreterOptions): ServerTool;\n//# sourceMappingURL=codeInterpreter.d.ts.map"],"mappings":";;;;;;;AAMA;AAKA;AAmBiBK,KAxBLF,0BAAAA,GAwB2B,IAUdC,GAAAA,IAAAA,GAAAA,KAAAA,GAAAA,KAAAA;AAKzB;AAyEA;;;UA3GiBA,4BAAAA;;;;;;;;gBAQCD;;;;;;;;;;;UAWDE,sBAAAA;;;;;;;;;;uBAUQD;;;;;KAKbE,mBAAAA,GAAsBL,QAAAA,CAAaM,SAAAA,CAAUC,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyEtCC,eAAAA,WAA0BL,yBAAyBH"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//#region src/tools/codeInterpreter.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts container options to the API format.
|
|
4
|
+
*/
|
|
5
|
+
function convertContainer(container) {
|
|
6
|
+
if (typeof container === "string") return container;
|
|
7
|
+
return {
|
|
8
|
+
type: "auto",
|
|
9
|
+
file_ids: container?.fileIds,
|
|
10
|
+
memory_limit: container?.memoryLimit
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a Code Interpreter tool that allows models to write and run Python code
|
|
15
|
+
* in a sandboxed environment to solve complex problems.
|
|
16
|
+
*
|
|
17
|
+
* Use Code Interpreter for:
|
|
18
|
+
* - **Data analysis**: Processing files with diverse data and formatting
|
|
19
|
+
* - **File generation**: Creating files with data and images of graphs
|
|
20
|
+
* - **Iterative coding**: Writing and running code iteratively to solve problems
|
|
21
|
+
* - **Visual intelligence**: Cropping, zooming, rotating, and transforming images
|
|
22
|
+
*
|
|
23
|
+
* The tool runs in a container, which is a fully sandboxed virtual machine.
|
|
24
|
+
* Containers can be created automatically (auto mode) or explicitly via the
|
|
25
|
+
* `/v1/containers` endpoint.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}
|
|
28
|
+
*
|
|
29
|
+
* @param options - Configuration options for the Code Interpreter tool
|
|
30
|
+
* @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
35
|
+
*
|
|
36
|
+
* const model = new ChatOpenAI({ model: "gpt-4.1" });
|
|
37
|
+
*
|
|
38
|
+
* // Basic usage with auto container (default 1GB memory)
|
|
39
|
+
* const response = await model.invoke(
|
|
40
|
+
* "Solve the equation 3x + 11 = 14",
|
|
41
|
+
* { tools: [tools.codeInterpreter()] }
|
|
42
|
+
* );
|
|
43
|
+
*
|
|
44
|
+
* // With increased memory limit for larger computations
|
|
45
|
+
* const response = await model.invoke(
|
|
46
|
+
* "Analyze this large dataset and create visualizations",
|
|
47
|
+
* {
|
|
48
|
+
* tools: [tools.codeInterpreter({
|
|
49
|
+
* container: { memoryLimit: "4g" }
|
|
50
|
+
* })]
|
|
51
|
+
* }
|
|
52
|
+
* );
|
|
53
|
+
*
|
|
54
|
+
* // With specific files available to the code
|
|
55
|
+
* const response = await model.invoke(
|
|
56
|
+
* "Process the uploaded CSV file",
|
|
57
|
+
* {
|
|
58
|
+
* tools: [tools.codeInterpreter({
|
|
59
|
+
* container: {
|
|
60
|
+
* memoryLimit: "4g",
|
|
61
|
+
* fileIds: ["file-abc123", "file-def456"]
|
|
62
|
+
* }
|
|
63
|
+
* })]
|
|
64
|
+
* }
|
|
65
|
+
* );
|
|
66
|
+
*
|
|
67
|
+
* // Using an explicit container ID (created via /v1/containers)
|
|
68
|
+
* const response = await model.invoke(
|
|
69
|
+
* "Continue working with the data",
|
|
70
|
+
* {
|
|
71
|
+
* tools: [tools.codeInterpreter({
|
|
72
|
+
* container: "cntr_abc123"
|
|
73
|
+
* })]
|
|
74
|
+
* }
|
|
75
|
+
* );
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* - Containers expire after 20 minutes of inactivity
|
|
80
|
+
* - While called "Code Interpreter", the model knows it as the "python tool"
|
|
81
|
+
* - For explicit prompting, ask for "the python tool" in your prompts
|
|
82
|
+
* - Files in model input are automatically uploaded to the container
|
|
83
|
+
* - Generated files are returned as `container_file_citation` annotations
|
|
84
|
+
*/
|
|
85
|
+
function codeInterpreter(options) {
|
|
86
|
+
return {
|
|
87
|
+
type: "code_interpreter",
|
|
88
|
+
container: convertContainer(options?.container)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
export { codeInterpreter };
|
|
94
|
+
//# sourceMappingURL=codeInterpreter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeInterpreter.js","names":["container: string | CodeInterpreterAutoContainer | undefined","options?: CodeInterpreterOptions"],"sources":["../../src/tools/codeInterpreter.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Memory limit options for the Code Interpreter container.\n * Higher tiers offer more RAM and are billed at different rates.\n */\nexport type CodeInterpreterMemoryLimit = \"1g\" | \"4g\" | \"16g\" | \"64g\";\n\n/**\n * Auto container configuration for Code Interpreter.\n * Creates a new container automatically or reuses an active one.\n */\nexport interface CodeInterpreterAutoContainer {\n /**\n * Memory limit for the container.\n * - `\"1g\"` (default): 1 GB RAM\n * - `\"4g\"`: 4 GB RAM\n * - `\"16g\"`: 16 GB RAM\n * - `\"64g\"`: 64 GB RAM\n */\n memoryLimit?: CodeInterpreterMemoryLimit;\n /**\n * Optional list of uploaded file IDs to make available to the code.\n * Files in the model input are automatically uploaded, so this is only\n * needed for additional files.\n */\n fileIds?: string[];\n}\n\n/**\n * Options for the Code Interpreter tool.\n */\nexport interface CodeInterpreterOptions {\n /**\n * The container configuration for the Code Interpreter.\n *\n * Can be either:\n * - A string container ID for explicit mode (created via `/v1/containers` endpoint)\n * - An auto configuration object that creates/reuses containers automatically\n *\n * If not provided, defaults to auto mode with default settings.\n */\n container?: string | CodeInterpreterAutoContainer;\n}\n\n/**\n * OpenAI Code Interpreter tool type for the Responses API.\n */\nexport type CodeInterpreterTool = OpenAIClient.Responses.Tool.CodeInterpreter;\n\n/**\n * Converts container options to the API format.\n */\nfunction convertContainer(\n container: string | CodeInterpreterAutoContainer | undefined\n):\n | string\n | OpenAIClient.Responses.Tool.CodeInterpreter.CodeInterpreterToolAuto {\n // If a string container ID is provided, use it directly\n if (typeof container === \"string\") {\n return container;\n }\n\n // Auto mode configuration\n return {\n type: \"auto\",\n file_ids: container?.fileIds,\n memory_limit: container?.memoryLimit,\n };\n}\n\n/**\n * Creates a Code Interpreter tool that allows models to write and run Python code\n * in a sandboxed environment to solve complex problems.\n *\n * Use Code Interpreter for:\n * - **Data analysis**: Processing files with diverse data and formatting\n * - **File generation**: Creating files with data and images of graphs\n * - **Iterative coding**: Writing and running code iteratively to solve problems\n * - **Visual intelligence**: Cropping, zooming, rotating, and transforming images\n *\n * The tool runs in a container, which is a fully sandboxed virtual machine.\n * Containers can be created automatically (auto mode) or explicitly via the\n * `/v1/containers` endpoint.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-code-interpreter | OpenAI Code Interpreter Documentation}\n *\n * @param options - Configuration options for the Code Interpreter tool\n * @returns A Code Interpreter tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with auto container (default 1GB memory)\n * const response = await model.invoke(\n * \"Solve the equation 3x + 11 = 14\",\n * { tools: [tools.codeInterpreter()] }\n * );\n *\n * // With increased memory limit for larger computations\n * const response = await model.invoke(\n * \"Analyze this large dataset and create visualizations\",\n * {\n * tools: [tools.codeInterpreter({\n * container: { memoryLimit: \"4g\" }\n * })]\n * }\n * );\n *\n * // With specific files available to the code\n * const response = await model.invoke(\n * \"Process the uploaded CSV file\",\n * {\n * tools: [tools.codeInterpreter({\n * container: {\n * memoryLimit: \"4g\",\n * fileIds: [\"file-abc123\", \"file-def456\"]\n * }\n * })]\n * }\n * );\n *\n * // Using an explicit container ID (created via /v1/containers)\n * const response = await model.invoke(\n * \"Continue working with the data\",\n * {\n * tools: [tools.codeInterpreter({\n * container: \"cntr_abc123\"\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Containers expire after 20 minutes of inactivity\n * - While called \"Code Interpreter\", the model knows it as the \"python tool\"\n * - For explicit prompting, ask for \"the python tool\" in your prompts\n * - Files in model input are automatically uploaded to the container\n * - Generated files are returned as `container_file_citation` annotations\n */\nexport function codeInterpreter(options?: CodeInterpreterOptions): ServerTool {\n return {\n type: \"code_interpreter\",\n container: convertContainer(options?.container),\n } satisfies CodeInterpreterTool;\n}\n"],"mappings":";;;;AAsDA,SAAS,iBACPA,WAGsE;AAEtE,KAAI,OAAO,cAAc,SACvB,QAAO;AAIT,QAAO;EACL,MAAM;EACN,UAAU,WAAW;EACrB,cAAc,WAAW;CAC1B;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0ED,SAAgB,gBAAgBC,SAA8C;AAC5E,QAAO;EACL,MAAM;EACN,WAAW,iBAAiB,SAAS,UAAU;CAChD;AACF"}
|