@langchain/openai 1.1.3 → 1.2.0-dev-1765432861398

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 (204) hide show
  1. package/README.md +583 -2
  2. package/dist/azure/chat_models/common.d.cts.map +1 -0
  3. package/dist/azure/chat_models/common.d.ts.map +1 -0
  4. package/dist/azure/chat_models/completions.d.cts.map +1 -0
  5. package/dist/azure/chat_models/completions.d.ts.map +1 -0
  6. package/dist/azure/chat_models/index.d.cts +1 -1
  7. package/dist/azure/chat_models/index.d.cts.map +1 -0
  8. package/dist/azure/chat_models/index.d.ts.map +1 -0
  9. package/dist/azure/chat_models/responses.d.cts.map +1 -0
  10. package/dist/azure/chat_models/responses.d.ts.map +1 -0
  11. package/dist/azure/embeddings.d.cts.map +1 -0
  12. package/dist/azure/embeddings.d.ts.map +1 -0
  13. package/dist/azure/llms.d.cts +0 -1
  14. package/dist/azure/llms.d.cts.map +1 -0
  15. package/dist/azure/llms.d.ts +0 -1
  16. package/dist/azure/llms.d.ts.map +1 -0
  17. package/dist/chat_models/base.cjs +5 -1
  18. package/dist/chat_models/base.cjs.map +1 -1
  19. package/dist/chat_models/base.d.cts +8 -22
  20. package/dist/chat_models/base.d.cts.map +1 -0
  21. package/dist/chat_models/base.d.ts +6 -20
  22. package/dist/chat_models/base.d.ts.map +1 -0
  23. package/dist/chat_models/base.js +6 -2
  24. package/dist/chat_models/base.js.map +1 -1
  25. package/dist/chat_models/completions.cjs.map +1 -1
  26. package/dist/chat_models/completions.d.cts +1 -3
  27. package/dist/chat_models/completions.d.cts.map +1 -0
  28. package/dist/chat_models/completions.d.ts +1 -3
  29. package/dist/chat_models/completions.d.ts.map +1 -0
  30. package/dist/chat_models/completions.js.map +1 -1
  31. package/dist/chat_models/index.d.cts +42 -4
  32. package/dist/chat_models/index.d.cts.map +1 -0
  33. package/dist/chat_models/index.d.ts +42 -4
  34. package/dist/chat_models/index.d.ts.map +1 -0
  35. package/dist/chat_models/responses.d.cts +2 -2
  36. package/dist/chat_models/responses.d.cts.map +1 -0
  37. package/dist/chat_models/responses.d.ts +2 -2
  38. package/dist/chat_models/responses.d.ts.map +1 -0
  39. package/dist/converters/completions.cjs +22 -12
  40. package/dist/converters/completions.cjs.map +1 -1
  41. package/dist/converters/completions.d.cts +0 -1
  42. package/dist/converters/completions.d.cts.map +1 -0
  43. package/dist/converters/completions.d.ts +0 -1
  44. package/dist/converters/completions.d.ts.map +1 -0
  45. package/dist/converters/completions.js +23 -13
  46. package/dist/converters/completions.js.map +1 -1
  47. package/dist/converters/responses.cjs +37 -4
  48. package/dist/converters/responses.cjs.map +1 -1
  49. package/dist/converters/responses.d.cts.map +1 -0
  50. package/dist/converters/responses.d.ts.map +1 -0
  51. package/dist/converters/responses.js +39 -6
  52. package/dist/converters/responses.js.map +1 -1
  53. package/dist/embeddings.d.cts +0 -1
  54. package/dist/embeddings.d.cts.map +1 -0
  55. package/dist/embeddings.d.ts +0 -1
  56. package/dist/embeddings.d.ts.map +1 -0
  57. package/dist/index.cjs +2 -1
  58. package/dist/index.d.cts +12 -2
  59. package/dist/index.d.ts +12 -3
  60. package/dist/index.js +2 -2
  61. package/dist/llms.d.cts +0 -1
  62. package/dist/llms.d.cts.map +1 -0
  63. package/dist/llms.d.ts +0 -1
  64. package/dist/llms.d.ts.map +1 -0
  65. package/dist/tools/applyPatch.cjs +116 -0
  66. package/dist/tools/applyPatch.cjs.map +1 -0
  67. package/dist/tools/applyPatch.d.cts +148 -0
  68. package/dist/tools/applyPatch.d.cts.map +1 -0
  69. package/dist/tools/applyPatch.d.ts +148 -0
  70. package/dist/tools/applyPatch.d.ts.map +1 -0
  71. package/dist/tools/applyPatch.js +115 -0
  72. package/dist/tools/applyPatch.js.map +1 -0
  73. package/dist/tools/codeInterpreter.cjs +95 -0
  74. package/dist/tools/codeInterpreter.cjs.map +1 -0
  75. package/dist/tools/codeInterpreter.d.cts +125 -0
  76. package/dist/tools/codeInterpreter.d.cts.map +1 -0
  77. package/dist/tools/codeInterpreter.d.ts +125 -0
  78. package/dist/tools/codeInterpreter.d.ts.map +1 -0
  79. package/dist/tools/codeInterpreter.js +94 -0
  80. package/dist/tools/codeInterpreter.js.map +1 -0
  81. package/dist/tools/computerUse.cjs +240 -0
  82. package/dist/tools/computerUse.cjs.map +1 -0
  83. package/dist/tools/computerUse.d.cts +234 -0
  84. package/dist/tools/computerUse.d.cts.map +1 -0
  85. package/dist/tools/computerUse.d.ts +234 -0
  86. package/dist/tools/computerUse.d.ts.map +1 -0
  87. package/dist/tools/computerUse.js +239 -0
  88. package/dist/tools/computerUse.js.map +1 -0
  89. package/dist/tools/custom.d.cts +1 -1
  90. package/dist/tools/custom.d.cts.map +1 -0
  91. package/dist/tools/custom.d.ts.map +1 -0
  92. package/dist/tools/dalle.d.cts +1 -2
  93. package/dist/tools/dalle.d.cts.map +1 -0
  94. package/dist/tools/dalle.d.ts +1 -2
  95. package/dist/tools/dalle.d.ts.map +1 -0
  96. package/dist/tools/fileSearch.cjs +137 -0
  97. package/dist/tools/fileSearch.cjs.map +1 -0
  98. package/dist/tools/fileSearch.d.cts +224 -0
  99. package/dist/tools/fileSearch.d.cts.map +1 -0
  100. package/dist/tools/fileSearch.d.ts +224 -0
  101. package/dist/tools/fileSearch.d.ts.map +1 -0
  102. package/dist/tools/fileSearch.js +136 -0
  103. package/dist/tools/fileSearch.js.map +1 -0
  104. package/dist/tools/imageGeneration.cjs +128 -0
  105. package/dist/tools/imageGeneration.cjs.map +1 -0
  106. package/dist/tools/imageGeneration.d.cts +199 -0
  107. package/dist/tools/imageGeneration.d.cts.map +1 -0
  108. package/dist/tools/imageGeneration.d.ts +199 -0
  109. package/dist/tools/imageGeneration.d.ts.map +1 -0
  110. package/dist/tools/imageGeneration.js +127 -0
  111. package/dist/tools/imageGeneration.js.map +1 -0
  112. package/dist/tools/index.cjs +26 -0
  113. package/dist/tools/index.cjs.map +1 -0
  114. package/dist/tools/index.d.cts +27 -0
  115. package/dist/tools/index.d.cts.map +1 -0
  116. package/dist/tools/index.d.ts +27 -1
  117. package/dist/tools/index.d.ts.map +1 -0
  118. package/dist/tools/index.js +26 -0
  119. package/dist/tools/index.js.map +1 -0
  120. package/dist/tools/localShell.cjs +145 -0
  121. package/dist/tools/localShell.cjs.map +1 -0
  122. package/dist/tools/localShell.d.cts +167 -0
  123. package/dist/tools/localShell.d.cts.map +1 -0
  124. package/dist/tools/localShell.d.ts +167 -0
  125. package/dist/tools/localShell.d.ts.map +1 -0
  126. package/dist/tools/localShell.js +144 -0
  127. package/dist/tools/localShell.js.map +1 -0
  128. package/dist/tools/mcp.cjs +53 -0
  129. package/dist/tools/mcp.cjs.map +1 -0
  130. package/dist/tools/mcp.d.cts +177 -0
  131. package/dist/tools/mcp.d.cts.map +1 -0
  132. package/dist/tools/mcp.d.ts +177 -0
  133. package/dist/tools/mcp.d.ts.map +1 -0
  134. package/dist/tools/mcp.js +52 -0
  135. package/dist/tools/mcp.js.map +1 -0
  136. package/dist/tools/shell.cjs +163 -0
  137. package/dist/tools/shell.cjs.map +1 -0
  138. package/dist/tools/shell.d.cts +221 -0
  139. package/dist/tools/shell.d.cts.map +1 -0
  140. package/dist/tools/shell.d.ts +221 -0
  141. package/dist/tools/shell.d.ts.map +1 -0
  142. package/dist/tools/shell.js +162 -0
  143. package/dist/tools/shell.js.map +1 -0
  144. package/dist/tools/webSearch.cjs +73 -0
  145. package/dist/tools/webSearch.cjs.map +1 -0
  146. package/dist/tools/webSearch.d.cts +130 -0
  147. package/dist/tools/webSearch.d.cts.map +1 -0
  148. package/dist/tools/webSearch.d.ts +130 -0
  149. package/dist/tools/webSearch.d.ts.map +1 -0
  150. package/dist/tools/webSearch.js +72 -0
  151. package/dist/tools/webSearch.js.map +1 -0
  152. package/dist/types.d.cts +2 -4
  153. package/dist/types.d.cts.map +1 -0
  154. package/dist/types.d.ts +1 -3
  155. package/dist/types.d.ts.map +1 -0
  156. package/dist/utils/azure.d.cts +1 -5
  157. package/dist/utils/azure.d.cts.map +1 -0
  158. package/dist/utils/azure.d.ts +1 -5
  159. package/dist/utils/azure.d.ts.map +1 -0
  160. package/dist/utils/client.d.cts.map +1 -0
  161. package/dist/utils/client.d.ts.map +1 -0
  162. package/dist/utils/misc.cjs +6 -0
  163. package/dist/utils/misc.cjs.map +1 -1
  164. package/dist/utils/misc.d.cts +1 -1
  165. package/dist/utils/misc.d.cts.map +1 -0
  166. package/dist/utils/misc.d.ts +1 -1
  167. package/dist/utils/misc.d.ts.map +1 -0
  168. package/dist/utils/misc.js +6 -1
  169. package/dist/utils/misc.js.map +1 -1
  170. package/dist/utils/prompts.d.cts +0 -1
  171. package/dist/utils/prompts.d.cts.map +1 -0
  172. package/dist/utils/prompts.d.ts +0 -1
  173. package/dist/utils/prompts.d.ts.map +1 -0
  174. package/dist/utils/tools.cjs +39 -1
  175. package/dist/utils/tools.cjs.map +1 -1
  176. package/dist/utils/tools.d.cts.map +1 -0
  177. package/dist/utils/tools.d.ts.map +1 -0
  178. package/dist/utils/tools.js +37 -2
  179. package/dist/utils/tools.js.map +1 -1
  180. package/package.json +8 -6
  181. package/dist/langchain-core/dist/callbacks/base.d.ts +0 -1
  182. package/dist/langchain-core/dist/callbacks/manager.d.ts +0 -2
  183. package/dist/langchain-core/dist/documents/transformers.d.ts +0 -2
  184. package/dist/langchain-core/dist/language_models/base.d.ts +0 -7
  185. package/dist/langchain-core/dist/language_models/chat_models.d.cts +0 -13
  186. package/dist/langchain-core/dist/language_models/chat_models.d.ts +0 -23
  187. package/dist/langchain-core/dist/messages/index.d.ts +0 -1
  188. package/dist/langchain-core/dist/messages/transformers.d.ts +0 -3
  189. package/dist/langchain-core/dist/runnables/base.d.ts +0 -7
  190. package/dist/langchain-core/dist/runnables/config.d.ts +0 -2
  191. package/dist/langchain-core/dist/runnables/graph.d.ts +0 -1
  192. package/dist/langchain-core/dist/runnables/types.d.ts +0 -2
  193. package/dist/langchain-core/dist/tools/index.d.ts +0 -8
  194. package/dist/langchain-core/dist/tools/types.d.ts +0 -7
  195. package/dist/langchain-core/dist/tracers/base.d.ts +0 -2
  196. package/dist/langchain-core/dist/tracers/event_stream.d.ts +0 -2
  197. package/dist/langchain-core/dist/tracers/log_stream.d.ts +0 -3
  198. package/dist/langchain-core/dist/types/_internal.d.cts +0 -11
  199. package/dist/langchain-core/dist/types/_internal.d.ts +0 -11
  200. package/dist/langchain-core/dist/utils/json_schema.d.ts +0 -1
  201. package/dist/langchain-core/dist/utils/stream.d.cts +0 -26
  202. package/dist/langchain-core/dist/utils/stream.d.ts +0 -26
  203. package/dist/langchain-core/dist/utils/types/index.d.ts +0 -1
  204. package/dist/langchain-core/dist/utils/types/zod.d.ts +0 -1
package/README.md CHANGED
@@ -70,6 +70,587 @@ const model = new ChatOpenAI({
70
70
  const response = await model.stream(new HumanMessage("Hello world!"));
71
71
  ```
72
72
 
73
+ ## Tools
74
+
75
+ This package provides LangChain-compatible wrappers for OpenAI's built-in tools for the Responses API.
76
+
77
+ ### Web Search Tool
78
+
79
+ The web search tool allows OpenAI models to search the web for up-to-date information before generating a response. Web search supports three main types:
80
+
81
+ 1. **Non-reasoning web search**: Quick lookups where the model passes queries directly to the search tool
82
+ 2. **Agentic search with reasoning models**: The model actively manages the search process, analyzing results and deciding whether to keep searching
83
+ 3. **Deep research**: Extended investigations using models like `o3-deep-research` or `gpt-5` with high reasoning effort
84
+
85
+ ```typescript
86
+ import { ChatOpenAI, tools } from "@langchain/openai";
87
+
88
+ const model = new ChatOpenAI({
89
+ model: "gpt-4o",
90
+ });
91
+
92
+ // Basic usage
93
+ const response = await model.invoke(
94
+ "What was a positive news story from today?",
95
+ {
96
+ tools: [tools.webSearch()],
97
+ }
98
+ );
99
+ ```
100
+
101
+ **Domain filtering** - Limit search results to specific domains (up to 100):
102
+
103
+ ```typescript
104
+ const response = await model.invoke("Latest AI research news", {
105
+ tools: [
106
+ tools.webSearch({
107
+ filters: {
108
+ allowedDomains: ["arxiv.org", "nature.com", "science.org"],
109
+ },
110
+ }),
111
+ ],
112
+ });
113
+ ```
114
+
115
+ **User location** - Refine search results based on geography:
116
+
117
+ ```typescript
118
+ const response = await model.invoke("What are the best restaurants near me?", {
119
+ tools: [
120
+ tools.webSearch({
121
+ userLocation: {
122
+ type: "approximate",
123
+ country: "US",
124
+ city: "San Francisco",
125
+ region: "California",
126
+ timezone: "America/Los_Angeles",
127
+ },
128
+ }),
129
+ ],
130
+ });
131
+ ```
132
+
133
+ **Cache-only mode** - Disable live internet access:
134
+
135
+ ```typescript
136
+ const response = await model.invoke("Find information about OpenAI", {
137
+ tools: [
138
+ tools.webSearch({
139
+ externalWebAccess: false,
140
+ }),
141
+ ],
142
+ });
143
+ ```
144
+
145
+ For more information, see [OpenAI's Web Search Documentation](https://platform.openai.com/docs/guides/tools-web-search).
146
+
147
+ ### MCP Tool (Model Context Protocol)
148
+
149
+ The MCP tool allows OpenAI models to connect to remote MCP servers and OpenAI-maintained service connectors, giving models access to external tools and services.
150
+
151
+ There are two ways to use MCP tools:
152
+
153
+ 1. **Remote MCP servers**: Connect to any public MCP server via URL
154
+ 2. **Connectors**: Use OpenAI-maintained wrappers for popular services like Google Workspace or Dropbox
155
+
156
+ **Remote MCP server** - Connect to any MCP-compatible server:
157
+
158
+ ```typescript
159
+ import { ChatOpenAI, tools } from "@langchain/openai";
160
+
161
+ const model = new ChatOpenAI({ model: "gpt-4o" });
162
+
163
+ const response = await model.invoke("Roll 2d4+1", {
164
+ tools: [
165
+ tools.mcp({
166
+ serverLabel: "dmcp",
167
+ serverDescription: "A D&D MCP server for dice rolling",
168
+ serverUrl: "https://dmcp-server.deno.dev/sse",
169
+ requireApproval: "never",
170
+ }),
171
+ ],
172
+ });
173
+ ```
174
+
175
+ **Service connectors** - Use OpenAI-maintained connectors for popular services:
176
+
177
+ ```typescript
178
+ const response = await model.invoke("What's on my calendar today?", {
179
+ tools: [
180
+ tools.mcp({
181
+ serverLabel: "google_calendar",
182
+ connectorId: "connector_googlecalendar",
183
+ authorization: "<oauth-access-token>",
184
+ requireApproval: "never",
185
+ }),
186
+ ],
187
+ });
188
+ ```
189
+
190
+ For more information, see [OpenAI's MCP Documentation](https://platform.openai.com/docs/guides/tools-remote-mcp).
191
+
192
+ ### Code Interpreter Tool
193
+
194
+ The Code Interpreter tool allows models to write and run Python code in a sandboxed environment to solve complex problems.
195
+
196
+ Use Code Interpreter for:
197
+
198
+ - **Data analysis**: Processing files with diverse data and formatting
199
+ - **File generation**: Creating files with data and images of graphs
200
+ - **Iterative coding**: Writing and running code iteratively to solve problems
201
+ - **Visual intelligence**: Cropping, zooming, rotating, and transforming images
202
+
203
+ ```typescript
204
+ import { ChatOpenAI, tools } from "@langchain/openai";
205
+
206
+ const model = new ChatOpenAI({ model: "gpt-4.1" });
207
+
208
+ // Basic usage with auto container (default 1GB memory)
209
+ const response = await model.invoke("Solve the equation 3x + 11 = 14", {
210
+ tools: [tools.codeInterpreter()],
211
+ });
212
+ ```
213
+
214
+ **Memory configuration** - Choose from 1GB (default), 4GB, 16GB, or 64GB:
215
+
216
+ ```typescript
217
+ const response = await model.invoke(
218
+ "Analyze this large dataset and create visualizations",
219
+ {
220
+ tools: [
221
+ tools.codeInterpreter({
222
+ container: { memoryLimit: "4g" },
223
+ }),
224
+ ],
225
+ }
226
+ );
227
+ ```
228
+
229
+ **With files** - Make uploaded files available to the code:
230
+
231
+ ```typescript
232
+ const response = await model.invoke("Process the uploaded CSV file", {
233
+ tools: [
234
+ tools.codeInterpreter({
235
+ container: {
236
+ memoryLimit: "4g",
237
+ fileIds: ["file-abc123", "file-def456"],
238
+ },
239
+ }),
240
+ ],
241
+ });
242
+ ```
243
+
244
+ **Explicit container** - Use a pre-created container ID:
245
+
246
+ ```typescript
247
+ const response = await model.invoke("Continue working with the data", {
248
+ tools: [
249
+ tools.codeInterpreter({
250
+ container: "cntr_abc123",
251
+ }),
252
+ ],
253
+ });
254
+ ```
255
+
256
+ > **Note**: Containers expire after 20 minutes of inactivity. While called "Code Interpreter", the model knows it as the "python tool" - for explicit prompting, ask for "the python tool" in your prompts.
257
+
258
+ For more information, see [OpenAI's Code Interpreter Documentation](https://platform.openai.com/docs/guides/tools-code-interpreter).
259
+
260
+ ### File Search Tool
261
+
262
+ The File Search tool allows models to search your files for relevant information using semantic and keyword search. It enables retrieval from a knowledge base of previously uploaded files stored in vector stores.
263
+
264
+ **Prerequisites**: Before using File Search, you must:
265
+
266
+ 1. Upload files to the File API with `purpose: "assistants"`
267
+ 2. Create a vector store
268
+ 3. Add files to the vector store
269
+
270
+ ```typescript
271
+ import { ChatOpenAI, tools } from "@langchain/openai";
272
+
273
+ const model = new ChatOpenAI({ model: "gpt-4.1" });
274
+
275
+ const response = await model.invoke("What is deep research by OpenAI?", {
276
+ tools: [
277
+ tools.fileSearch({
278
+ vectorStoreIds: ["vs_abc123"],
279
+ // maxNumResults: 5, // Limit results for lower latency
280
+ // filters: { type: "eq", key: "category", value: "blog" }, // Metadata filtering
281
+ // filters: { type: "and", filters: [ // Compound filters (AND/OR)
282
+ // { type: "eq", key: "category", value: "technical" },
283
+ // { type: "gte", key: "year", value: 2024 },
284
+ // ]},
285
+ // rankingOptions: { scoreThreshold: 0.8, ranker: "auto" }, // Customize scoring
286
+ }),
287
+ ],
288
+ });
289
+ ```
290
+
291
+ Filter operators: `eq` (equals), `ne` (not equal), `gt` (greater than), `gte` (greater than or equal), `lt` (less than), `lte` (less than or equal).
292
+
293
+ For more information, see [OpenAI's File Search Documentation](https://platform.openai.com/docs/guides/tools-file-search).
294
+
295
+ ### Image Generation Tool
296
+
297
+ The Image Generation tool allows models to generate or edit images using text prompts and optional image inputs. It leverages the GPT Image model and automatically optimizes text inputs for improved performance.
298
+
299
+ Use Image Generation for:
300
+
301
+ - **Creating images from text**: Generate images from detailed text descriptions
302
+ - **Editing existing images**: Modify images based on text instructions
303
+ - **Multi-turn image editing**: Iteratively refine images across conversation turns
304
+ - **Various output formats**: Support for PNG, JPEG, and WebP formats
305
+
306
+ ```typescript
307
+ import { ChatOpenAI, tools } from "@langchain/openai";
308
+
309
+ const model = new ChatOpenAI({ model: "gpt-4o" });
310
+
311
+ // Basic usage - generate an image
312
+ const response = await model.invoke(
313
+ "Generate an image of a gray tabby cat hugging an otter with an orange scarf",
314
+ { tools: [tools.imageGeneration()] }
315
+ );
316
+
317
+ // Access the generated image (base64-encoded)
318
+ const imageOutput = response.additional_kwargs.tool_outputs?.find(
319
+ (output) => output.type === "image_generation_call"
320
+ );
321
+ if (imageOutput?.result) {
322
+ const fs = await import("fs");
323
+ fs.writeFileSync("output.png", Buffer.from(imageOutput.result, "base64"));
324
+ }
325
+ ```
326
+
327
+ **Custom size and quality** - Configure output dimensions and quality:
328
+
329
+ ```typescript
330
+ const response = await model.invoke("Draw a beautiful sunset over mountains", {
331
+ tools: [
332
+ tools.imageGeneration({
333
+ size: "1536x1024", // Landscape format (also: "1024x1024", "1024x1536", "auto")
334
+ quality: "high", // Quality level (also: "low", "medium", "auto")
335
+ }),
336
+ ],
337
+ });
338
+ ```
339
+
340
+ **Output format and compression** - Choose format and compression level:
341
+
342
+ ```typescript
343
+ const response = await model.invoke("Create a product photo", {
344
+ tools: [
345
+ tools.imageGeneration({
346
+ outputFormat: "jpeg", // Format (also: "png", "webp")
347
+ outputCompression: 90, // Compression 0-100 (for JPEG/WebP)
348
+ }),
349
+ ],
350
+ });
351
+ ```
352
+
353
+ **Transparent background** - Generate images with transparency:
354
+
355
+ ```typescript
356
+ const response = await model.invoke(
357
+ "Create a logo with transparent background",
358
+ {
359
+ tools: [
360
+ tools.imageGeneration({
361
+ background: "transparent", // Background type (also: "opaque", "auto")
362
+ outputFormat: "png",
363
+ }),
364
+ ],
365
+ }
366
+ );
367
+ ```
368
+
369
+ **Streaming with partial images** - Get visual feedback during generation:
370
+
371
+ ```typescript
372
+ const response = await model.invoke("Draw a detailed fantasy castle", {
373
+ tools: [
374
+ tools.imageGeneration({
375
+ partialImages: 2, // Number of partial images (0-3)
376
+ }),
377
+ ],
378
+ });
379
+ ```
380
+
381
+ **Force image generation** - Ensure the model uses the image generation tool:
382
+
383
+ ```typescript
384
+ const response = await model.invoke("A serene lake at dawn", {
385
+ tools: [tools.imageGeneration()],
386
+ tool_choice: { type: "image_generation" },
387
+ });
388
+ ```
389
+
390
+ **Multi-turn editing** - Refine images across conversation turns:
391
+
392
+ ```typescript
393
+ // First turn: generate initial image
394
+ const response1 = await model.invoke("Draw a red car", {
395
+ tools: [tools.imageGeneration()],
396
+ });
397
+
398
+ // Second turn: edit the image
399
+ const response2 = await model.invoke(
400
+ [response1, new HumanMessage("Now change the car color to blue")],
401
+ { tools: [tools.imageGeneration()] }
402
+ );
403
+ ```
404
+
405
+ > **Prompting tips**: Use terms like "draw" or "edit" for best results. For combining images, say "edit the first image by adding this element" instead of "combine" or "merge".
406
+
407
+ Supported models: `gpt-4o`, `gpt-4o-mini`, `gpt-4.1`, `gpt-4.1-mini`, `gpt-4.1-nano`, `o3`
408
+
409
+ For more information, see [OpenAI's Image Generation Documentation](https://platform.openai.com/docs/guides/tools-image-generation).
410
+
411
+ ### Computer Use Tool
412
+
413
+ The Computer Use tool allows models to control computer interfaces by simulating mouse clicks, keyboard input, scrolling, and more. It uses OpenAI's Computer-Using Agent (CUA) model to understand screenshots and suggest actions.
414
+
415
+ > **Beta**: Computer use is in beta. Use in sandboxed environments only and do not use for high-stakes or authenticated tasks. Always implement human-in-the-loop for important decisions.
416
+
417
+ **How it works**: The tool operates in a continuous loop:
418
+
419
+ 1. Model sends computer actions (click, type, scroll, etc.)
420
+ 2. Your code executes these actions in a controlled environment
421
+ 3. You capture a screenshot of the result
422
+ 4. Send the screenshot back to the model
423
+ 5. Repeat until the task is complete
424
+
425
+ ```typescript
426
+ import { ChatOpenAI, tools } from "@langchain/openai";
427
+
428
+ const model = new ChatOpenAI({ model: "computer-use-preview" });
429
+
430
+ // With execute callback for automatic action handling
431
+ const computer = tools.computerUse({
432
+ displayWidth: 1024,
433
+ displayHeight: 768,
434
+ environment: "browser",
435
+ execute: async (action) => {
436
+ if (action.type === "screenshot") {
437
+ return captureScreenshot();
438
+ }
439
+ if (action.type === "click") {
440
+ await page.mouse.click(action.x, action.y, { button: action.button });
441
+ return captureScreenshot();
442
+ }
443
+ if (action.type === "type") {
444
+ await page.keyboard.type(action.text);
445
+ return captureScreenshot();
446
+ }
447
+ if (action.type === "scroll") {
448
+ await page.mouse.move(action.x, action.y);
449
+ await page.evaluate(
450
+ `window.scrollBy(${action.scroll_x}, ${action.scroll_y})`
451
+ );
452
+ return captureScreenshot();
453
+ }
454
+ // Handle other actions...
455
+ return captureScreenshot();
456
+ },
457
+ });
458
+
459
+ const llmWithComputer = model.bindTools([computer]);
460
+ const response = await llmWithComputer.invoke(
461
+ "Check the latest news on bing.com"
462
+ );
463
+ ```
464
+
465
+ For more information, see [OpenAI's Computer Use Documentation](https://platform.openai.com/docs/guides/tools-computer-use).
466
+
467
+ ### Local Shell Tool
468
+
469
+ The Local Shell tool allows models to run shell commands locally on a machine you provide. Commands are executed inside your own runtime—the API only returns the instructions.
470
+
471
+ > **Security Warning**: Running arbitrary shell commands can be dangerous. Always sandbox execution or add strict allow/deny-lists before forwarding commands to the system shell.
472
+ > **Note**: This tool is designed to work with [Codex CLI](https://github.com/openai/codex) and the `codex-mini-latest` model.
473
+
474
+ ```typescript
475
+ import { ChatOpenAI, tools } from "@langchain/openai";
476
+ import { exec } from "child_process";
477
+ import { promisify } from "util";
478
+
479
+ const execAsync = promisify(exec);
480
+ const model = new ChatOpenAI({ model: "codex-mini-latest" });
481
+
482
+ // With execute callback for automatic command handling
483
+ const shell = tools.localShell({
484
+ execute: async (action) => {
485
+ const { command, env, working_directory, timeout_ms } = action;
486
+ const result = await execAsync(command.join(" "), {
487
+ cwd: working_directory ?? process.cwd(),
488
+ env: { ...process.env, ...env },
489
+ timeout: timeout_ms ?? undefined,
490
+ });
491
+ return result.stdout + result.stderr;
492
+ },
493
+ });
494
+
495
+ const llmWithShell = model.bindTools([shell]);
496
+ const response = await llmWithShell.invoke(
497
+ "List files in the current directory"
498
+ );
499
+ ```
500
+
501
+ **Action properties**: The model returns actions with these properties:
502
+
503
+ - `command` - Array of argv tokens to execute
504
+ - `env` - Environment variables to set
505
+ - `working_directory` - Directory to run the command in
506
+ - `timeout_ms` - Suggested timeout (enforce your own limits)
507
+ - `user` - Optional user to run the command as
508
+
509
+ For more information, see [OpenAI's Local Shell Documentation](https://platform.openai.com/docs/guides/tools-local-shell).
510
+
511
+ ### Shell Tool
512
+
513
+ The Shell tool allows models to run shell commands through your integration. Unlike Local Shell, this tool supports executing multiple commands concurrently and is designed for `gpt-5.1`.
514
+
515
+ > **Security Warning**: Running arbitrary shell commands can be dangerous. Always sandbox execution or add strict allow/deny-lists before forwarding commands to the system shell.
516
+
517
+ **Use cases**:
518
+
519
+ - **Automating filesystem or process diagnostics** – e.g., "find the largest PDF under ~/Documents"
520
+ - **Extending model capabilities** – Using built-in UNIX utilities, Python runtime, and other CLIs
521
+ - **Running multi-step build and test flows** – Chaining commands like `pip install` and `pytest`
522
+ - **Complex agentic coding workflows** – Using with `apply_patch` for file operations
523
+
524
+ ```typescript
525
+ import { ChatOpenAI, tools } from "@langchain/openai";
526
+ import { exec } from "node:child_process/promises";
527
+
528
+ const model = new ChatOpenAI({ model: "gpt-5.1" });
529
+
530
+ // With execute callback for automatic command handling
531
+ const shellTool = tools.shell({
532
+ execute: async (action) => {
533
+ const outputs = await Promise.all(
534
+ action.commands.map(async (cmd) => {
535
+ try {
536
+ const { stdout, stderr } = await exec(cmd, {
537
+ timeout: action.timeout_ms ?? undefined,
538
+ });
539
+ return {
540
+ stdout,
541
+ stderr,
542
+ outcome: { type: "exit" as const, exit_code: 0 },
543
+ };
544
+ } catch (error) {
545
+ const timedOut = error.killed && error.signal === "SIGTERM";
546
+ return {
547
+ stdout: error.stdout ?? "",
548
+ stderr: error.stderr ?? String(error),
549
+ outcome: timedOut
550
+ ? { type: "timeout" as const }
551
+ : { type: "exit" as const, exit_code: error.code ?? 1 },
552
+ };
553
+ }
554
+ })
555
+ );
556
+ return {
557
+ output: outputs,
558
+ maxOutputLength: action.max_output_length,
559
+ };
560
+ },
561
+ });
562
+
563
+ const llmWithShell = model.bindTools([shellTool]);
564
+ const response = await llmWithShell.invoke(
565
+ "Find the largest PDF file in ~/Documents"
566
+ );
567
+ ```
568
+
569
+ **Action properties**: The model returns actions with these properties:
570
+
571
+ - `commands` - Array of shell commands to execute (can run concurrently)
572
+ - `timeout_ms` - Optional timeout in milliseconds (enforce your own limits)
573
+ - `max_output_length` - Optional maximum characters to return per command
574
+
575
+ **Return format**: Your execute function should return a `ShellResult`:
576
+
577
+ ```typescript
578
+ interface ShellResult {
579
+ output: Array<{
580
+ stdout: string;
581
+ stderr: string;
582
+ outcome: { type: "exit"; exit_code: number } | { type: "timeout" };
583
+ }>;
584
+ maxOutputLength?: number | null; // Pass back from action if provided
585
+ }
586
+ ```
587
+
588
+ For more information, see [OpenAI's Shell Documentation](https://platform.openai.com/docs/guides/tools-shell).
589
+
590
+ ### Apply Patch Tool
591
+
592
+ The Apply Patch tool allows models to propose structured diffs that your integration applies. This enables iterative, multi-step code editing workflows where the model can create, update, and delete files in your codebase.
593
+
594
+ **When to use**:
595
+
596
+ - **Multi-file refactors** – Rename symbols, extract helpers, or reorganize modules
597
+ - **Bug fixes** – Have the model both diagnose issues and emit precise patches
598
+ - **Tests & docs generation** – Create new test files, fixtures, and documentation
599
+ - **Migrations & mechanical edits** – Apply repetitive, structured updates
600
+
601
+ > **Security Warning**: Applying patches can modify files in your codebase. Always validate paths, implement backups, and consider sandboxing.
602
+ > **Note**: This tool is designed to work with `gpt-5.1` model.
603
+
604
+ ```typescript
605
+ import { ChatOpenAI, tools } from "@langchain/openai";
606
+ import { applyDiff } from "@openai/agents";
607
+ import * as fs from "fs/promises";
608
+
609
+ const model = new ChatOpenAI({ model: "gpt-5.1" });
610
+
611
+ // With execute callback for automatic patch handling
612
+ const patchTool = tools.applyPatch({
613
+ execute: async (operation) => {
614
+ if (operation.type === "create_file") {
615
+ const content = applyDiff("", operation.diff, "create");
616
+ await fs.writeFile(operation.path, content);
617
+ return `Created ${operation.path}`;
618
+ }
619
+ if (operation.type === "update_file") {
620
+ const current = await fs.readFile(operation.path, "utf-8");
621
+ const newContent = applyDiff(current, operation.diff);
622
+ await fs.writeFile(operation.path, newContent);
623
+ return `Updated ${operation.path}`;
624
+ }
625
+ if (operation.type === "delete_file") {
626
+ await fs.unlink(operation.path);
627
+ return `Deleted ${operation.path}`;
628
+ }
629
+ return "Unknown operation type";
630
+ },
631
+ });
632
+
633
+ const llmWithPatch = model.bindTools([patchTool]);
634
+ const response = await llmWithPatch.invoke(
635
+ "Rename the fib() function to fibonacci() in lib/fib.py"
636
+ );
637
+ ```
638
+
639
+ **Operation types**: The model returns operations with these properties:
640
+
641
+ - `create_file` – Create a new file at `path` with content from `diff`
642
+ - `update_file` – Modify an existing file at `path` using V4A diff format in `diff`
643
+ - `delete_file` – Remove a file at `path`
644
+
645
+ **Best practices**:
646
+
647
+ - **Path validation**: Prevent directory traversal and restrict edits to allowed directories
648
+ - **Backups**: Consider backing up files before applying patches
649
+ - **Error handling**: Return descriptive error messages so the model can recover
650
+ - **Atomicity**: Decide whether you want "all-or-nothing" semantics (rollback if any patch fails)
651
+
652
+ For more information, see [OpenAI's Apply Patch Documentation](https://platform.openai.com/docs/guides/tools-apply-patch).
653
+
73
654
  ## Embeddings
74
655
 
75
656
  This package also adds support for OpenAI's embeddings model.
@@ -111,8 +692,8 @@ Test files should live within a `tests/` file in the `src/` folder. Unit tests s
111
692
  end in `.int.test.ts`:
112
693
 
113
694
  ```bash
114
- $ pnpm test
115
- $ pnpm test:int
695
+ pnpm test
696
+ pnpm test:int
116
697
  ```
117
698
 
118
699
  ### Lint & Format
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.cts","names":["Serialized","ChatOpenAICallOptions","AzureOpenAIChatInput","OpenAICoreRequestOptions","BaseChatOpenAI","BaseChatOpenAIFields","AZURE_ALIASES","AZURE_SECRETS","AZURE_SERIALIZABLE_KEYS","AzureChatOpenAIFields","Partial","_constructAzureFields","_getAzureClientOptions","_serializeAzureChat"],"sources":["../../../src/azure/chat_models/common.d.ts"],"sourcesContent":["import type { Serialized } from \"@langchain/core/load/serializable\";\nimport { ChatOpenAICallOptions } from \"../../chat_models/index.js\";\nimport { AzureOpenAIChatInput, OpenAICoreRequestOptions } from \"../../types.js\";\nimport { BaseChatOpenAI, BaseChatOpenAIFields } from \"../../chat_models/base.js\";\nexport declare const AZURE_ALIASES: {\n openAIApiKey: string;\n openAIApiVersion: string;\n openAIBasePath: string;\n deploymentName: string;\n azureOpenAIEndpoint: string;\n azureOpenAIApiVersion: string;\n azureOpenAIBasePath: string;\n azureOpenAIApiDeploymentName: string;\n};\nexport declare const AZURE_SECRETS: {\n azureOpenAIApiKey: string;\n};\nexport declare const AZURE_SERIALIZABLE_KEYS: string[];\nexport interface AzureChatOpenAIFields extends BaseChatOpenAIFields, Partial<AzureOpenAIChatInput> {\n /**\n * Whether to use the responses API for all requests. If `false` the responses API will be used\n * only when required in order to fulfill the request.\n */\n useResponsesApi?: boolean;\n}\nexport declare function _constructAzureFields(this: Partial<AzureOpenAIChatInput>, fields?: AzureChatOpenAIFields): void;\nexport declare function _getAzureClientOptions(this: BaseChatOpenAI<ChatOpenAICallOptions> & Partial<AzureOpenAIChatInput>, options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;\nexport declare function _serializeAzureChat(this: BaseChatOpenAI<ChatOpenAICallOptions> & Partial<AzureOpenAIChatInput>, input: Serialized): Serialized;\n//# sourceMappingURL=common.d.ts.map"],"mappings":";;;;;;UAkBiBS,qBAAAA,SAA8BJ,sBAAsBK,QAAQR"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","names":["Serialized","ChatOpenAICallOptions","AzureOpenAIChatInput","OpenAICoreRequestOptions","BaseChatOpenAI","BaseChatOpenAIFields","AZURE_ALIASES","AZURE_SECRETS","AZURE_SERIALIZABLE_KEYS","AzureChatOpenAIFields","Partial","_constructAzureFields","_getAzureClientOptions","_serializeAzureChat"],"sources":["../../../src/azure/chat_models/common.d.ts"],"sourcesContent":["import type { Serialized } from \"@langchain/core/load/serializable\";\nimport { ChatOpenAICallOptions } from \"../../chat_models/index.js\";\nimport { AzureOpenAIChatInput, OpenAICoreRequestOptions } from \"../../types.js\";\nimport { BaseChatOpenAI, BaseChatOpenAIFields } from \"../../chat_models/base.js\";\nexport declare const AZURE_ALIASES: {\n openAIApiKey: string;\n openAIApiVersion: string;\n openAIBasePath: string;\n deploymentName: string;\n azureOpenAIEndpoint: string;\n azureOpenAIApiVersion: string;\n azureOpenAIBasePath: string;\n azureOpenAIApiDeploymentName: string;\n};\nexport declare const AZURE_SECRETS: {\n azureOpenAIApiKey: string;\n};\nexport declare const AZURE_SERIALIZABLE_KEYS: string[];\nexport interface AzureChatOpenAIFields extends BaseChatOpenAIFields, Partial<AzureOpenAIChatInput> {\n /**\n * Whether to use the responses API for all requests. If `false` the responses API will be used\n * only when required in order to fulfill the request.\n */\n useResponsesApi?: boolean;\n}\nexport declare function _constructAzureFields(this: Partial<AzureOpenAIChatInput>, fields?: AzureChatOpenAIFields): void;\nexport declare function _getAzureClientOptions(this: BaseChatOpenAI<ChatOpenAICallOptions> & Partial<AzureOpenAIChatInput>, options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;\nexport declare function _serializeAzureChat(this: BaseChatOpenAI<ChatOpenAICallOptions> & Partial<AzureOpenAIChatInput>, input: Serialized): Serialized;\n//# sourceMappingURL=common.d.ts.map"],"mappings":";;;;;;;UAkBiBS,qBAAAA,SAA8BJ,sBAAsBK,QAAQR"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completions.d.cts","names":["LangSmithParams","Serialized","ChatOpenAICompletions","ChatOpenAICompletionsCallOptions","AzureOpenAIChatInput","OpenAICoreRequestOptions","AzureChatOpenAIFields","AzureChatOpenAICompletions","CallOptions","Promise","Record","Partial"],"sources":["../../../src/azure/chat_models/completions.d.ts"],"sourcesContent":["import { LangSmithParams } from \"@langchain/core/language_models/chat_models\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { ChatOpenAICompletions, ChatOpenAICompletionsCallOptions } from \"../../chat_models/completions.js\";\nimport { AzureOpenAIChatInput, OpenAICoreRequestOptions } from \"../../types.js\";\nimport { AzureChatOpenAIFields } from \"./common.js\";\nexport declare class AzureChatOpenAICompletions<CallOptions extends ChatOpenAICompletionsCallOptions = ChatOpenAICompletionsCallOptions> extends ChatOpenAICompletions<CallOptions> implements Partial<AzureOpenAIChatInput> {\n azureOpenAIApiVersion?: string;\n azureOpenAIApiKey?: string;\n azureADTokenProvider?: () => Promise<string>;\n azureOpenAIApiInstanceName?: string;\n azureOpenAIApiDeploymentName?: string;\n azureOpenAIBasePath?: string;\n azureOpenAIEndpoint?: string;\n _llmType(): string;\n get lc_aliases(): Record<string, string>;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_serializable_keys(): string[];\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n constructor(fields?: AzureChatOpenAIFields);\n _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;\n toJSON(): Serialized;\n}\n//# sourceMappingURL=completions.d.ts.map"],"mappings":";;;;;;;cAKqBO,+CAA+CJ,mCAAmCA,0CAA0CD,sBAAsBM,wBAAwBG,QAAQP;;EAAlLG,iBAAAA,CAAAA,EAAAA,MAAAA;EAA+CJ,oBAAAA,CAAAA,EAAAA,GAAAA,GAGnCM,OAHmCN,CAAAA,MAAAA,CAAAA;EAAmCA,0BAAAA,CAAAA,EAAAA,MAAAA;EAAgEK,4BAAAA,CAAAA,EAAAA,MAAAA;EAAgCJ,mBAAAA,CAAAA,EAAAA,MAAAA;EAGtKK,mBAAAA,CAAAA,EAAAA,MAAAA;EAMXC,QAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAK+BV,IAAAA,UAAAA,CAAAA,CAAAA,EAL/BU,MAK+BV,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAC5BM,IAAAA,UAAAA,CAAAA,CAAAA,EAAAA;IACMD,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,MAAAA;EAAuCA,CAAAA,GAAAA,SAAAA;EACxDJ,IAAAA,oBAAAA,CAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EAjBmIC,WAAAA,CAAAA,OAAAA,EAAAA,IAAAA,CAAAA,mBAAAA,CAAAA,CAAAA,EAc5FF,eAd4FE;EAA8CS,WAAAA,CAAAA,MAAAA,CAAAA,EAetKL,qBAfsKK;EAAO,iBAAA,CAAA,OAAA,EAgBvKN,wBAhBuK,GAAA,SAAA,CAAA,EAgBhIA,wBAhBgI;YAiBxLJ"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completions.d.ts","names":["LangSmithParams","Serialized","ChatOpenAICompletions","ChatOpenAICompletionsCallOptions","AzureOpenAIChatInput","OpenAICoreRequestOptions","AzureChatOpenAIFields","AzureChatOpenAICompletions","CallOptions","Promise","Record","Partial"],"sources":["../../../src/azure/chat_models/completions.d.ts"],"sourcesContent":["import { LangSmithParams } from \"@langchain/core/language_models/chat_models\";\nimport { Serialized } from \"@langchain/core/load/serializable\";\nimport { ChatOpenAICompletions, ChatOpenAICompletionsCallOptions } from \"../../chat_models/completions.js\";\nimport { AzureOpenAIChatInput, OpenAICoreRequestOptions } from \"../../types.js\";\nimport { AzureChatOpenAIFields } from \"./common.js\";\nexport declare class AzureChatOpenAICompletions<CallOptions extends ChatOpenAICompletionsCallOptions = ChatOpenAICompletionsCallOptions> extends ChatOpenAICompletions<CallOptions> implements Partial<AzureOpenAIChatInput> {\n azureOpenAIApiVersion?: string;\n azureOpenAIApiKey?: string;\n azureADTokenProvider?: () => Promise<string>;\n azureOpenAIApiInstanceName?: string;\n azureOpenAIApiDeploymentName?: string;\n azureOpenAIBasePath?: string;\n azureOpenAIEndpoint?: string;\n _llmType(): string;\n get lc_aliases(): Record<string, string>;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_serializable_keys(): string[];\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n constructor(fields?: AzureChatOpenAIFields);\n _getClientOptions(options: OpenAICoreRequestOptions | undefined): OpenAICoreRequestOptions;\n toJSON(): Serialized;\n}\n//# sourceMappingURL=completions.d.ts.map"],"mappings":";;;;;;;cAKqBO,+CAA+CJ,mCAAmCA,0CAA0CD,sBAAsBM,wBAAwBG,QAAQP;;EAAlLG,iBAAAA,CAAAA,EAAAA,MAAAA;EAA+CJ,oBAAAA,CAAAA,EAAAA,GAAAA,GAGnCM,OAHmCN,CAAAA,MAAAA,CAAAA;EAAmCA,0BAAAA,CAAAA,EAAAA,MAAAA;EAAgEK,4BAAAA,CAAAA,EAAAA,MAAAA;EAAgCJ,mBAAAA,CAAAA,EAAAA,MAAAA;EAGtKK,mBAAAA,CAAAA,EAAAA,MAAAA;EAMXC,QAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAK+BV,IAAAA,UAAAA,CAAAA,CAAAA,EAL/BU,MAK+BV,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;EAC5BM,IAAAA,UAAAA,CAAAA,CAAAA,EAAAA;IACMD,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,MAAAA;EAAuCA,CAAAA,GAAAA,SAAAA;EACxDJ,IAAAA,oBAAAA,CAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EAjBmIC,WAAAA,CAAAA,OAAAA,EAAAA,IAAAA,CAAAA,mBAAAA,CAAAA,CAAAA,EAc5FF,eAd4FE;EAA8CS,WAAAA,CAAAA,MAAAA,CAAAA,EAetKL,qBAfsKK;EAAO,iBAAA,CAAA,OAAA,EAgBvKN,wBAhBuK,GAAA,SAAA,CAAA,EAgBhIA,wBAhBgI;YAiBxLJ"}
@@ -2,8 +2,8 @@ import { AzureOpenAIChatInput } from "../../types.cjs";
2
2
  import { ChatOpenAI, ChatOpenAICallOptions } from "../../chat_models/index.cjs";
3
3
  import { AzureChatOpenAIFields } from "./common.cjs";
4
4
  import { Serialized } from "@langchain/core/load/serializable";
5
- import { StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
6
5
  import { LangSmithParams } from "@langchain/core/language_models/chat_models";
6
+ import { StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
7
7
 
8
8
  //#region src/azure/chat_models/index.d.ts
9
9
 
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":["StructuredOutputMethodOptions","Serialized","LangSmithParams","ChatOpenAI","ChatOpenAICallOptions","AzureOpenAIChatInput","AzureChatOpenAIFields","AzureChatOpenAI","CallOptions","Promise","Record","Partial"],"sources":["../../../src/azure/chat_models/index.d.ts"],"sourcesContent":["import { StructuredOutputMethodOptions } from \"@langchain/core/language_models/base\";\nimport type { Serialized } from \"@langchain/core/load/serializable\";\nimport { LangSmithParams } from \"@langchain/core/language_models/chat_models\";\nimport { ChatOpenAI, ChatOpenAICallOptions } from \"../../chat_models/index.js\";\nimport { AzureOpenAIChatInput } from \"../../types.js\";\nimport { AzureChatOpenAIFields } from \"./common.js\";\n/**\n * Azure OpenAI chat model integration.\n *\n * Setup:\n * Install `@langchain/openai` and set the following environment variables:\n *\n * ```bash\n * npm install @langchain/openai\n * export AZURE_OPENAI_API_KEY=\"your-api-key\"\n * export AZURE_OPENAI_API_DEPLOYMENT_NAME=\"your-deployment-name\"\n * export AZURE_OPENAI_API_VERSION=\"your-version\"\n * export AZURE_OPENAI_BASE_PATH=\"your-base-path\"\n * ```\n *\n * ## [Constructor args](https://api.js.langchain.com/classes/langchain_openai.AzureChatOpenAI.html#constructor)\n *\n * ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_openai.ChatOpenAICallOptions.html)\n *\n * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.\n * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:\n *\n * ```typescript\n * // When calling `.withConfig`, call options should be passed via the first argument\n * const llmWithArgsBound = llm.withConfig({\n * stop: [\"\\n\"],\n * tools: [...],\n * });\n *\n * // When calling `.bindTools`, call options should be passed via the second argument\n * const llmWithTools = llm.bindTools(\n * [...],\n * {\n * tool_choice: \"auto\",\n * }\n * );\n * ```\n *\n * ## Examples\n *\n * <details open>\n * <summary><strong>Instantiate</strong></summary>\n *\n * ```typescript\n * import { AzureChatOpenAI } from '@langchain/openai';\n *\n * const llm = new AzureChatOpenAI({\n * azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY, // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY\n * azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME, // In Node.js defaults to process.env.AZURE_OPENAI_API_INSTANCE_NAME\n * azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME, // In Node.js defaults to process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME\n * azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION, // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION\n * temperature: 0,\n * maxTokens: undefined,\n * timeout: undefined,\n * maxRetries: 2,\n * // apiKey: \"...\",\n * // baseUrl: \"...\",\n * // other params...\n * });\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Invoking</strong></summary>\n *\n * ```typescript\n * const input = `Translate \"I love programming\" into French.`;\n *\n * // Models also accept a list of chat messages or a formatted prompt\n * const result = await llm.invoke(input);\n * console.log(result);\n * ```\n *\n * ```txt\n * AIMessage {\n * \"id\": \"chatcmpl-9u4Mpu44CbPjwYFkTbeoZgvzB00Tz\",\n * \"content\": \"J'adore la programmation.\",\n * \"response_metadata\": {\n * \"tokenUsage\": {\n * \"completionTokens\": 5,\n * \"promptTokens\": 28,\n * \"totalTokens\": 33\n * },\n * \"finish_reason\": \"stop\",\n * \"system_fingerprint\": \"fp_3aa7262c27\"\n * },\n * \"usage_metadata\": {\n * \"input_tokens\": 28,\n * \"output_tokens\": 5,\n * \"total_tokens\": 33\n * }\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Streaming Chunks</strong></summary>\n *\n * ```typescript\n * for await (const chunk of await llm.stream(input)) {\n * console.log(chunk);\n * }\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"id\": \"chatcmpl-9u4NWB7yUeHCKdLr6jP3HpaOYHTqs\",\n * \"content\": \"\"\n * }\n * AIMessageChunk {\n * \"content\": \"J\"\n * }\n * AIMessageChunk {\n * \"content\": \"'adore\"\n * }\n * AIMessageChunk {\n * \"content\": \" la\"\n * }\n * AIMessageChunk {\n * \"content\": \" programmation\",,\n * }\n * AIMessageChunk {\n * \"content\": \".\",,\n * }\n * AIMessageChunk {\n * \"content\": \"\",\n * \"response_metadata\": {\n * \"finish_reason\": \"stop\",\n * \"system_fingerprint\": \"fp_c9aa9c0491\"\n * },\n * }\n * AIMessageChunk {\n * \"content\": \"\",\n * \"usage_metadata\": {\n * \"input_tokens\": 28,\n * \"output_tokens\": 5,\n * \"total_tokens\": 33\n * }\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Aggregate Streamed Chunks</strong></summary>\n *\n * ```typescript\n * import { AIMessageChunk } from '@langchain/core/messages';\n * import { concat } from '@langchain/core/utils/stream';\n *\n * const stream = await llm.stream(input);\n * let full: AIMessageChunk | undefined;\n * for await (const chunk of stream) {\n * full = !full ? chunk : concat(full, chunk);\n * }\n * console.log(full);\n * ```\n *\n * ```txt\n * AIMessageChunk {\n * \"id\": \"chatcmpl-9u4PnX6Fy7OmK46DASy0bH6cxn5Xu\",\n * \"content\": \"J'adore la programmation.\",\n * \"response_metadata\": {\n * \"prompt\": 0,\n * \"completion\": 0,\n * \"finish_reason\": \"stop\",\n * },\n * \"usage_metadata\": {\n * \"input_tokens\": 28,\n * \"output_tokens\": 5,\n * \"total_tokens\": 33\n * }\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Bind tools</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const GetWeather = {\n * name: \"GetWeather\",\n * description: \"Get the current weather in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const GetPopulation = {\n * name: \"GetPopulation\",\n * description: \"Get the current population in a given location\",\n * schema: z.object({\n * location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n * }),\n * }\n *\n * const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);\n * const aiMsg = await llmWithTools.invoke(\n * \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n * {\n * name: 'GetWeather',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_uPU4FiFzoKAtMxfmPnfQL6UK'\n * },\n * {\n * name: 'GetWeather',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_UNkEwuQsHrGYqgDQuH9nPAtX'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'Los Angeles, CA' },\n * type: 'tool_call',\n * id: 'call_kL3OXxaq9OjIKqRTpvjaCH14'\n * },\n * {\n * name: 'GetPopulation',\n * args: { location: 'New York, NY' },\n * type: 'tool_call',\n * id: 'call_s9KQB1UWj45LLGaEnjz0179q'\n * }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n *\n * const Joke = z.object({\n * setup: z.string().describe(\"The setup of the joke\"),\n * punchline: z.string().describe(\"The punchline to the joke\"),\n * rating: z.number().nullable().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llm.withStructuredOutput(Joke, { name: \"Joke\" });\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n * setup: 'Why was the cat sitting on the computer?',\n * punchline: 'Because it wanted to keep an eye on the mouse!',\n * rating: 7\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>JSON Object Response Format</strong></summary>\n *\n * ```typescript\n * const jsonLlm = llm.withConfig({ response_format: { type: \"json_object\" } });\n * const jsonLlmAiMsg = await jsonLlm.invoke(\n * \"Return a JSON object with key 'randomInts' and a value of 10 random ints in [0-99]\"\n * );\n * console.log(jsonLlmAiMsg.content);\n * ```\n *\n * ```txt\n * {\n * \"randomInts\": [23, 87, 45, 12, 78, 34, 56, 90, 11, 67]\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Multimodal</strong></summary>\n *\n * ```typescript\n * import { HumanMessage } from '@langchain/core/messages';\n *\n * const imageUrl = \"https://example.com/image.jpg\";\n * const imageData = await fetch(imageUrl).then(res => res.arrayBuffer());\n * const base64Image = Buffer.from(imageData).toString('base64');\n *\n * const message = new HumanMessage({\n * content: [\n * { type: \"text\", text: \"describe the weather in this image\" },\n * {\n * type: \"image_url\",\n * image_url: { url: `data:image/jpeg;base64,${base64Image}` },\n * },\n * ]\n * });\n *\n * const imageDescriptionAiMsg = await llm.invoke([message]);\n * console.log(imageDescriptionAiMsg.content);\n * ```\n *\n * ```txt\n * The weather in the image appears to be clear and sunny. The sky is mostly blue with a few scattered white clouds, indicating fair weather. The bright sunlight is casting shadows on the green, grassy hill, suggesting it is a pleasant day with good visibility. There are no signs of rain or stormy conditions.\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Usage Metadata</strong></summary>\n *\n * ```typescript\n * const aiMsgForMetadata = await llm.invoke(input);\n * console.log(aiMsgForMetadata.usage_metadata);\n * ```\n *\n * ```txt\n * { input_tokens: 28, output_tokens: 5, total_tokens: 33 }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Logprobs</strong></summary>\n *\n * ```typescript\n * const logprobsLlm = new ChatOpenAI({ model: \"gpt-4o-mini\", logprobs: true });\n * const aiMsgForLogprobs = await logprobsLlm.invoke(input);\n * console.log(aiMsgForLogprobs.response_metadata.logprobs);\n * ```\n *\n * ```txt\n * {\n * content: [\n * {\n * token: 'J',\n * logprob: -0.000050616763,\n * bytes: [Array],\n * top_logprobs: []\n * },\n * {\n * token: \"'\",\n * logprob: -0.01868736,\n * bytes: [Array],\n * top_logprobs: []\n * },\n * {\n * token: 'ad',\n * logprob: -0.0000030545007,\n * bytes: [Array],\n * top_logprobs: []\n * },\n * { token: 'ore', logprob: 0, bytes: [Array], top_logprobs: [] },\n * {\n * token: ' la',\n * logprob: -0.515404,\n * bytes: [Array],\n * top_logprobs: []\n * },\n * {\n * token: ' programm',\n * logprob: -0.0000118755715,\n * bytes: [Array],\n * top_logprobs: []\n * },\n * { token: 'ation', logprob: 0, bytes: [Array], top_logprobs: [] },\n * {\n * token: '.',\n * logprob: -0.0000037697225,\n * bytes: [Array],\n * top_logprobs: []\n * }\n * ],\n * refusal: null\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Response Metadata</strong></summary>\n *\n * ```typescript\n * const aiMsgForResponseMetadata = await llm.invoke(input);\n * console.log(aiMsgForResponseMetadata.response_metadata);\n * ```\n *\n * ```txt\n * {\n * tokenUsage: { completionTokens: 5, promptTokens: 28, totalTokens: 33 },\n * finish_reason: 'stop',\n * system_fingerprint: 'fp_3aa7262c27'\n * }\n * ```\n * </details>\n */\nexport declare class AzureChatOpenAI<CallOptions extends ChatOpenAICallOptions = ChatOpenAICallOptions> extends ChatOpenAI<CallOptions> implements Partial<AzureOpenAIChatInput> {\n azureOpenAIApiVersion?: string;\n azureOpenAIApiKey?: string;\n azureADTokenProvider?: () => Promise<string>;\n azureOpenAIApiInstanceName?: string;\n azureOpenAIApiDeploymentName?: string;\n azureOpenAIBasePath?: string;\n azureOpenAIEndpoint?: string;\n _llmType(): string;\n get lc_aliases(): Record<string, string>;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_serializable_keys(): string[];\n getLsParams(options: this[\"ParsedCallOptions\"]): LangSmithParams;\n constructor(fields?: AzureChatOpenAIFields);\n /** @internal */\n _getStructuredOutputMethod(config: StructuredOutputMethodOptions<boolean>): string | undefined;\n toJSON(): Serialized;\n}\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;;;;;;AAkaA;;;;;;;;;;;;;AAA0J;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAArIO,oCAAoCH,wBAAwBA,+BAA+BD,WAAWK,wBAAwBG,QAAQN;;;+BAG1HI;;;;;;oBAMXC;;;;;mDAK+BR;uBAC5BI;;qCAEcN;YACzBC"}