langchain 0.0.197-rc.0 → 0.0.197-rc.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 (202) hide show
  1. package/dist/agents/executor.cjs +351 -1
  2. package/dist/agents/executor.d.ts +61 -3
  3. package/dist/agents/executor.js +350 -1
  4. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
  5. package/dist/base_language/count_tokens.cjs +1 -1
  6. package/dist/base_language/count_tokens.d.ts +1 -1
  7. package/dist/base_language/count_tokens.js +1 -1
  8. package/dist/base_language/index.cjs +1 -1
  9. package/dist/base_language/index.d.ts +1 -1
  10. package/dist/base_language/index.js +1 -1
  11. package/dist/cache/base.cjs +1 -1
  12. package/dist/cache/base.d.ts +1 -1
  13. package/dist/cache/base.js +1 -1
  14. package/dist/cache/index.cjs +1 -1
  15. package/dist/cache/index.d.ts +1 -1
  16. package/dist/cache/index.js +1 -1
  17. package/dist/callbacks/base.cjs +1 -1
  18. package/dist/callbacks/base.d.ts +1 -1
  19. package/dist/callbacks/base.js +1 -1
  20. package/dist/callbacks/handlers/console.cjs +1 -1
  21. package/dist/callbacks/handlers/console.d.ts +1 -1
  22. package/dist/callbacks/handlers/console.js +1 -1
  23. package/dist/callbacks/handlers/initialize.cjs +1 -1
  24. package/dist/callbacks/handlers/initialize.d.ts +1 -1
  25. package/dist/callbacks/handlers/initialize.js +1 -1
  26. package/dist/callbacks/handlers/log_stream.cjs +1 -1
  27. package/dist/callbacks/handlers/log_stream.d.ts +1 -1
  28. package/dist/callbacks/handlers/log_stream.js +1 -1
  29. package/dist/callbacks/handlers/run_collector.cjs +1 -1
  30. package/dist/callbacks/handlers/run_collector.d.ts +1 -1
  31. package/dist/callbacks/handlers/run_collector.js +1 -1
  32. package/dist/callbacks/handlers/tracer.cjs +1 -1
  33. package/dist/callbacks/handlers/tracer.d.ts +1 -1
  34. package/dist/callbacks/handlers/tracer.js +1 -1
  35. package/dist/callbacks/handlers/tracer_langchain.cjs +1 -1
  36. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -1
  37. package/dist/callbacks/handlers/tracer_langchain.js +1 -1
  38. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +1 -1
  39. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -1
  40. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -1
  41. package/dist/callbacks/manager.cjs +1 -1
  42. package/dist/callbacks/manager.d.ts +1 -1
  43. package/dist/callbacks/manager.js +1 -1
  44. package/dist/callbacks/promises.cjs +1 -1
  45. package/dist/callbacks/promises.d.ts +1 -1
  46. package/dist/callbacks/promises.js +1 -1
  47. package/dist/chains/base.cjs +16 -0
  48. package/dist/chains/base.d.ts +2 -0
  49. package/dist/chains/base.js +16 -0
  50. package/dist/chains/openai_functions/structured_output.cjs +1 -1
  51. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  52. package/dist/chains/openai_functions/structured_output.js +1 -1
  53. package/dist/chains/openai_moderation.cjs +2 -2
  54. package/dist/chains/openai_moderation.d.ts +1 -1
  55. package/dist/chains/openai_moderation.js +1 -1
  56. package/dist/chat_models/base.cjs +1 -1
  57. package/dist/chat_models/base.d.ts +1 -1
  58. package/dist/chat_models/base.js +1 -1
  59. package/dist/chat_models/fireworks.d.ts +2 -2
  60. package/dist/chat_models/iflytek_xinghuo/common.d.ts +1 -1
  61. package/dist/chat_models/minimax.d.ts +2 -2
  62. package/dist/chat_models/openai.cjs +4 -698
  63. package/dist/chat_models/openai.d.ts +4 -137
  64. package/dist/chat_models/openai.js +2 -695
  65. package/dist/document.cjs +1 -1
  66. package/dist/document.d.ts +1 -1
  67. package/dist/document.js +1 -1
  68. package/dist/document_loaders/fs/openai_whisper_audio.cjs +2 -2
  69. package/dist/document_loaders/fs/openai_whisper_audio.d.ts +1 -1
  70. package/dist/document_loaders/fs/openai_whisper_audio.js +1 -1
  71. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  72. package/dist/document_loaders/web/s3.d.ts +1 -1
  73. package/dist/embeddings/base.cjs +1 -1
  74. package/dist/embeddings/base.d.ts +1 -1
  75. package/dist/embeddings/base.js +1 -1
  76. package/dist/embeddings/cache_backed.cjs +1 -1
  77. package/dist/embeddings/cache_backed.js +1 -1
  78. package/dist/embeddings/openai.cjs +2 -240
  79. package/dist/embeddings/openai.d.ts +1 -82
  80. package/dist/embeddings/openai.js +1 -239
  81. package/dist/experimental/openai_assistant/index.cjs +3 -3
  82. package/dist/experimental/openai_assistant/index.d.ts +1 -1
  83. package/dist/experimental/openai_assistant/index.js +1 -1
  84. package/dist/experimental/openai_assistant/schema.d.ts +1 -1
  85. package/dist/experimental/openai_files/index.cjs +2 -2
  86. package/dist/experimental/openai_files/index.d.ts +1 -1
  87. package/dist/experimental/openai_files/index.js +1 -1
  88. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  89. package/dist/llms/base.cjs +1 -1
  90. package/dist/llms/base.d.ts +1 -1
  91. package/dist/llms/base.js +1 -1
  92. package/dist/llms/fireworks.d.ts +2 -2
  93. package/dist/llms/openai-chat.cjs +3 -445
  94. package/dist/llms/openai-chat.d.ts +4 -123
  95. package/dist/llms/openai-chat.js +2 -443
  96. package/dist/llms/openai.cjs +6 -530
  97. package/dist/llms/openai.d.ts +4 -123
  98. package/dist/llms/openai.js +2 -525
  99. package/dist/load/index.cjs +4 -2
  100. package/dist/load/index.d.ts +2 -2
  101. package/dist/load/index.js +4 -2
  102. package/dist/load/serializable.cjs +1 -1
  103. package/dist/load/serializable.d.ts +1 -1
  104. package/dist/load/serializable.js +1 -1
  105. package/dist/memory/base.cjs +2 -2
  106. package/dist/memory/base.d.ts +2 -2
  107. package/dist/memory/base.js +2 -2
  108. package/dist/output_parsers/list.cjs +1 -1
  109. package/dist/output_parsers/list.d.ts +1 -1
  110. package/dist/output_parsers/list.js +1 -1
  111. package/dist/output_parsers/openai_functions.cjs +1 -1
  112. package/dist/output_parsers/openai_functions.d.ts +1 -1
  113. package/dist/output_parsers/openai_functions.js +1 -1
  114. package/dist/output_parsers/structured.d.ts +1 -1
  115. package/dist/prompts/base.cjs +3 -3
  116. package/dist/prompts/base.d.ts +3 -3
  117. package/dist/prompts/base.js +3 -3
  118. package/dist/prompts/chat.cjs +2 -2
  119. package/dist/prompts/chat.d.ts +2 -2
  120. package/dist/prompts/chat.js +2 -2
  121. package/dist/prompts/few_shot.cjs +1 -1
  122. package/dist/prompts/few_shot.d.ts +1 -1
  123. package/dist/prompts/few_shot.js +1 -1
  124. package/dist/prompts/index.cjs +1 -1
  125. package/dist/prompts/index.d.ts +1 -1
  126. package/dist/prompts/index.js +1 -1
  127. package/dist/prompts/pipeline.cjs +1 -1
  128. package/dist/prompts/pipeline.d.ts +1 -1
  129. package/dist/prompts/pipeline.js +1 -1
  130. package/dist/prompts/prompt.cjs +1 -1
  131. package/dist/prompts/prompt.d.ts +1 -1
  132. package/dist/prompts/prompt.js +1 -1
  133. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +1 -1
  134. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -1
  135. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -1
  136. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +1 -1
  137. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -1
  138. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -1
  139. package/dist/prompts/selectors/conditional.cjs +1 -1
  140. package/dist/prompts/selectors/conditional.d.ts +1 -1
  141. package/dist/prompts/selectors/conditional.js +1 -1
  142. package/dist/prompts/serde.d.ts +1 -1
  143. package/dist/prompts/template.cjs +1 -1
  144. package/dist/prompts/template.d.ts +1 -1
  145. package/dist/prompts/template.js +1 -1
  146. package/dist/runnables/index.cjs +1 -1
  147. package/dist/runnables/index.d.ts +1 -1
  148. package/dist/runnables/index.js +1 -1
  149. package/dist/schema/document.cjs +1 -1
  150. package/dist/schema/document.d.ts +1 -1
  151. package/dist/schema/document.js +1 -1
  152. package/dist/schema/index.cjs +7 -7
  153. package/dist/schema/index.d.ts +11 -11
  154. package/dist/schema/index.js +7 -7
  155. package/dist/schema/output_parser.cjs +1 -1
  156. package/dist/schema/output_parser.d.ts +1 -1
  157. package/dist/schema/output_parser.js +1 -1
  158. package/dist/schema/retriever.cjs +1 -1
  159. package/dist/schema/retriever.d.ts +1 -1
  160. package/dist/schema/retriever.js +1 -1
  161. package/dist/schema/runnable/base.cjs +1 -1
  162. package/dist/schema/runnable/base.d.ts +1 -1
  163. package/dist/schema/runnable/base.js +1 -1
  164. package/dist/schema/runnable/branch.cjs +1 -1
  165. package/dist/schema/runnable/branch.d.ts +1 -1
  166. package/dist/schema/runnable/branch.js +1 -1
  167. package/dist/schema/runnable/config.d.ts +1 -1
  168. package/dist/schema/runnable/index.cjs +1 -1
  169. package/dist/schema/runnable/index.d.ts +1 -1
  170. package/dist/schema/runnable/index.js +1 -1
  171. package/dist/schema/runnable/passthrough.cjs +1 -1
  172. package/dist/schema/runnable/passthrough.d.ts +1 -1
  173. package/dist/schema/runnable/passthrough.js +1 -1
  174. package/dist/schema/runnable/router.cjs +1 -1
  175. package/dist/schema/runnable/router.d.ts +1 -1
  176. package/dist/schema/runnable/router.js +1 -1
  177. package/dist/schema/storage.cjs +1 -1
  178. package/dist/schema/storage.d.ts +1 -1
  179. package/dist/schema/storage.js +1 -1
  180. package/dist/tools/base.cjs +4 -108
  181. package/dist/tools/base.d.ts +1 -72
  182. package/dist/tools/base.js +1 -105
  183. package/dist/tools/bingserpapi.d.ts +1 -1
  184. package/dist/tools/convert_to_openai.cjs +4 -38
  185. package/dist/tools/convert_to_openai.d.ts +1 -11
  186. package/dist/tools/convert_to_openai.js +1 -35
  187. package/dist/tools/searchapi.d.ts +1 -1
  188. package/dist/tools/serpapi.d.ts +1 -1
  189. package/dist/tools/serper.d.ts +1 -1
  190. package/dist/types/openai-types.d.ts +1 -133
  191. package/dist/util/async_caller.cjs +1 -1
  192. package/dist/util/async_caller.d.ts +1 -1
  193. package/dist/util/async_caller.js +1 -1
  194. package/dist/util/openai.cjs +2 -18
  195. package/dist/util/openai.d.ts +1 -1
  196. package/dist/util/openai.js +1 -17
  197. package/dist/util/openapi.d.ts +2 -2
  198. package/dist/util/prompt-layer.d.ts +1 -1
  199. package/package.json +6 -5
  200. package/dist/util/openai-format-fndef.cjs +0 -81
  201. package/dist/util/openai-format-fndef.d.ts +0 -44
  202. package/dist/util/openai-format-fndef.js +0 -77
@@ -1,530 +1,7 @@
1
- import { OpenAI as OpenAIClient } from "openai";
2
- import { calculateMaxTokens } from "../base_language/count_tokens.js";
3
- import { GenerationChunk } from "../schema/index.js";
4
- import { getEndpoint } from "../util/azure.js";
5
- import { chunkArray } from "../util/chunk.js";
1
+ import { OpenAI } from "@langchain/openai";
6
2
  import { getEnvironmentVariable } from "../util/env.js";
7
3
  import { promptLayerTrackRequest } from "../util/prompt-layer.js";
8
- import { BaseLLM } from "./base.js";
9
- import { OpenAIChat } from "./openai-chat.js";
10
- import { wrapOpenAIClientError } from "../util/openai.js";
11
- /**
12
- * Wrapper around OpenAI large language models.
13
- *
14
- * To use you should have the `openai` package installed, with the
15
- * `OPENAI_API_KEY` environment variable set.
16
- *
17
- * To use with Azure you should have the `openai` package installed, with the
18
- * `AZURE_OPENAI_API_KEY`,
19
- * `AZURE_OPENAI_API_INSTANCE_NAME`,
20
- * `AZURE_OPENAI_API_DEPLOYMENT_NAME`
21
- * and `AZURE_OPENAI_API_VERSION` environment variable set.
22
- *
23
- * @remarks
24
- * Any parameters that are valid to be passed to {@link
25
- * https://platform.openai.com/docs/api-reference/completions/create |
26
- * `openai.createCompletion`} can be passed through {@link modelKwargs}, even
27
- * if not explicitly available on this class.
28
- * @example
29
- * ```typescript
30
- * const model = new OpenAI({
31
- * modelName: "gpt-4",
32
- * temperature: 0.7,
33
- * maxTokens: 1000,
34
- * maxRetries: 5,
35
- * });
36
- *
37
- * const res = await model.call(
38
- * "Question: What would be a good company name for a company that makes colorful socks?\nAnswer:"
39
- * );
40
- * console.log({ res });
41
- * ```
42
- */
43
- export class OpenAI extends BaseLLM {
44
- static lc_name() {
45
- return "OpenAI";
46
- }
47
- get callKeys() {
48
- return [...super.callKeys, "options"];
49
- }
50
- get lc_secrets() {
51
- return {
52
- openAIApiKey: "OPENAI_API_KEY",
53
- azureOpenAIApiKey: "AZURE_OPENAI_API_KEY",
54
- organization: "OPENAI_ORGANIZATION",
55
- };
56
- }
57
- get lc_aliases() {
58
- return {
59
- modelName: "model",
60
- openAIApiKey: "openai_api_key",
61
- azureOpenAIApiVersion: "azure_openai_api_version",
62
- azureOpenAIApiKey: "azure_openai_api_key",
63
- azureOpenAIApiInstanceName: "azure_openai_api_instance_name",
64
- azureOpenAIApiDeploymentName: "azure_openai_api_deployment_name",
65
- };
66
- }
67
- constructor(fields,
68
- /** @deprecated */
69
- configuration) {
70
- if ((fields?.modelName?.startsWith("gpt-3.5-turbo") ||
71
- fields?.modelName?.startsWith("gpt-4")) &&
72
- !fields?.modelName?.includes("-instruct")) {
73
- // eslint-disable-next-line no-constructor-return
74
- return new OpenAIChat(fields, configuration);
75
- }
76
- super(fields ?? {});
77
- Object.defineProperty(this, "lc_serializable", {
78
- enumerable: true,
79
- configurable: true,
80
- writable: true,
81
- value: true
82
- });
83
- Object.defineProperty(this, "temperature", {
84
- enumerable: true,
85
- configurable: true,
86
- writable: true,
87
- value: 0.7
88
- });
89
- Object.defineProperty(this, "maxTokens", {
90
- enumerable: true,
91
- configurable: true,
92
- writable: true,
93
- value: 256
94
- });
95
- Object.defineProperty(this, "topP", {
96
- enumerable: true,
97
- configurable: true,
98
- writable: true,
99
- value: 1
100
- });
101
- Object.defineProperty(this, "frequencyPenalty", {
102
- enumerable: true,
103
- configurable: true,
104
- writable: true,
105
- value: 0
106
- });
107
- Object.defineProperty(this, "presencePenalty", {
108
- enumerable: true,
109
- configurable: true,
110
- writable: true,
111
- value: 0
112
- });
113
- Object.defineProperty(this, "n", {
114
- enumerable: true,
115
- configurable: true,
116
- writable: true,
117
- value: 1
118
- });
119
- Object.defineProperty(this, "bestOf", {
120
- enumerable: true,
121
- configurable: true,
122
- writable: true,
123
- value: void 0
124
- });
125
- Object.defineProperty(this, "logitBias", {
126
- enumerable: true,
127
- configurable: true,
128
- writable: true,
129
- value: void 0
130
- });
131
- Object.defineProperty(this, "modelName", {
132
- enumerable: true,
133
- configurable: true,
134
- writable: true,
135
- value: "gpt-3.5-turbo-instruct"
136
- });
137
- Object.defineProperty(this, "modelKwargs", {
138
- enumerable: true,
139
- configurable: true,
140
- writable: true,
141
- value: void 0
142
- });
143
- Object.defineProperty(this, "batchSize", {
144
- enumerable: true,
145
- configurable: true,
146
- writable: true,
147
- value: 20
148
- });
149
- Object.defineProperty(this, "timeout", {
150
- enumerable: true,
151
- configurable: true,
152
- writable: true,
153
- value: void 0
154
- });
155
- Object.defineProperty(this, "stop", {
156
- enumerable: true,
157
- configurable: true,
158
- writable: true,
159
- value: void 0
160
- });
161
- Object.defineProperty(this, "user", {
162
- enumerable: true,
163
- configurable: true,
164
- writable: true,
165
- value: void 0
166
- });
167
- Object.defineProperty(this, "streaming", {
168
- enumerable: true,
169
- configurable: true,
170
- writable: true,
171
- value: false
172
- });
173
- Object.defineProperty(this, "openAIApiKey", {
174
- enumerable: true,
175
- configurable: true,
176
- writable: true,
177
- value: void 0
178
- });
179
- Object.defineProperty(this, "azureOpenAIApiVersion", {
180
- enumerable: true,
181
- configurable: true,
182
- writable: true,
183
- value: void 0
184
- });
185
- Object.defineProperty(this, "azureOpenAIApiKey", {
186
- enumerable: true,
187
- configurable: true,
188
- writable: true,
189
- value: void 0
190
- });
191
- Object.defineProperty(this, "azureOpenAIApiInstanceName", {
192
- enumerable: true,
193
- configurable: true,
194
- writable: true,
195
- value: void 0
196
- });
197
- Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
198
- enumerable: true,
199
- configurable: true,
200
- writable: true,
201
- value: void 0
202
- });
203
- Object.defineProperty(this, "azureOpenAIBasePath", {
204
- enumerable: true,
205
- configurable: true,
206
- writable: true,
207
- value: void 0
208
- });
209
- Object.defineProperty(this, "organization", {
210
- enumerable: true,
211
- configurable: true,
212
- writable: true,
213
- value: void 0
214
- });
215
- Object.defineProperty(this, "client", {
216
- enumerable: true,
217
- configurable: true,
218
- writable: true,
219
- value: void 0
220
- });
221
- Object.defineProperty(this, "clientConfig", {
222
- enumerable: true,
223
- configurable: true,
224
- writable: true,
225
- value: void 0
226
- });
227
- this.openAIApiKey =
228
- fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
229
- this.azureOpenAIApiKey =
230
- fields?.azureOpenAIApiKey ??
231
- getEnvironmentVariable("AZURE_OPENAI_API_KEY");
232
- if (!this.azureOpenAIApiKey && !this.openAIApiKey) {
233
- throw new Error("OpenAI or Azure OpenAI API key not found");
234
- }
235
- this.azureOpenAIApiInstanceName =
236
- fields?.azureOpenAIApiInstanceName ??
237
- getEnvironmentVariable("AZURE_OPENAI_API_INSTANCE_NAME");
238
- this.azureOpenAIApiDeploymentName =
239
- (fields?.azureOpenAIApiCompletionsDeploymentName ||
240
- fields?.azureOpenAIApiDeploymentName) ??
241
- (getEnvironmentVariable("AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME") ||
242
- getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME"));
243
- this.azureOpenAIApiVersion =
244
- fields?.azureOpenAIApiVersion ??
245
- getEnvironmentVariable("AZURE_OPENAI_API_VERSION");
246
- this.azureOpenAIBasePath =
247
- fields?.azureOpenAIBasePath ??
248
- getEnvironmentVariable("AZURE_OPENAI_BASE_PATH");
249
- this.organization =
250
- fields?.configuration?.organization ??
251
- getEnvironmentVariable("OPENAI_ORGANIZATION");
252
- this.modelName = fields?.modelName ?? this.modelName;
253
- this.modelKwargs = fields?.modelKwargs ?? {};
254
- this.batchSize = fields?.batchSize ?? this.batchSize;
255
- this.timeout = fields?.timeout;
256
- this.temperature = fields?.temperature ?? this.temperature;
257
- this.maxTokens = fields?.maxTokens ?? this.maxTokens;
258
- this.topP = fields?.topP ?? this.topP;
259
- this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty;
260
- this.presencePenalty = fields?.presencePenalty ?? this.presencePenalty;
261
- this.n = fields?.n ?? this.n;
262
- this.bestOf = fields?.bestOf ?? this.bestOf;
263
- this.logitBias = fields?.logitBias;
264
- this.stop = fields?.stop;
265
- this.user = fields?.user;
266
- this.streaming = fields?.streaming ?? false;
267
- if (this.streaming && this.bestOf && this.bestOf > 1) {
268
- throw new Error("Cannot stream results when bestOf > 1");
269
- }
270
- if (this.azureOpenAIApiKey) {
271
- if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
272
- throw new Error("Azure OpenAI API instance name not found");
273
- }
274
- if (!this.azureOpenAIApiDeploymentName) {
275
- throw new Error("Azure OpenAI API deployment name not found");
276
- }
277
- if (!this.azureOpenAIApiVersion) {
278
- throw new Error("Azure OpenAI API version not found");
279
- }
280
- this.openAIApiKey = this.openAIApiKey ?? "";
281
- }
282
- this.clientConfig = {
283
- apiKey: this.openAIApiKey,
284
- organization: this.organization,
285
- baseURL: configuration?.basePath ?? fields?.configuration?.basePath,
286
- dangerouslyAllowBrowser: true,
287
- defaultHeaders: configuration?.baseOptions?.headers ??
288
- fields?.configuration?.baseOptions?.headers,
289
- defaultQuery: configuration?.baseOptions?.params ??
290
- fields?.configuration?.baseOptions?.params,
291
- ...configuration,
292
- ...fields?.configuration,
293
- };
294
- }
295
- /**
296
- * Get the parameters used to invoke the model
297
- */
298
- invocationParams(options) {
299
- return {
300
- model: this.modelName,
301
- temperature: this.temperature,
302
- max_tokens: this.maxTokens,
303
- top_p: this.topP,
304
- frequency_penalty: this.frequencyPenalty,
305
- presence_penalty: this.presencePenalty,
306
- n: this.n,
307
- best_of: this.bestOf,
308
- logit_bias: this.logitBias,
309
- stop: options?.stop ?? this.stop,
310
- user: this.user,
311
- stream: this.streaming,
312
- ...this.modelKwargs,
313
- };
314
- }
315
- /** @ignore */
316
- _identifyingParams() {
317
- return {
318
- model_name: this.modelName,
319
- ...this.invocationParams(),
320
- ...this.clientConfig,
321
- };
322
- }
323
- /**
324
- * Get the identifying parameters for the model
325
- */
326
- identifyingParams() {
327
- return this._identifyingParams();
328
- }
329
- /**
330
- * Call out to OpenAI's endpoint with k unique prompts
331
- *
332
- * @param [prompts] - The prompts to pass into the model.
333
- * @param [options] - Optional list of stop words to use when generating.
334
- * @param [runManager] - Optional callback manager to use when generating.
335
- *
336
- * @returns The full LLM output.
337
- *
338
- * @example
339
- * ```ts
340
- * import { OpenAI } from "langchain/llms/openai";
341
- * const openai = new OpenAI();
342
- * const response = await openai.generate(["Tell me a joke."]);
343
- * ```
344
- */
345
- async _generate(prompts, options, runManager) {
346
- const subPrompts = chunkArray(prompts, this.batchSize);
347
- const choices = [];
348
- const tokenUsage = {};
349
- const params = this.invocationParams(options);
350
- if (params.max_tokens === -1) {
351
- if (prompts.length !== 1) {
352
- throw new Error("max_tokens set to -1 not supported for multiple inputs");
353
- }
354
- params.max_tokens = await calculateMaxTokens({
355
- prompt: prompts[0],
356
- // Cast here to allow for other models that may not fit the union
357
- modelName: this.modelName,
358
- });
359
- }
360
- for (let i = 0; i < subPrompts.length; i += 1) {
361
- const data = params.stream
362
- ? await (async () => {
363
- const choices = [];
364
- let response;
365
- const stream = await this.completionWithRetry({
366
- ...params,
367
- stream: true,
368
- prompt: subPrompts[i],
369
- }, options);
370
- for await (const message of stream) {
371
- // on the first message set the response properties
372
- if (!response) {
373
- response = {
374
- id: message.id,
375
- object: message.object,
376
- created: message.created,
377
- model: message.model,
378
- };
379
- }
380
- // on all messages, update choice
381
- for (const part of message.choices) {
382
- if (!choices[part.index]) {
383
- choices[part.index] = part;
384
- }
385
- else {
386
- const choice = choices[part.index];
387
- choice.text += part.text;
388
- choice.finish_reason = part.finish_reason;
389
- choice.logprobs = part.logprobs;
390
- }
391
- void runManager?.handleLLMNewToken(part.text, {
392
- prompt: Math.floor(part.index / this.n),
393
- completion: part.index % this.n,
394
- });
395
- }
396
- }
397
- if (options.signal?.aborted) {
398
- throw new Error("AbortError");
399
- }
400
- return { ...response, choices };
401
- })()
402
- : await this.completionWithRetry({
403
- ...params,
404
- stream: false,
405
- prompt: subPrompts[i],
406
- }, {
407
- signal: options.signal,
408
- ...options.options,
409
- });
410
- choices.push(...data.choices);
411
- const { completion_tokens: completionTokens, prompt_tokens: promptTokens, total_tokens: totalTokens, } = data.usage
412
- ? data.usage
413
- : {
414
- completion_tokens: undefined,
415
- prompt_tokens: undefined,
416
- total_tokens: undefined,
417
- };
418
- if (completionTokens) {
419
- tokenUsage.completionTokens =
420
- (tokenUsage.completionTokens ?? 0) + completionTokens;
421
- }
422
- if (promptTokens) {
423
- tokenUsage.promptTokens = (tokenUsage.promptTokens ?? 0) + promptTokens;
424
- }
425
- if (totalTokens) {
426
- tokenUsage.totalTokens = (tokenUsage.totalTokens ?? 0) + totalTokens;
427
- }
428
- }
429
- const generations = chunkArray(choices, this.n).map((promptChoices) => promptChoices.map((choice) => ({
430
- text: choice.text ?? "",
431
- generationInfo: {
432
- finishReason: choice.finish_reason,
433
- logprobs: choice.logprobs,
434
- },
435
- })));
436
- return {
437
- generations,
438
- llmOutput: { tokenUsage },
439
- };
440
- }
441
- // TODO(jacoblee): Refactor with _generate(..., {stream: true}) implementation?
442
- async *_streamResponseChunks(input, options, runManager) {
443
- const params = {
444
- ...this.invocationParams(options),
445
- prompt: input,
446
- stream: true,
447
- };
448
- const stream = await this.completionWithRetry(params, options);
449
- for await (const data of stream) {
450
- const choice = data?.choices[0];
451
- if (!choice) {
452
- continue;
453
- }
454
- const chunk = new GenerationChunk({
455
- text: choice.text,
456
- generationInfo: {
457
- finishReason: choice.finish_reason,
458
- },
459
- });
460
- yield chunk;
461
- // eslint-disable-next-line no-void
462
- void runManager?.handleLLMNewToken(chunk.text ?? "");
463
- }
464
- if (options.signal?.aborted) {
465
- throw new Error("AbortError");
466
- }
467
- }
468
- async completionWithRetry(request, options) {
469
- const requestOptions = this._getClientOptions(options);
470
- return this.caller.call(async () => {
471
- try {
472
- const res = await this.client.completions.create(request, requestOptions);
473
- return res;
474
- }
475
- catch (e) {
476
- const error = wrapOpenAIClientError(e);
477
- throw error;
478
- }
479
- });
480
- }
481
- /**
482
- * Calls the OpenAI API with retry logic in case of failures.
483
- * @param request The request to send to the OpenAI API.
484
- * @param options Optional configuration for the API call.
485
- * @returns The response from the OpenAI API.
486
- */
487
- _getClientOptions(options) {
488
- if (!this.client) {
489
- const openAIEndpointConfig = {
490
- azureOpenAIApiDeploymentName: this.azureOpenAIApiDeploymentName,
491
- azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
492
- azureOpenAIApiKey: this.azureOpenAIApiKey,
493
- azureOpenAIBasePath: this.azureOpenAIBasePath,
494
- baseURL: this.clientConfig.baseURL,
495
- };
496
- const endpoint = getEndpoint(openAIEndpointConfig);
497
- const params = {
498
- ...this.clientConfig,
499
- baseURL: endpoint,
500
- timeout: this.timeout,
501
- maxRetries: 0,
502
- };
503
- if (!params.baseURL) {
504
- delete params.baseURL;
505
- }
506
- this.client = new OpenAIClient(params);
507
- }
508
- const requestOptions = {
509
- ...this.clientConfig,
510
- ...options,
511
- };
512
- if (this.azureOpenAIApiKey) {
513
- requestOptions.headers = {
514
- "api-key": this.azureOpenAIApiKey,
515
- ...requestOptions.headers,
516
- };
517
- requestOptions.query = {
518
- "api-version": this.azureOpenAIApiVersion,
519
- ...requestOptions.query,
520
- };
521
- }
522
- return requestOptions;
523
- }
524
- _llmType() {
525
- return "openai";
526
- }
527
- }
4
+ export { OpenAI };
528
5
  /**
529
6
  * PromptLayer wrapper to OpenAI
530
7
  * @augments OpenAI
@@ -24,10 +24,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.load = void 0;
27
- const load_1 = require("langchain-core/load");
27
+ const load_1 = require("@langchain/core/load");
28
28
  const import_constants_js_1 = require("./import_constants.cjs");
29
29
  const importMap = __importStar(require("./import_map.cjs"));
30
- async function load(text, secretsMap = {}, optionalImportsMap = {}) {
30
+ async function load(text,
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ secretsMap = {}, optionalImportsMap = {}) {
31
33
  return (0, load_1.load)(text, {
32
34
  secretsMap,
33
35
  optionalImportsMap,
@@ -1,2 +1,2 @@
1
- import { OptionalImportMap, SecretMap } from "./import_type.js";
2
- export declare function load<T>(text: string, secretsMap?: SecretMap, optionalImportsMap?: OptionalImportMap): Promise<T>;
1
+ import { OptionalImportMap } from "./import_type.js";
2
+ export declare function load<T>(text: string, secretsMap?: Record<string, any>, optionalImportsMap?: OptionalImportMap): Promise<T>;
@@ -1,7 +1,9 @@
1
- import { load as coreLoad } from "langchain-core/load";
1
+ import { load as coreLoad } from "@langchain/core/load";
2
2
  import { optionalImportEntrypoints } from "./import_constants.js";
3
3
  import * as importMap from "./import_map.js";
4
- export async function load(text, secretsMap = {}, optionalImportsMap = {}) {
4
+ export async function load(text,
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ secretsMap = {}, optionalImportsMap = {}) {
5
7
  return coreLoad(text, {
6
8
  secretsMap,
7
9
  optionalImportsMap,
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("langchain-core/load/serializable"), exports);
17
+ __exportStar(require("@langchain/core/load/serializable"), exports);
@@ -1 +1 @@
1
- export * from "langchain-core/load/serializable";
1
+ export * from "@langchain/core/load/serializable";
@@ -1 +1 @@
1
- export * from "langchain-core/load/serializable";
1
+ export * from "@langchain/core/load/serializable";
@@ -15,6 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.getBufferString = void 0;
18
- __exportStar(require("langchain-core/memory"), exports);
19
- var messages_1 = require("langchain-core/messages");
18
+ __exportStar(require("@langchain/core/memory"), exports);
19
+ var messages_1 = require("@langchain/core/messages");
20
20
  Object.defineProperty(exports, "getBufferString", { enumerable: true, get: function () { return messages_1.getBufferString; } });
@@ -1,2 +1,2 @@
1
- export * from "langchain-core/memory";
2
- export { getBufferString } from "langchain-core/messages";
1
+ export * from "@langchain/core/memory";
2
+ export { getBufferString } from "@langchain/core/messages";
@@ -1,2 +1,2 @@
1
- export * from "langchain-core/memory";
2
- export { getBufferString } from "langchain-core/messages";
1
+ export * from "@langchain/core/memory";
2
+ export { getBufferString } from "@langchain/core/messages";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CustomListOutputParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
4
- var output_parsers_1 = require("langchain-core/output_parsers");
4
+ var output_parsers_1 = require("@langchain/core/output_parsers");
5
5
  Object.defineProperty(exports, "ListOutputParser", { enumerable: true, get: function () { return output_parsers_1.ListOutputParser; } });
6
6
  Object.defineProperty(exports, "CommaSeparatedListOutputParser", { enumerable: true, get: function () { return output_parsers_1.CommaSeparatedListOutputParser; } });
7
7
  Object.defineProperty(exports, "CustomListOutputParser", { enumerable: true, get: function () { return output_parsers_1.CustomListOutputParser; } });
@@ -1 +1 @@
1
- export { ListOutputParser, CommaSeparatedListOutputParser, CustomListOutputParser, } from "langchain-core/output_parsers";
1
+ export { ListOutputParser, CommaSeparatedListOutputParser, CustomListOutputParser, } from "@langchain/core/output_parsers";
@@ -1 +1 @@
1
- export { ListOutputParser, CommaSeparatedListOutputParser, CustomListOutputParser, } from "langchain-core/output_parsers";
1
+ export { ListOutputParser, CommaSeparatedListOutputParser, CustomListOutputParser, } from "@langchain/core/output_parsers";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = void 0;
4
- const json_patch_1 = require("langchain-core/utils/json_patch");
4
+ const json_patch_1 = require("@langchain/core/utils/json_patch");
5
5
  const output_parser_js_1 = require("../schema/output_parser.cjs");
6
6
  const json_js_1 = require("./json.cjs");
7
7
  /**
@@ -1,5 +1,5 @@
1
1
  import { JsonSchema7ObjectType } from "zod-to-json-schema/src/parsers/object.js";
2
- import { type Operation as JSONPatchOperation } from "langchain-core/utils/json_patch";
2
+ import { type Operation as JSONPatchOperation } from "@langchain/core/utils/json_patch";
3
3
  import { ChatGeneration, Generation } from "../schema/index.js";
4
4
  import { Optional } from "../types/type-utils.js";
5
5
  import { BaseCumulativeTransformOutputParser, type BaseCumulativeTransformOutputParserInput, BaseLLMOutputParser } from "../schema/output_parser.js";
@@ -1,4 +1,4 @@
1
- import { compare, } from "langchain-core/utils/json_patch";
1
+ import { compare, } from "@langchain/core/utils/json_patch";
2
2
  import { BaseCumulativeTransformOutputParser, BaseLLMOutputParser, } from "../schema/output_parser.js";
3
3
  import { parsePartialJson } from "./json.js";
4
4
  /**
@@ -10,7 +10,7 @@ export declare class StructuredOutputParser<T extends z.ZodTypeAny> extends Base
10
10
  schema: T;
11
11
  static lc_name(): string;
12
12
  lc_namespace: string[];
13
- toJSON(): import("langchain-core/load/serializable").SerializedNotImplemented;
13
+ toJSON(): import("@langchain/core/load/serializable").SerializedNotImplemented;
14
14
  constructor(schema: T);
15
15
  /**
16
16
  * Creates a new StructuredOutputParser from a Zod schema.
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseExampleSelector = exports.StringPromptValue = exports.BasePromptTemplate = exports.BaseStringPromptTemplate = void 0;
4
- var prompts_1 = require("langchain-core/prompts");
4
+ var prompts_1 = require("@langchain/core/prompts");
5
5
  Object.defineProperty(exports, "BaseStringPromptTemplate", { enumerable: true, get: function () { return prompts_1.BaseStringPromptTemplate; } });
6
6
  Object.defineProperty(exports, "BasePromptTemplate", { enumerable: true, get: function () { return prompts_1.BasePromptTemplate; } });
7
- var prompt_values_1 = require("langchain-core/prompt_values");
7
+ var prompt_values_1 = require("@langchain/core/prompt_values");
8
8
  Object.defineProperty(exports, "StringPromptValue", { enumerable: true, get: function () { return prompt_values_1.StringPromptValue; } });
9
- var example_selectors_1 = require("langchain-core/example_selectors");
9
+ var example_selectors_1 = require("@langchain/core/example_selectors");
10
10
  Object.defineProperty(exports, "BaseExampleSelector", { enumerable: true, get: function () { return example_selectors_1.BaseExampleSelector; } });