@langchain/openai 0.6.8 → 1.0.0-alpha.1

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 (162) hide show
  1. package/README.md +8 -8
  2. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  3. package/dist/azure/chat_models.cjs +661 -808
  4. package/dist/azure/chat_models.cjs.map +1 -0
  5. package/dist/azure/chat_models.d.cts +449 -0
  6. package/dist/azure/chat_models.d.cts.map +1 -0
  7. package/dist/azure/chat_models.d.ts +32 -28
  8. package/dist/azure/chat_models.d.ts.map +1 -0
  9. package/dist/azure/chat_models.js +660 -804
  10. package/dist/azure/chat_models.js.map +1 -0
  11. package/dist/azure/embeddings.cjs +81 -130
  12. package/dist/azure/embeddings.cjs.map +1 -0
  13. package/dist/azure/embeddings.d.cts +27 -0
  14. package/dist/azure/embeddings.d.cts.map +1 -0
  15. package/dist/azure/embeddings.d.ts +25 -20
  16. package/dist/azure/embeddings.d.ts.map +1 -0
  17. package/dist/azure/embeddings.js +80 -126
  18. package/dist/azure/embeddings.js.map +1 -0
  19. package/dist/azure/llms.cjs +109 -168
  20. package/dist/azure/llms.cjs.map +1 -0
  21. package/dist/azure/llms.d.cts +33 -0
  22. package/dist/azure/llms.d.cts.map +1 -0
  23. package/dist/azure/llms.d.ts +31 -25
  24. package/dist/azure/llms.d.ts.map +1 -0
  25. package/dist/azure/llms.js +108 -164
  26. package/dist/azure/llms.js.map +1 -0
  27. package/dist/chat_models.cjs +1951 -2763
  28. package/dist/chat_models.cjs.map +1 -0
  29. package/dist/chat_models.d.cts +930 -0
  30. package/dist/chat_models.d.cts.map +1 -0
  31. package/dist/chat_models.d.ts +365 -336
  32. package/dist/chat_models.d.ts.map +1 -0
  33. package/dist/chat_models.js +1946 -2753
  34. package/dist/chat_models.js.map +1 -0
  35. package/dist/embeddings.cjs +136 -193
  36. package/dist/embeddings.cjs.map +1 -0
  37. package/dist/embeddings.d.cts +115 -0
  38. package/dist/embeddings.d.cts.map +1 -0
  39. package/dist/embeddings.d.ts +88 -81
  40. package/dist/embeddings.d.ts.map +1 -0
  41. package/dist/embeddings.js +134 -188
  42. package/dist/embeddings.js.map +1 -0
  43. package/dist/index.cjs +47 -34
  44. package/dist/index.d.cts +16 -0
  45. package/dist/index.d.ts +16 -13
  46. package/dist/index.js +17 -13
  47. package/dist/langchain-core/dist/types/_internal.d.cts +11 -0
  48. package/dist/langchain-core/dist/types/_internal.d.cts.map +1 -0
  49. package/dist/langchain-core/dist/types/_internal.d.ts +11 -0
  50. package/dist/langchain-core/dist/types/_internal.d.ts.map +1 -0
  51. package/dist/langchain-core/dist/utils/stream.d.cts +26 -0
  52. package/dist/langchain-core/dist/utils/stream.d.cts.map +1 -0
  53. package/dist/langchain-core/dist/utils/stream.d.ts +26 -0
  54. package/dist/langchain-core/dist/utils/stream.d.ts.map +1 -0
  55. package/dist/llms.cjs +312 -468
  56. package/dist/llms.cjs.map +1 -0
  57. package/dist/llms.d.cts +123 -0
  58. package/dist/llms.d.cts.map +1 -0
  59. package/dist/llms.d.ts +93 -87
  60. package/dist/llms.d.ts.map +1 -0
  61. package/dist/llms.js +309 -462
  62. package/dist/llms.js.map +1 -0
  63. package/dist/tools/custom.cjs +25 -26
  64. package/dist/tools/custom.cjs.map +1 -0
  65. package/dist/tools/custom.d.cts +10 -0
  66. package/dist/tools/custom.d.cts.map +1 -0
  67. package/dist/tools/custom.d.ts +8 -3
  68. package/dist/tools/custom.d.ts.map +1 -0
  69. package/dist/tools/custom.js +24 -23
  70. package/dist/tools/custom.js.map +1 -0
  71. package/dist/tools/dalle.cjs +104 -194
  72. package/dist/tools/dalle.cjs.map +1 -0
  73. package/dist/tools/dalle.d.cts +123 -0
  74. package/dist/tools/dalle.d.cts.map +1 -0
  75. package/dist/tools/dalle.d.ts +111 -104
  76. package/dist/tools/dalle.d.ts.map +1 -0
  77. package/dist/tools/dalle.js +102 -189
  78. package/dist/tools/dalle.js.map +1 -0
  79. package/dist/tools/index.cjs +1 -17
  80. package/dist/tools/index.js +1 -1
  81. package/dist/types.d.cts +263 -0
  82. package/dist/types.d.cts.map +1 -0
  83. package/dist/types.d.ts +244 -234
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/utils/azure.cjs +86 -47
  86. package/dist/utils/azure.cjs.map +1 -0
  87. package/dist/utils/azure.d.cts +76 -0
  88. package/dist/utils/azure.d.cts.map +1 -0
  89. package/dist/utils/azure.d.ts +51 -9
  90. package/dist/utils/azure.d.ts.map +1 -0
  91. package/dist/utils/azure.js +85 -45
  92. package/dist/utils/azure.js.map +1 -0
  93. package/dist/utils/client.cjs +25 -0
  94. package/dist/utils/client.cjs.map +1 -0
  95. package/dist/utils/client.d.cts +5 -0
  96. package/dist/utils/client.d.cts.map +1 -0
  97. package/dist/utils/client.d.ts +5 -0
  98. package/dist/utils/client.d.ts.map +1 -0
  99. package/dist/utils/client.js +24 -0
  100. package/dist/utils/client.js.map +1 -0
  101. package/dist/utils/errors.cjs +9 -8
  102. package/dist/utils/errors.cjs.map +1 -0
  103. package/dist/utils/errors.js +9 -6
  104. package/dist/utils/errors.js.map +1 -0
  105. package/dist/utils/message_inputs.cjs +139 -0
  106. package/dist/utils/message_inputs.cjs.map +1 -0
  107. package/dist/utils/message_inputs.d.cts +9 -0
  108. package/dist/utils/message_inputs.d.cts.map +1 -0
  109. package/dist/utils/message_inputs.d.ts +9 -0
  110. package/dist/utils/message_inputs.d.ts.map +1 -0
  111. package/dist/utils/message_inputs.js +137 -0
  112. package/dist/utils/message_inputs.js.map +1 -0
  113. package/dist/utils/misc.cjs +30 -0
  114. package/dist/utils/misc.cjs.map +1 -0
  115. package/dist/utils/misc.d.cts +9 -0
  116. package/dist/utils/misc.d.cts.map +1 -0
  117. package/dist/utils/misc.d.ts +9 -0
  118. package/dist/utils/misc.d.ts.map +1 -0
  119. package/dist/utils/misc.js +27 -0
  120. package/dist/utils/misc.js.map +1 -0
  121. package/dist/utils/output.cjs +74 -0
  122. package/dist/utils/output.cjs.map +1 -0
  123. package/dist/utils/output.js +72 -0
  124. package/dist/utils/output.js.map +1 -0
  125. package/dist/utils/prompts.cjs +39 -38
  126. package/dist/utils/prompts.cjs.map +1 -0
  127. package/dist/utils/prompts.d.cts +42 -0
  128. package/dist/utils/prompts.d.cts.map +1 -0
  129. package/dist/utils/prompts.d.ts +10 -4
  130. package/dist/utils/prompts.d.ts.map +1 -0
  131. package/dist/utils/prompts.js +40 -36
  132. package/dist/utils/prompts.js.map +1 -0
  133. package/dist/utils/standard.cjs +113 -0
  134. package/dist/utils/standard.cjs.map +1 -0
  135. package/dist/utils/standard.js +111 -0
  136. package/dist/utils/standard.js.map +1 -0
  137. package/dist/utils/tools.cjs +150 -127
  138. package/dist/utils/tools.cjs.map +1 -0
  139. package/dist/utils/tools.d.cts +13 -0
  140. package/dist/utils/tools.d.cts.map +1 -0
  141. package/dist/utils/tools.d.ts +12 -42
  142. package/dist/utils/tools.d.ts.map +1 -0
  143. package/dist/utils/tools.js +146 -123
  144. package/dist/utils/tools.js.map +1 -0
  145. package/package.json +33 -41
  146. package/dist/tools/index.d.ts +0 -1
  147. package/dist/types.cjs +0 -2
  148. package/dist/types.js +0 -1
  149. package/dist/utils/errors.d.ts +0 -2
  150. package/dist/utils/headers.cjs +0 -39
  151. package/dist/utils/headers.d.ts +0 -8
  152. package/dist/utils/headers.js +0 -35
  153. package/dist/utils/openai-format-fndef.cjs +0 -80
  154. package/dist/utils/openai-format-fndef.d.ts +0 -44
  155. package/dist/utils/openai-format-fndef.js +0 -77
  156. package/dist/utils/openai.cjs +0 -127
  157. package/dist/utils/openai.d.ts +0 -15
  158. package/dist/utils/openai.js +0 -119
  159. package/index.cjs +0 -1
  160. package/index.d.cts +0 -1
  161. package/index.d.ts +0 -1
  162. package/index.js +0 -1
@@ -1,192 +1,105 @@
1
- /* eslint-disable no-param-reassign */
1
+ import { OpenAI as OpenAI$1 } from "openai";
2
2
  import { getEnvironmentVariable } from "@langchain/core/utils/env";
3
- import { OpenAI as OpenAIClient } from "openai";
4
3
  import { Tool } from "@langchain/core/tools";
4
+
5
+ //#region src/tools/dalle.ts
5
6
  /**
6
- * A tool for generating images with Open AIs Dall-E 2 or 3 API.
7
- */
8
- export class DallEAPIWrapper extends Tool {
9
- static lc_name() {
10
- return "DallEAPIWrapper";
11
- }
12
- constructor(fields) {
13
- // Shim for new base tool param name
14
- if (fields?.responseFormat !== undefined &&
15
- ["url", "b64_json"].includes(fields.responseFormat)) {
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- fields.dallEResponseFormat = fields.responseFormat;
18
- fields.responseFormat = "content";
19
- }
20
- super(fields);
21
- Object.defineProperty(this, "name", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: "dalle_api_wrapper"
26
- });
27
- Object.defineProperty(this, "description", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: "A wrapper around OpenAI DALL-E API. Useful for when you need to generate images from a text description. Input should be an image description."
32
- });
33
- Object.defineProperty(this, "client", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: void 0
38
- });
39
- Object.defineProperty(this, "model", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: "dall-e-3"
44
- });
45
- Object.defineProperty(this, "style", {
46
- enumerable: true,
47
- configurable: true,
48
- writable: true,
49
- value: "vivid"
50
- });
51
- Object.defineProperty(this, "quality", {
52
- enumerable: true,
53
- configurable: true,
54
- writable: true,
55
- value: "standard"
56
- });
57
- Object.defineProperty(this, "n", {
58
- enumerable: true,
59
- configurable: true,
60
- writable: true,
61
- value: 1
62
- });
63
- Object.defineProperty(this, "size", {
64
- enumerable: true,
65
- configurable: true,
66
- writable: true,
67
- value: "1024x1024"
68
- });
69
- Object.defineProperty(this, "dallEResponseFormat", {
70
- enumerable: true,
71
- configurable: true,
72
- writable: true,
73
- value: "url"
74
- });
75
- Object.defineProperty(this, "user", {
76
- enumerable: true,
77
- configurable: true,
78
- writable: true,
79
- value: void 0
80
- });
81
- const openAIApiKey = fields?.apiKey ??
82
- fields?.openAIApiKey ??
83
- getEnvironmentVariable("OPENAI_API_KEY");
84
- const organization = fields?.organization ?? getEnvironmentVariable("OPENAI_ORGANIZATION");
85
- const clientConfig = {
86
- apiKey: openAIApiKey,
87
- organization,
88
- dangerouslyAllowBrowser: true,
89
- baseURL: fields?.baseUrl,
90
- };
91
- this.client = new OpenAIClient(clientConfig);
92
- this.model = fields?.model ?? fields?.modelName ?? this.model;
93
- this.style = fields?.style ?? this.style;
94
- this.quality = fields?.quality ?? this.quality;
95
- this.n = fields?.n ?? this.n;
96
- this.size = fields?.size ?? this.size;
97
- this.dallEResponseFormat =
98
- fields?.dallEResponseFormat ?? this.dallEResponseFormat;
99
- this.user = fields?.user;
100
- }
101
- /**
102
- * Processes the API response if multiple images are generated.
103
- * Returns a list of MessageContentImageUrl objects. If the response
104
- * format is `url`, then the `image_url` field will contain the URL.
105
- * If it is `b64_json`, then the `image_url` field will contain an object
106
- * with a `url` field with the base64 encoded image.
107
- *
108
- * @param {OpenAIClient.Images.ImagesResponse[]} response The API response
109
- * @returns {MessageContentImageUrl[]}
110
- */
111
- processMultipleGeneratedUrls(response) {
112
- if (this.dallEResponseFormat === "url") {
113
- return response.flatMap((res) => {
114
- const imageUrlContent = res.data
115
- ?.flatMap((item) => {
116
- if (!item.url)
117
- return [];
118
- return {
119
- type: "image_url",
120
- image_url: item.url,
121
- };
122
- })
123
- .filter((item) => item !== undefined &&
124
- item.type === "image_url" &&
125
- typeof item.image_url === "string" &&
126
- item.image_url !== undefined) ?? [];
127
- return imageUrlContent;
128
- });
129
- }
130
- else {
131
- return response.flatMap((res) => {
132
- const b64Content = res.data
133
- ?.flatMap((item) => {
134
- if (!item.b64_json)
135
- return [];
136
- return {
137
- type: "image_url",
138
- image_url: {
139
- url: item.b64_json,
140
- },
141
- };
142
- })
143
- .filter((item) => item !== undefined &&
144
- item.type === "image_url" &&
145
- typeof item.image_url === "object" &&
146
- "url" in item.image_url &&
147
- typeof item.image_url.url === "string" &&
148
- item.image_url.url !== undefined) ?? [];
149
- return b64Content;
150
- });
151
- }
152
- }
153
- /** @ignore */
154
- async _call(input) {
155
- const generateImageFields = {
156
- model: this.model,
157
- prompt: input,
158
- n: 1,
159
- size: this.size,
160
- response_format: this.dallEResponseFormat,
161
- style: this.style,
162
- quality: this.quality,
163
- user: this.user,
164
- };
165
- if (this.n > 1) {
166
- const results = await Promise.all(Array.from({ length: this.n }).map(() => this.client.images.generate(generateImageFields)));
167
- return this.processMultipleGeneratedUrls(results);
168
- }
169
- const response = await this.client.images.generate(generateImageFields);
170
- let data = "";
171
- if (this.dallEResponseFormat === "url") {
172
- [data] =
173
- response.data
174
- ?.map((item) => item.url)
175
- .filter((url) => url !== "undefined") ?? [];
176
- }
177
- else {
178
- [data] =
179
- response.data
180
- ?.map((item) => item.b64_json)
181
- .filter((b64_json) => b64_json !== "undefined") ??
182
- [];
183
- }
184
- return data;
185
- }
186
- }
187
- Object.defineProperty(DallEAPIWrapper, "toolName", {
188
- enumerable: true,
189
- configurable: true,
190
- writable: true,
191
- value: "dalle_api_wrapper"
192
- });
7
+ * A tool for generating images with Open AIs Dall-E 2 or 3 API.
8
+ */
9
+ var DallEAPIWrapper = class extends Tool {
10
+ static lc_name() {
11
+ return "DallEAPIWrapper";
12
+ }
13
+ name = "dalle_api_wrapper";
14
+ description = "A wrapper around OpenAI DALL-E API. Useful for when you need to generate images from a text description. Input should be an image description.";
15
+ client;
16
+ static toolName = "dalle_api_wrapper";
17
+ model = "dall-e-3";
18
+ style = "vivid";
19
+ quality = "standard";
20
+ n = 1;
21
+ size = "1024x1024";
22
+ dallEResponseFormat = "url";
23
+ user;
24
+ constructor(fields) {
25
+ if (fields?.responseFormat !== void 0 && ["url", "b64_json"].includes(fields.responseFormat)) {
26
+ fields.dallEResponseFormat = fields.responseFormat;
27
+ fields.responseFormat = "content";
28
+ }
29
+ super(fields);
30
+ const openAIApiKey = fields?.apiKey ?? fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
31
+ const organization = fields?.organization ?? getEnvironmentVariable("OPENAI_ORGANIZATION");
32
+ const clientConfig = {
33
+ apiKey: openAIApiKey,
34
+ organization,
35
+ dangerouslyAllowBrowser: true,
36
+ baseURL: fields?.baseUrl
37
+ };
38
+ this.client = new OpenAI$1(clientConfig);
39
+ this.model = fields?.model ?? fields?.modelName ?? this.model;
40
+ this.style = fields?.style ?? this.style;
41
+ this.quality = fields?.quality ?? this.quality;
42
+ this.n = fields?.n ?? this.n;
43
+ this.size = fields?.size ?? this.size;
44
+ this.dallEResponseFormat = fields?.dallEResponseFormat ?? this.dallEResponseFormat;
45
+ this.user = fields?.user;
46
+ }
47
+ /**
48
+ * Processes the API response if multiple images are generated.
49
+ * Returns a list of MessageContentImageUrl objects. If the response
50
+ * format is `url`, then the `image_url` field will contain the URL.
51
+ * If it is `b64_json`, then the `image_url` field will contain an object
52
+ * with a `url` field with the base64 encoded image.
53
+ *
54
+ * @param {OpenAIClient.Images.ImagesResponse[]} response The API response
55
+ * @returns {MessageContentImageUrl[]}
56
+ */
57
+ processMultipleGeneratedUrls(response) {
58
+ if (this.dallEResponseFormat === "url") return response.flatMap((res) => {
59
+ const imageUrlContent = res.data?.flatMap((item) => {
60
+ if (!item.url) return [];
61
+ return {
62
+ type: "image_url",
63
+ image_url: item.url
64
+ };
65
+ }).filter((item) => item !== void 0 && item.type === "image_url" && typeof item.image_url === "string" && item.image_url !== void 0) ?? [];
66
+ return imageUrlContent;
67
+ });
68
+ else return response.flatMap((res) => {
69
+ const b64Content = res.data?.flatMap((item) => {
70
+ if (!item.b64_json) return [];
71
+ return {
72
+ type: "image_url",
73
+ image_url: { url: item.b64_json }
74
+ };
75
+ }).filter((item) => item !== void 0 && item.type === "image_url" && typeof item.image_url === "object" && "url" in item.image_url && typeof item.image_url.url === "string" && item.image_url.url !== void 0) ?? [];
76
+ return b64Content;
77
+ });
78
+ }
79
+ /** @ignore */
80
+ async _call(input) {
81
+ const generateImageFields = {
82
+ model: this.model,
83
+ prompt: input,
84
+ n: 1,
85
+ size: this.size,
86
+ response_format: this.dallEResponseFormat,
87
+ style: this.style,
88
+ quality: this.quality,
89
+ user: this.user
90
+ };
91
+ if (this.n > 1) {
92
+ const results = await Promise.all(Array.from({ length: this.n }).map(() => this.client.images.generate(generateImageFields)));
93
+ return this.processMultipleGeneratedUrls(results);
94
+ }
95
+ const response = await this.client.images.generate(generateImageFields);
96
+ let data = "";
97
+ if (this.dallEResponseFormat === "url") [data] = response.data?.map((item) => item.url).filter((url) => url !== "undefined") ?? [];
98
+ else [data] = response.data?.map((item) => item.b64_json).filter((b64_json) => b64_json !== "undefined") ?? [];
99
+ return data;
100
+ }
101
+ };
102
+
103
+ //#endregion
104
+ export { DallEAPIWrapper };
105
+ //# sourceMappingURL=dalle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dalle.js","names":["fields?: DallEAPIWrapperParams","OpenAIClient","response: OpenAIClient.Images.ImagesResponse[]","input: string"],"sources":["../../src/tools/dalle.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { getEnvironmentVariable } from \"@langchain/core/utils/env\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { Tool, ToolParams } from \"@langchain/core/tools\";\nimport {\n MessageContentComplex,\n MessageContentImageUrl,\n} from \"@langchain/core/messages\";\n\n/**\n * @see https://platform.openai.com/docs/api-reference/images/create\n */\nexport type OpenAIImageModelId =\n | OpenAIClient.ImageModel\n | (string & NonNullable<unknown>);\n\n/**\n * An interface for the Dall-E API Wrapper.\n */\nexport interface DallEAPIWrapperParams extends ToolParams {\n /**\n * The OpenAI API key\n * Alias for `apiKey`\n */\n openAIApiKey?: string;\n /**\n * The OpenAI API key\n */\n apiKey?: string;\n /**\n * The model to use.\n * Alias for `model`\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n * @deprecated Use `model` instead.\n */\n modelName?: OpenAIImageModelId;\n /**\n * The model to use.\n * @params \"dall-e-2\" | \"dall-e-3\"\n * @default \"dall-e-3\"\n */\n model?: OpenAIImageModelId;\n /**\n * The style of the generated images. Must be one of vivid or natural.\n * Vivid causes the model to lean towards generating hyper-real and dramatic images.\n * Natural causes the model to produce more natural, less hyper-real looking images.\n * @default \"vivid\"\n */\n style?: \"natural\" | \"vivid\";\n /**\n * The quality of the image that will be generated. ‘hd’ creates images with finer\n * details and greater consistency across the image.\n * @default \"standard\"\n */\n quality?: \"standard\" | \"hd\";\n /**\n * The number of images to generate.\n * Must be between 1 and 10.\n * For dall-e-3, only `n: 1` is supported.\n * @default 1\n */\n n?: number;\n /**\n * The size of the generated images.\n * Must be one of 256x256, 512x512, or 1024x1024 for DALL·E-2 models.\n * Must be one of 1024x1024, 1792x1024, or 1024x1792 for DALL·E-3 models.\n * @default \"1024x1024\"\n */\n size?: \"256x256\" | \"512x512\" | \"1024x1024\" | \"1792x1024\" | \"1024x1792\";\n /**\n * The format in which the generated images are returned.\n * Must be one of \"url\" or \"b64_json\".\n * @default \"url\"\n */\n dallEResponseFormat?: \"url\" | \"b64_json\";\n /**\n * @deprecated Use dallEResponseFormat instead for the Dall-E response type.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n responseFormat?: any;\n /**\n * A unique identifier representing your end-user, which will help\n * OpenAI to monitor and detect abuse.\n */\n user?: string;\n /**\n * The organization to use\n */\n organization?: string;\n /**\n * The base URL of the OpenAI API.\n */\n baseUrl?: string;\n}\n\n/**\n * A tool for generating images with Open AIs Dall-E 2 or 3 API.\n */\nexport class DallEAPIWrapper extends Tool {\n static lc_name() {\n return \"DallEAPIWrapper\";\n }\n\n name = \"dalle_api_wrapper\";\n\n description =\n \"A wrapper around OpenAI DALL-E API. Useful for when you need to generate images from a text description. Input should be an image description.\";\n\n protected client: OpenAIClient;\n\n static readonly toolName = \"dalle_api_wrapper\";\n\n private model = \"dall-e-3\";\n\n private style: \"natural\" | \"vivid\" = \"vivid\";\n\n private quality: \"standard\" | \"hd\" = \"standard\";\n\n private n = 1;\n\n private size:\n | \"256x256\"\n | \"512x512\"\n | \"1024x1024\"\n | \"1792x1024\"\n | \"1024x1792\" = \"1024x1024\";\n\n private dallEResponseFormat: \"url\" | \"b64_json\" = \"url\";\n\n private user?: string;\n\n constructor(fields?: DallEAPIWrapperParams) {\n // Shim for new base tool param name\n if (\n fields?.responseFormat !== undefined &&\n [\"url\", \"b64_json\"].includes(fields.responseFormat)\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields.dallEResponseFormat = fields.responseFormat as any;\n fields.responseFormat = \"content\";\n }\n super(fields);\n const openAIApiKey =\n fields?.apiKey ??\n fields?.openAIApiKey ??\n getEnvironmentVariable(\"OPENAI_API_KEY\");\n\n const organization =\n fields?.organization ?? getEnvironmentVariable(\"OPENAI_ORGANIZATION\");\n\n const clientConfig = {\n apiKey: openAIApiKey,\n organization,\n dangerouslyAllowBrowser: true,\n baseURL: fields?.baseUrl,\n };\n this.client = new OpenAIClient(clientConfig);\n this.model = fields?.model ?? fields?.modelName ?? this.model;\n this.style = fields?.style ?? this.style;\n this.quality = fields?.quality ?? this.quality;\n this.n = fields?.n ?? this.n;\n this.size = fields?.size ?? this.size;\n this.dallEResponseFormat =\n fields?.dallEResponseFormat ?? this.dallEResponseFormat;\n this.user = fields?.user;\n }\n\n /**\n * Processes the API response if multiple images are generated.\n * Returns a list of MessageContentImageUrl objects. If the response\n * format is `url`, then the `image_url` field will contain the URL.\n * If it is `b64_json`, then the `image_url` field will contain an object\n * with a `url` field with the base64 encoded image.\n *\n * @param {OpenAIClient.Images.ImagesResponse[]} response The API response\n * @returns {MessageContentImageUrl[]}\n */\n private processMultipleGeneratedUrls(\n response: OpenAIClient.Images.ImagesResponse[]\n ): MessageContentImageUrl[] {\n if (this.dallEResponseFormat === \"url\") {\n return response.flatMap((res) => {\n const imageUrlContent =\n res.data\n ?.flatMap((item) => {\n if (!item.url) return [];\n return {\n type: \"image_url\" as const,\n image_url: item.url,\n };\n })\n .filter(\n (item) =>\n item !== undefined &&\n item.type === \"image_url\" &&\n typeof item.image_url === \"string\" &&\n item.image_url !== undefined\n ) ?? [];\n return imageUrlContent;\n });\n } else {\n return response.flatMap((res) => {\n const b64Content =\n res.data\n ?.flatMap((item) => {\n if (!item.b64_json) return [];\n return {\n type: \"image_url\" as const,\n image_url: {\n url: item.b64_json,\n },\n };\n })\n .filter(\n (item) =>\n item !== undefined &&\n item.type === \"image_url\" &&\n typeof item.image_url === \"object\" &&\n \"url\" in item.image_url &&\n typeof item.image_url.url === \"string\" &&\n item.image_url.url !== undefined\n ) ?? [];\n return b64Content;\n });\n }\n }\n\n /** @ignore */\n async _call(input: string): Promise<string | MessageContentComplex[]> {\n const generateImageFields = {\n model: this.model,\n prompt: input,\n n: 1,\n size: this.size,\n response_format: this.dallEResponseFormat,\n style: this.style,\n quality: this.quality,\n user: this.user,\n };\n\n if (this.n > 1) {\n const results = await Promise.all(\n Array.from({ length: this.n }).map(() =>\n this.client.images.generate(generateImageFields)\n )\n );\n\n return this.processMultipleGeneratedUrls(results);\n }\n\n const response = await this.client.images.generate(generateImageFields);\n\n let data = \"\";\n if (this.dallEResponseFormat === \"url\") {\n [data] =\n response.data\n ?.map((item) => item.url)\n .filter((url): url is string => url !== \"undefined\") ?? [];\n } else {\n [data] =\n response.data\n ?.map((item) => item.b64_json)\n .filter((b64_json): b64_json is string => b64_json !== \"undefined\") ??\n [];\n }\n return data;\n }\n}\n"],"mappings":";;;;;;;;AAmGA,IAAa,kBAAb,cAAqC,KAAK;CACxC,OAAO,UAAU;AACf,SAAO;CACR;CAED,OAAO;CAEP,cACE;CAEF,AAAU;CAEV,OAAgB,WAAW;CAE3B,AAAQ,QAAQ;CAEhB,AAAQ,QAA6B;CAErC,AAAQ,UAA6B;CAErC,AAAQ,IAAI;CAEZ,AAAQ,OAKU;CAElB,AAAQ,sBAA0C;CAElD,AAAQ;CAER,YAAYA,QAAgC;AAE1C,MACE,QAAQ,mBAAmB,UAC3B,CAAC,OAAO,UAAW,EAAC,SAAS,OAAO,eAAe,EACnD;GAEA,OAAO,sBAAsB,OAAO;GACpC,OAAO,iBAAiB;EACzB;EACD,MAAM,OAAO;EACb,MAAM,eACJ,QAAQ,UACR,QAAQ,gBACR,uBAAuB,iBAAiB;EAE1C,MAAM,eACJ,QAAQ,gBAAgB,uBAAuB,sBAAsB;EAEvE,MAAM,eAAe;GACnB,QAAQ;GACR;GACA,yBAAyB;GACzB,SAAS,QAAQ;EAClB;EACD,KAAK,SAAS,IAAIC,SAAa;EAC/B,KAAK,QAAQ,QAAQ,SAAS,QAAQ,aAAa,KAAK;EACxD,KAAK,QAAQ,QAAQ,SAAS,KAAK;EACnC,KAAK,UAAU,QAAQ,WAAW,KAAK;EACvC,KAAK,IAAI,QAAQ,KAAK,KAAK;EAC3B,KAAK,OAAO,QAAQ,QAAQ,KAAK;EACjC,KAAK,sBACH,QAAQ,uBAAuB,KAAK;EACtC,KAAK,OAAO,QAAQ;CACrB;;;;;;;;;;;CAYD,AAAQ,6BACNC,UAC0B;AAC1B,MAAI,KAAK,wBAAwB,MAC/B,QAAO,SAAS,QAAQ,CAAC,QAAQ;GAC/B,MAAM,kBACJ,IAAI,MACA,QAAQ,CAAC,SAAS;AAClB,QAAI,CAAC,KAAK,IAAK,QAAO,CAAE;AACxB,WAAO;KACL,MAAM;KACN,WAAW,KAAK;IACjB;GACF,EAAC,CACD,OACC,CAAC,SACC,SAAS,UACT,KAAK,SAAS,eACd,OAAO,KAAK,cAAc,YAC1B,KAAK,cAAc,OACtB,IAAI,CAAE;AACX,UAAO;EACR,EAAC;MAEF,QAAO,SAAS,QAAQ,CAAC,QAAQ;GAC/B,MAAM,aACJ,IAAI,MACA,QAAQ,CAAC,SAAS;AAClB,QAAI,CAAC,KAAK,SAAU,QAAO,CAAE;AAC7B,WAAO;KACL,MAAM;KACN,WAAW,EACT,KAAK,KAAK,SACX;IACF;GACF,EAAC,CACD,OACC,CAAC,SACC,SAAS,UACT,KAAK,SAAS,eACd,OAAO,KAAK,cAAc,YAC1B,SAAS,KAAK,aACd,OAAO,KAAK,UAAU,QAAQ,YAC9B,KAAK,UAAU,QAAQ,OAC1B,IAAI,CAAE;AACX,UAAO;EACR,EAAC;CAEL;;CAGD,MAAM,MAAMC,OAA0D;EACpE,MAAM,sBAAsB;GAC1B,OAAO,KAAK;GACZ,QAAQ;GACR,GAAG;GACH,MAAM,KAAK;GACX,iBAAiB,KAAK;GACtB,OAAO,KAAK;GACZ,SAAS,KAAK;GACd,MAAM,KAAK;EACZ;AAED,MAAI,KAAK,IAAI,GAAG;GACd,MAAM,UAAU,MAAM,QAAQ,IAC5B,MAAM,KAAK,EAAE,QAAQ,KAAK,EAAG,EAAC,CAAC,IAAI,MACjC,KAAK,OAAO,OAAO,SAAS,oBAAoB,CACjD,CACF;AAED,UAAO,KAAK,6BAA6B,QAAQ;EAClD;EAED,MAAM,WAAW,MAAM,KAAK,OAAO,OAAO,SAAS,oBAAoB;EAEvE,IAAI,OAAO;AACX,MAAI,KAAK,wBAAwB,OAC/B,CAAC,KAAK,GACJ,SAAS,MACL,IAAI,CAAC,SAAS,KAAK,IAAI,CACxB,OAAO,CAAC,QAAuB,QAAQ,YAAY,IAAI,CAAE;OAE9D,CAAC,KAAK,GACJ,SAAS,MACL,IAAI,CAAC,SAAS,KAAK,SAAS,CAC7B,OAAO,CAAC,aAAiC,aAAa,YAAY,IACrE,CAAE;AAEN,SAAO;CACR;AACF"}
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./dalle.cjs"), exports);
1
+ const require_dalle = require('./dalle.cjs');
@@ -1 +1 @@
1
- export * from "./dalle.js";
1
+ import { DallEAPIWrapper } from "./dalle.js";
@@ -0,0 +1,263 @@
1
+ import { OpenAI as OpenAI$1 } from "openai";
2
+ import { BaseLanguageModelCallOptions } from "@langchain/core/language_models/base";
3
+ import { InteropZodObject } from "@langchain/core/utils/types";
4
+ import { ResponseFormatJSONObject, ResponseFormatJSONSchema, ResponseFormatText, ResponseFormatTextGrammar, ResponseFormatTextPython } from "openai/resources/shared";
5
+ import { TiktokenModel } from "js-tiktoken/lite";
6
+
7
+ //#region src/types.d.ts
8
+
9
+ /**
10
+ * @see https://platform.openai.com/docs/models
11
+ */
12
+ type OpenAIChatModelId = OpenAI$1.ChatModel | (string & NonNullable<unknown>);
13
+ type OpenAIVerbosityParam = "low" | "medium" | "high" | null;
14
+ declare interface OpenAIBaseInput {
15
+ /** Sampling temperature to use */
16
+ temperature: number;
17
+ /**
18
+ * Maximum number of tokens to generate in the completion. -1 returns as many
19
+ * tokens as possible given the prompt and the model's maximum context size.
20
+ */
21
+ maxTokens?: number;
22
+ /**
23
+ * Maximum number of tokens to generate in the completion. -1 returns as many
24
+ * tokens as possible given the prompt and the model's maximum context size.
25
+ * Alias for `maxTokens` for reasoning models.
26
+ */
27
+ maxCompletionTokens?: number;
28
+ /** Total probability mass of tokens to consider at each step */
29
+ topP: number;
30
+ /** Penalizes repeated tokens according to frequency */
31
+ frequencyPenalty: number;
32
+ /** Penalizes repeated tokens */
33
+ presencePenalty: number;
34
+ /** Number of completions to generate for each prompt */
35
+ n: number;
36
+ /** Dictionary used to adjust the probability of specific tokens being generated */
37
+ logitBias?: Record<string, number>;
38
+ /** Unique string identifier representing your end-user, which can help OpenAI to monitor and detect abuse. */
39
+ user?: string;
40
+ /** Whether to stream the results or not. Enabling disables tokenUsage reporting */
41
+ streaming: boolean;
42
+ /**
43
+ * Whether or not to include token usage data in streamed chunks.
44
+ * @default true
45
+ */
46
+ streamUsage?: boolean;
47
+ /**
48
+ * Model name to use
49
+ * Alias for `model`
50
+ * @deprecated Use "model" instead.
51
+ */
52
+ modelName: string;
53
+ /** Model name to use */
54
+ model: OpenAIChatModelId;
55
+ /** Holds any additional parameters that are valid to pass to {@link
56
+ * https://platform.openai.com/docs/api-reference/completions/create |
57
+ * `openai.createCompletion`} that are not explicitly specified on this class.
58
+ */
59
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+ modelKwargs?: Record<string, any>;
61
+ /**
62
+ * List of stop words to use when generating
63
+ * Alias for `stopSequences`
64
+ */
65
+ stop?: string[];
66
+ /** List of stop words to use when generating */
67
+ stopSequences?: string[];
68
+ /**
69
+ * Timeout to use when making requests to OpenAI.
70
+ */
71
+ timeout?: number;
72
+ /**
73
+ * API key to use when making requests to OpenAI. Defaults to the value of
74
+ * `OPENAI_API_KEY` environment variable.
75
+ * Alias for `apiKey`
76
+ */
77
+ openAIApiKey?: string;
78
+ /**
79
+ * API key to use when making requests to OpenAI. Defaults to the value of
80
+ * `OPENAI_API_KEY` environment variable.
81
+ */
82
+ apiKey?: string;
83
+ /**
84
+ * The verbosity of the model's response.
85
+ */
86
+ verbosity?: OpenAIVerbosityParam;
87
+ }
88
+ type OpenAICoreRequestOptions = OpenAI$1.RequestOptions;
89
+ interface OpenAICallOptions extends BaseLanguageModelCallOptions {
90
+ /**
91
+ * Additional options to pass to the underlying axios request.
92
+ */
93
+ options?: OpenAICoreRequestOptions;
94
+ }
95
+ /**
96
+ * Input to OpenAI class.
97
+ */
98
+ declare interface OpenAIInput extends OpenAIBaseInput {
99
+ /** Generates `bestOf` completions server side and returns the "best" */
100
+ bestOf?: number;
101
+ /** Batch size to use when passing multiple documents to generate */
102
+ batchSize: number;
103
+ }
104
+ interface OpenAIChatInput extends OpenAIBaseInput {
105
+ /**
106
+ * Whether to return log probabilities of the output tokens or not.
107
+ * If true, returns the log probabilities of each output token returned in the content of message.
108
+ */
109
+ logprobs?: boolean;
110
+ /**
111
+ * An integer between 0 and 5 specifying the number of most likely tokens to return at each token position,
112
+ * each with an associated log probability. logprobs must be set to true if this parameter is used.
113
+ */
114
+ topLogprobs?: number;
115
+ /** ChatGPT messages to pass as a prefix to the prompt */
116
+ prefixMessages?: OpenAI$1.Chat.ChatCompletionMessageParam[];
117
+ /**
118
+ * Whether to include the raw OpenAI response in the output message's "additional_kwargs" field.
119
+ * Currently in experimental beta.
120
+ */
121
+ __includeRawResponse?: boolean;
122
+ /**
123
+ * Whether the model supports the `strict` argument when passing in tools.
124
+ * If `undefined` the `strict` argument will not be passed to OpenAI.
125
+ */
126
+ supportsStrictToolCalling?: boolean;
127
+ /**
128
+ * Output types that you would like the model to generate for this request. Most
129
+ * models are capable of generating text, which is the default:
130
+ *
131
+ * `["text"]`
132
+ *
133
+ * The `gpt-4o-audio-preview` model can also be used to
134
+ * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
135
+ * this model generate both text and audio responses, you can use:
136
+ *
137
+ * `["text", "audio"]`
138
+ */
139
+ modalities?: Array<OpenAI$1.Chat.ChatCompletionModality>;
140
+ /**
141
+ * Parameters for audio output. Required when audio output is requested with
142
+ * `modalities: ["audio"]`.
143
+ * [Learn more](https://platform.openai.com/docs/guides/audio).
144
+ */
145
+ audio?: OpenAI$1.Chat.ChatCompletionAudioParam;
146
+ /**
147
+ * Options for reasoning models.
148
+ *
149
+ * Note that some options, like reasoning summaries, are only available when using the responses
150
+ * API. This option is ignored when not using a reasoning model.
151
+ */
152
+ reasoning?: OpenAI$1.Reasoning;
153
+ /**
154
+ * Should be set to `true` in tenancies with Zero Data Retention
155
+ * @see https://platform.openai.com/docs/guides/your-data
156
+ *
157
+ * @default false
158
+ */
159
+ zdrEnabled?: boolean;
160
+ /**
161
+ * Service tier to use for this request. Can be "auto", "default", or "flex" or "priority".
162
+ * Specifies the service tier for prioritization and latency optimization.
163
+ */
164
+ service_tier?: OpenAI$1.Responses.ResponseCreateParams["service_tier"];
165
+ /**
166
+ * Used by OpenAI to cache responses for similar requests to optimize your cache
167
+ * hit rates. Replaces the `user` field.
168
+ * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
169
+ */
170
+ promptCacheKey?: string;
171
+ }
172
+ interface AzureOpenAIInput {
173
+ /**
174
+ * API version to use when making requests to Azure OpenAI.
175
+ */
176
+ azureOpenAIApiVersion?: string;
177
+ /**
178
+ * API key to use when making requests to Azure OpenAI.
179
+ */
180
+ azureOpenAIApiKey?: string;
181
+ /**
182
+ * Azure OpenAI API instance name to use when making requests to Azure OpenAI.
183
+ * this is the name of the instance you created in the Azure portal.
184
+ * e.g. "my-openai-instance"
185
+ * this will be used in the endpoint URL: https://my-openai-instance.openai.azure.com/openai/deployments/{DeploymentName}/
186
+ */
187
+ azureOpenAIApiInstanceName?: string;
188
+ /**
189
+ * Azure OpenAI API deployment name to use for completions when making requests to Azure OpenAI.
190
+ * This is the name of the deployment you created in the Azure portal.
191
+ * e.g. "my-openai-deployment"
192
+ * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/
193
+ */
194
+ azureOpenAIApiDeploymentName?: string;
195
+ /**
196
+ * Azure OpenAI API deployment name to use for embedding when making requests to Azure OpenAI.
197
+ * This is the name of the deployment you created in the Azure portal.
198
+ * This will fallback to azureOpenAIApiDeploymentName if not provided.
199
+ * e.g. "my-openai-deployment"
200
+ * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/
201
+ */
202
+ azureOpenAIApiEmbeddingsDeploymentName?: string;
203
+ /**
204
+ * Azure OpenAI API deployment name to use for completions when making requests to Azure OpenAI.
205
+ * Completions are only available for gpt-3.5-turbo and text-davinci-003 deployments.
206
+ * This is the name of the deployment you created in the Azure portal.
207
+ * This will fallback to azureOpenAIApiDeploymentName if not provided.
208
+ * e.g. "my-openai-deployment"
209
+ * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/
210
+ */
211
+ azureOpenAIApiCompletionsDeploymentName?: string;
212
+ /**
213
+ * Custom base url for Azure OpenAI API. This is useful in case you have a deployment in another region.
214
+ * e.g. setting this value to "https://westeurope.api.cognitive.microsoft.com/openai/deployments"
215
+ * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/
216
+ */
217
+ azureOpenAIBasePath?: string;
218
+ /**
219
+ * Custom endpoint for Azure OpenAI API. This is useful in case you have a deployment in another region.
220
+ * e.g. setting this value to "https://westeurope.api.cognitive.microsoft.com/"
221
+ * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/
222
+ */
223
+ azureOpenAIEndpoint?: string;
224
+ /**
225
+ * A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),
226
+ * which will be invoked on every request.
227
+ */
228
+ azureADTokenProvider?: () => Promise<string>;
229
+ }
230
+ interface AzureOpenAIChatInput extends OpenAIChatInput, AzureOpenAIInput {
231
+ openAIApiKey?: string;
232
+ openAIApiVersion?: string;
233
+ openAIBasePath?: string;
234
+ deploymentName?: string;
235
+ }
236
+ type ChatOpenAIResponseFormatJSONSchema = Omit<ResponseFormatJSONSchema, "json_schema"> & {
237
+ json_schema: Omit<ResponseFormatJSONSchema["json_schema"], "schema"> & {
238
+ /**
239
+ * The schema for the response format, described as a JSON Schema object
240
+ * or a Zod object.
241
+ */
242
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
+ schema: Record<string, any> | InteropZodObject;
244
+ };
245
+ };
246
+ /**
247
+ * The summary of a model's reasoning step.
248
+ */
249
+ type ChatOpenAIReasoningSummary = Omit<OpenAI$1.Responses.ResponseReasoningItem, "summary"> & {
250
+ /**
251
+ * The summary of the reasoning step. The index field will be populated if the response was
252
+ * streamed. This allows LangChain to recompose the reasoning summary output correctly when the
253
+ * AIMessage is used as an input for future generation requests.
254
+ */
255
+ summary: Array<OpenAI$1.Responses.ResponseReasoningItem.Summary & {
256
+ index?: number;
257
+ }>;
258
+ };
259
+ type ChatOpenAIResponseFormat = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatTextGrammar | ResponseFormatTextPython | ChatOpenAIResponseFormatJSONSchema;
260
+ type ResponseFormatConfiguration = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema;
261
+ //#endregion
262
+ export { AzureOpenAIChatInput, AzureOpenAIInput, ChatOpenAIReasoningSummary, ChatOpenAIResponseFormat, OpenAIBaseInput, OpenAICallOptions, OpenAIChatInput, OpenAIChatModelId, OpenAICoreRequestOptions, OpenAIInput, OpenAIVerbosityParam, ResponseFormatConfiguration, type TiktokenModel };
263
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":["OpenAI","OpenAIClient","ResponseFormatText","ResponseFormatJSONObject","ResponseFormatJSONSchema","ResponseFormatTextPython","ResponseFormatTextGrammar","TiktokenModel","BaseLanguageModelCallOptions","InteropZodObject","OpenAIChatModelId","ChatModel","NonNullable","OpenAIVerbosityParam","OpenAIBaseInput","Record","OpenAICoreRequestOptions","RequestOptions","OpenAICallOptions","OpenAIInput","OpenAIChatInput","Chat","ChatCompletionMessageParam","ChatCompletionModality","Array","ChatCompletionAudioParam","Reasoning","Responses","ResponseCreateParams","AzureOpenAIInput","Promise","AzureOpenAIChatInput","ChatOpenAIResponseFormatJSONSchema","Omit","ChatOpenAIReasoningSummary","ResponseReasoningItem","Summary","ChatOpenAIResponseFormat","ResponseFormatConfiguration"],"sources":["../src/types.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport type { ResponseFormatText, ResponseFormatJSONObject, ResponseFormatJSONSchema, ResponseFormatTextPython, ResponseFormatTextGrammar } from \"openai/resources/shared\";\nimport { TiktokenModel } from \"js-tiktoken/lite\";\nimport type { BaseLanguageModelCallOptions } from \"@langchain/core/language_models/base\";\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\n// reexport this type from the included package so we can easily override and extend it if needed in the future\n// also makes it easier for folks to import this type without digging around into the dependent packages\nexport type { TiktokenModel };\n/**\n * @see https://platform.openai.com/docs/models\n */\nexport type OpenAIChatModelId = OpenAIClient.ChatModel | (string & NonNullable<unknown>);\nexport type OpenAIVerbosityParam = \"low\" | \"medium\" | \"high\" | null;\nexport declare interface OpenAIBaseInput {\n /** Sampling temperature to use */\n temperature: number;\n /**\n * Maximum number of tokens to generate in the completion. -1 returns as many\n * tokens as possible given the prompt and the model's maximum context size.\n */\n maxTokens?: number;\n /**\n * Maximum number of tokens to generate in the completion. -1 returns as many\n * tokens as possible given the prompt and the model's maximum context size.\n * Alias for `maxTokens` for reasoning models.\n */\n maxCompletionTokens?: number;\n /** Total probability mass of tokens to consider at each step */\n topP: number;\n /** Penalizes repeated tokens according to frequency */\n frequencyPenalty: number;\n /** Penalizes repeated tokens */\n presencePenalty: number;\n /** Number of completions to generate for each prompt */\n n: number;\n /** Dictionary used to adjust the probability of specific tokens being generated */\n logitBias?: Record<string, number>;\n /** Unique string identifier representing your end-user, which can help OpenAI to monitor and detect abuse. */\n user?: string;\n /** Whether to stream the results or not. Enabling disables tokenUsage reporting */\n streaming: boolean;\n /**\n * Whether or not to include token usage data in streamed chunks.\n * @default true\n */\n streamUsage?: boolean;\n /**\n * Model name to use\n * Alias for `model`\n * @deprecated Use \"model\" instead.\n */\n modelName: string;\n /** Model name to use */\n model: OpenAIChatModelId;\n /** Holds any additional parameters that are valid to pass to {@link\n * https://platform.openai.com/docs/api-reference/completions/create |\n * `openai.createCompletion`} that are not explicitly specified on this class.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n modelKwargs?: Record<string, any>;\n /**\n * List of stop words to use when generating\n * Alias for `stopSequences`\n */\n stop?: string[];\n /** List of stop words to use when generating */\n stopSequences?: string[];\n /**\n * Timeout to use when making requests to OpenAI.\n */\n timeout?: number;\n /**\n * API key to use when making requests to OpenAI. Defaults to the value of\n * `OPENAI_API_KEY` environment variable.\n * Alias for `apiKey`\n */\n openAIApiKey?: string;\n /**\n * API key to use when making requests to OpenAI. Defaults to the value of\n * `OPENAI_API_KEY` environment variable.\n */\n apiKey?: string;\n /**\n * The verbosity of the model's response.\n */\n verbosity?: OpenAIVerbosityParam;\n}\nexport type OpenAICoreRequestOptions = OpenAIClient.RequestOptions;\nexport interface OpenAICallOptions extends BaseLanguageModelCallOptions {\n /**\n * Additional options to pass to the underlying axios request.\n */\n options?: OpenAICoreRequestOptions;\n}\n/**\n * Input to OpenAI class.\n */\nexport declare interface OpenAIInput extends OpenAIBaseInput {\n /** Generates `bestOf` completions server side and returns the \"best\" */\n bestOf?: number;\n /** Batch size to use when passing multiple documents to generate */\n batchSize: number;\n}\nexport interface OpenAIChatInput extends OpenAIBaseInput {\n /**\n * Whether to return log probabilities of the output tokens or not.\n * If true, returns the log probabilities of each output token returned in the content of message.\n */\n logprobs?: boolean;\n /**\n * An integer between 0 and 5 specifying the number of most likely tokens to return at each token position,\n * each with an associated log probability. logprobs must be set to true if this parameter is used.\n */\n topLogprobs?: number;\n /** ChatGPT messages to pass as a prefix to the prompt */\n prefixMessages?: OpenAIClient.Chat.ChatCompletionMessageParam[];\n /**\n * Whether to include the raw OpenAI response in the output message's \"additional_kwargs\" field.\n * Currently in experimental beta.\n */\n __includeRawResponse?: boolean;\n /**\n * Whether the model supports the `strict` argument when passing in tools.\n * If `undefined` the `strict` argument will not be passed to OpenAI.\n */\n supportsStrictToolCalling?: boolean;\n /**\n * Output types that you would like the model to generate for this request. Most\n * models are capable of generating text, which is the default:\n *\n * `[\"text\"]`\n *\n * The `gpt-4o-audio-preview` model can also be used to\n * [generate audio](https://platform.openai.com/docs/guides/audio). To request that\n * this model generate both text and audio responses, you can use:\n *\n * `[\"text\", \"audio\"]`\n */\n modalities?: Array<OpenAIClient.Chat.ChatCompletionModality>;\n /**\n * Parameters for audio output. Required when audio output is requested with\n * `modalities: [\"audio\"]`.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\n audio?: OpenAIClient.Chat.ChatCompletionAudioParam;\n /**\n * Options for reasoning models.\n *\n * Note that some options, like reasoning summaries, are only available when using the responses\n * API. This option is ignored when not using a reasoning model.\n */\n reasoning?: OpenAIClient.Reasoning;\n /**\n * Should be set to `true` in tenancies with Zero Data Retention\n * @see https://platform.openai.com/docs/guides/your-data\n *\n * @default false\n */\n zdrEnabled?: boolean;\n /**\n * Service tier to use for this request. Can be \"auto\", \"default\", or \"flex\" or \"priority\".\n * Specifies the service tier for prioritization and latency optimization.\n */\n service_tier?: OpenAIClient.Responses.ResponseCreateParams[\"service_tier\"];\n /**\n * Used by OpenAI to cache responses for similar requests to optimize your cache\n * hit rates. Replaces the `user` field.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n */\n promptCacheKey?: string;\n}\nexport interface AzureOpenAIInput {\n /**\n * API version to use when making requests to Azure OpenAI.\n */\n azureOpenAIApiVersion?: string;\n /**\n * API key to use when making requests to Azure OpenAI.\n */\n azureOpenAIApiKey?: string;\n /**\n * Azure OpenAI API instance name to use when making requests to Azure OpenAI.\n * this is the name of the instance you created in the Azure portal.\n * e.g. \"my-openai-instance\"\n * this will be used in the endpoint URL: https://my-openai-instance.openai.azure.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIApiInstanceName?: string;\n /**\n * Azure OpenAI API deployment name to use for completions when making requests to Azure OpenAI.\n * This is the name of the deployment you created in the Azure portal.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiDeploymentName?: string;\n /**\n * Azure OpenAI API deployment name to use for embedding when making requests to Azure OpenAI.\n * This is the name of the deployment you created in the Azure portal.\n * This will fallback to azureOpenAIApiDeploymentName if not provided.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiEmbeddingsDeploymentName?: string;\n /**\n * Azure OpenAI API deployment name to use for completions when making requests to Azure OpenAI.\n * Completions are only available for gpt-3.5-turbo and text-davinci-003 deployments.\n * This is the name of the deployment you created in the Azure portal.\n * This will fallback to azureOpenAIApiDeploymentName if not provided.\n * e.g. \"my-openai-deployment\"\n * this will be used in the endpoint URL: https://{InstanceName}.openai.azure.com/openai/deployments/my-openai-deployment/\n */\n azureOpenAIApiCompletionsDeploymentName?: string;\n /**\n * Custom base url for Azure OpenAI API. This is useful in case you have a deployment in another region.\n * e.g. setting this value to \"https://westeurope.api.cognitive.microsoft.com/openai/deployments\"\n * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIBasePath?: string;\n /**\n * Custom endpoint for Azure OpenAI API. This is useful in case you have a deployment in another region.\n * e.g. setting this value to \"https://westeurope.api.cognitive.microsoft.com/\"\n * will be result in the endpoint URL: https://westeurope.api.cognitive.microsoft.com/openai/deployments/{DeploymentName}/\n */\n azureOpenAIEndpoint?: string;\n /**\n * A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),\n * which will be invoked on every request.\n */\n azureADTokenProvider?: () => Promise<string>;\n}\nexport interface AzureOpenAIChatInput extends OpenAIChatInput, AzureOpenAIInput {\n openAIApiKey?: string;\n openAIApiVersion?: string;\n openAIBasePath?: string;\n deploymentName?: string;\n}\ntype ChatOpenAIResponseFormatJSONSchema = Omit<ResponseFormatJSONSchema, \"json_schema\"> & {\n json_schema: Omit<ResponseFormatJSONSchema[\"json_schema\"], \"schema\"> & {\n /**\n * The schema for the response format, described as a JSON Schema object\n * or a Zod object.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any> | InteropZodObject;\n };\n};\n/**\n * The summary of a model's reasoning step.\n */\nexport type ChatOpenAIReasoningSummary = Omit<OpenAIClient.Responses.ResponseReasoningItem, \"summary\"> & {\n /**\n * The summary of the reasoning step. The index field will be populated if the response was\n * streamed. This allows LangChain to recompose the reasoning summary output correctly when the\n * AIMessage is used as an input for future generation requests.\n */\n summary: Array<OpenAIClient.Responses.ResponseReasoningItem.Summary & {\n index?: number;\n }>;\n};\nexport type ChatOpenAIResponseFormat = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatTextGrammar | ResponseFormatTextPython | ChatOpenAIResponseFormatJSONSchema;\nexport type ResponseFormatConfiguration = ResponseFormatText | ResponseFormatJSONObject | ResponseFormatJSONSchema;\n"],"mappings":";;;;;;;;;;;AAW8E,KAAlEU,iBAAAA,GAAoBT,QAAAA,CAAaU,SAAiC,GAAA,CAAA,MAAA,GAAXC,WAAW,CAAA,OAAA,CAAA,CAAA;AAClEC,KAAAA,oBAAAA,GAAoB,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,IAAA;AACPC,kBAAAA,eAAAA,CAAe;EAAA;EAAA,WAuBxBC,EAAAA,MAAAA;EAAM;;;AAiDc;EAExBC,SAAAA,CAAAA,EAAAA,MAAAA;EACKE;;;;AAAsD;EAS9CC,mBAAW,CAAA,EAAA,MAASL;EAM5BM;EAAe,IAAA,EAAA,MAAA;EAAA;EAYiC,gBAuB7BC,EAAKE,MAAAA;EAAsB;EAAzC,eAMGF,EAAKI,MAAAA;EAAwB;EAOhB,CAAA,EAYnBxB,MAAAA;EAA2C;EA5DN,SAAA,CAAA,EAnExCc,MAmEwC,CAAA,MAAA,EAAA,MAAA,CAAA;EAoEvCc;EA0DAE,IAAAA,CAAAA,EAAAA,MAAAA;EAAoB;EAAA,SAASX,EAAAA,OAAAA;EAAe;AAAkB;AAK9E;;EACsC,WAAQhB,CAAAA,EAAAA,OAAAA;EAAwB;;;;;EAOjB,SAAA,EAAA,MAAA;EAM1C8B;EAA0B,KAAA,EAnM3BxB,iBAmM2B;EAAA;;;;EAMpB;EAIN2B,WAAAA,CAAAA,EAvMMtB,MAuMNsB,CAAAA,MAAwB,EAAA,GAAA,CAAA;EAAA;;;;EAA4E,IAAGhC,CAAAA,EAAAA,MAAAA,EAAAA;EAAwB;EAAqC,aAAA,CAAA,EAAA,MAAA,EAAA;EACpKiC;;;EAAgD,OAAGnC,CAAAA,EAAAA,MAAAA;EAAwB;AAA2B;;;;;;;;;;;;;cA9KlGU;;KAEJG,wBAAAA,GAA2Bf,QAAAA,CAAagB;UACnCC,iBAAAA,SAA0BV;;;;YAI7BQ;;;;;kBAKWG,WAAAA,SAAoBL;;;;;;UAM5BM,eAAAA,SAAwBN;;;;;;;;;;;;mBAYpBb,QAAAA,CAAaoB,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;eAuBtBE,MAAMvB,QAAAA,CAAaoB,IAAAA,CAAKE;;;;;;UAM7BtB,QAAAA,CAAaoB,IAAAA,CAAKI;;;;;;;cAOdxB,QAAAA,CAAayB;;;;;;;;;;;;iBAYVzB,QAAAA,CAAa0B,SAAAA,CAAUC;;;;;;;;UAQzBC,gBAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAwDgBC;;UAEhBC,oBAAAA,SAA6BX,iBAAiBS;;;;;;KAM1DG,kCAAAA,GAAqCC,KAAK7B;eAC9B6B,KAAK7B;;;;;;YAMNW,sBAAsBN;;;;;;KAM1ByB,0BAAAA,GAA6BD,KAAKhC,QAAAA,CAAa0B,SAAAA,CAAUQ;;;;;;WAMxDX,MAAMvB,QAAAA,CAAa0B,SAAAA,CAAUQ,qBAAAA,CAAsBC;;;;KAIpDC,wBAAAA,GAA2BnC,qBAAqBC,2BAA2BG,4BAA4BD,2BAA2B2B;KAClIM,2BAAAA,GAA8BpC,qBAAqBC,2BAA2BC"}