langchain 0.0.196 → 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 (225) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agents/executor.cjs +351 -1
  3. package/dist/agents/executor.d.ts +61 -3
  4. package/dist/agents/executor.js +350 -1
  5. package/dist/agents/openai/index.cjs +6 -2
  6. package/dist/agents/openai/index.js +6 -2
  7. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
  8. package/dist/base_language/count_tokens.cjs +4 -4
  9. package/dist/base_language/count_tokens.d.ts +1 -1
  10. package/dist/base_language/count_tokens.js +1 -1
  11. package/dist/base_language/index.cjs +3 -3
  12. package/dist/base_language/index.d.ts +1 -1
  13. package/dist/base_language/index.js +1 -1
  14. package/dist/cache/base.cjs +1 -1
  15. package/dist/cache/base.d.ts +1 -1
  16. package/dist/cache/base.js +1 -1
  17. package/dist/cache/index.cjs +2 -2
  18. package/dist/cache/index.d.ts +1 -1
  19. package/dist/cache/index.js +1 -1
  20. package/dist/callbacks/base.cjs +1 -1
  21. package/dist/callbacks/base.d.ts +1 -1
  22. package/dist/callbacks/base.js +1 -1
  23. package/dist/callbacks/handlers/console.cjs +1 -1
  24. package/dist/callbacks/handlers/console.d.ts +1 -1
  25. package/dist/callbacks/handlers/console.js +1 -1
  26. package/dist/callbacks/handlers/initialize.cjs +1 -1
  27. package/dist/callbacks/handlers/initialize.d.ts +1 -1
  28. package/dist/callbacks/handlers/initialize.js +1 -1
  29. package/dist/callbacks/handlers/log_stream.cjs +1 -1
  30. package/dist/callbacks/handlers/log_stream.d.ts +1 -1
  31. package/dist/callbacks/handlers/log_stream.js +1 -1
  32. package/dist/callbacks/handlers/run_collector.cjs +1 -1
  33. package/dist/callbacks/handlers/run_collector.d.ts +1 -1
  34. package/dist/callbacks/handlers/run_collector.js +1 -1
  35. package/dist/callbacks/handlers/tracer.cjs +1 -1
  36. package/dist/callbacks/handlers/tracer.d.ts +1 -1
  37. package/dist/callbacks/handlers/tracer.js +1 -1
  38. package/dist/callbacks/handlers/tracer_langchain.cjs +1 -1
  39. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -1
  40. package/dist/callbacks/handlers/tracer_langchain.js +1 -1
  41. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +1 -1
  42. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -1
  43. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -1
  44. package/dist/callbacks/manager.cjs +1 -1
  45. package/dist/callbacks/manager.d.ts +1 -1
  46. package/dist/callbacks/manager.js +1 -1
  47. package/dist/callbacks/promises.cjs +1 -1
  48. package/dist/callbacks/promises.d.ts +1 -1
  49. package/dist/callbacks/promises.js +1 -1
  50. package/dist/chains/base.cjs +16 -0
  51. package/dist/chains/base.d.ts +2 -0
  52. package/dist/chains/base.js +16 -0
  53. package/dist/chains/openai_functions/structured_output.cjs +1 -1
  54. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  55. package/dist/chains/openai_functions/structured_output.js +1 -1
  56. package/dist/chains/openai_moderation.cjs +2 -2
  57. package/dist/chains/openai_moderation.d.ts +1 -1
  58. package/dist/chains/openai_moderation.js +1 -1
  59. package/dist/chat_models/anthropic.cjs +15 -348
  60. package/dist/chat_models/anthropic.d.ts +1 -156
  61. package/dist/chat_models/anthropic.js +1 -346
  62. package/dist/chat_models/base.cjs +1 -1
  63. package/dist/chat_models/base.d.ts +1 -1
  64. package/dist/chat_models/base.js +1 -1
  65. package/dist/chat_models/bedrock/web.cjs +21 -1
  66. package/dist/chat_models/bedrock/web.d.ts +1 -1
  67. package/dist/chat_models/bedrock/web.js +21 -1
  68. package/dist/chat_models/fireworks.d.ts +2 -2
  69. package/dist/chat_models/iflytek_xinghuo/common.d.ts +1 -1
  70. package/dist/chat_models/minimax.d.ts +2 -2
  71. package/dist/chat_models/openai.cjs +4 -698
  72. package/dist/chat_models/openai.d.ts +4 -137
  73. package/dist/chat_models/openai.js +2 -695
  74. package/dist/document.cjs +2 -2
  75. package/dist/document.d.ts +1 -1
  76. package/dist/document.js +1 -1
  77. package/dist/document_loaders/fs/openai_whisper_audio.cjs +2 -2
  78. package/dist/document_loaders/fs/openai_whisper_audio.d.ts +1 -1
  79. package/dist/document_loaders/fs/openai_whisper_audio.js +1 -1
  80. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  81. package/dist/document_loaders/web/github.cjs +105 -0
  82. package/dist/document_loaders/web/github.d.ts +26 -0
  83. package/dist/document_loaders/web/github.js +105 -0
  84. package/dist/document_loaders/web/s3.d.ts +1 -1
  85. package/dist/embeddings/base.cjs +1 -1
  86. package/dist/embeddings/base.d.ts +1 -1
  87. package/dist/embeddings/base.js +1 -1
  88. package/dist/embeddings/cache_backed.cjs +1 -1
  89. package/dist/embeddings/cache_backed.js +1 -1
  90. package/dist/embeddings/openai.cjs +2 -240
  91. package/dist/embeddings/openai.d.ts +1 -82
  92. package/dist/embeddings/openai.js +1 -239
  93. package/dist/experimental/openai_assistant/index.cjs +3 -3
  94. package/dist/experimental/openai_assistant/index.d.ts +1 -1
  95. package/dist/experimental/openai_assistant/index.js +1 -1
  96. package/dist/experimental/openai_assistant/schema.d.ts +1 -1
  97. package/dist/experimental/openai_files/index.cjs +2 -2
  98. package/dist/experimental/openai_files/index.d.ts +1 -1
  99. package/dist/experimental/openai_files/index.js +1 -1
  100. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  101. package/dist/llms/base.cjs +1 -1
  102. package/dist/llms/base.d.ts +1 -1
  103. package/dist/llms/base.js +1 -1
  104. package/dist/llms/bedrock/web.cjs +21 -1
  105. package/dist/llms/bedrock/web.d.ts +1 -1
  106. package/dist/llms/bedrock/web.js +21 -1
  107. package/dist/llms/fireworks.d.ts +2 -2
  108. package/dist/llms/openai-chat.cjs +3 -445
  109. package/dist/llms/openai-chat.d.ts +4 -123
  110. package/dist/llms/openai-chat.js +2 -443
  111. package/dist/llms/openai.cjs +6 -530
  112. package/dist/llms/openai.d.ts +4 -123
  113. package/dist/llms/openai.js +2 -525
  114. package/dist/load/index.cjs +4 -2
  115. package/dist/load/index.d.ts +2 -2
  116. package/dist/load/index.js +4 -2
  117. package/dist/load/serializable.cjs +1 -1
  118. package/dist/load/serializable.d.ts +1 -1
  119. package/dist/load/serializable.js +1 -1
  120. package/dist/memory/base.cjs +2 -2
  121. package/dist/memory/base.d.ts +2 -2
  122. package/dist/memory/base.js +2 -2
  123. package/dist/output_parsers/list.cjs +4 -122
  124. package/dist/output_parsers/list.d.ts +1 -57
  125. package/dist/output_parsers/list.js +1 -119
  126. package/dist/output_parsers/openai_functions.cjs +1 -1
  127. package/dist/output_parsers/openai_functions.d.ts +1 -1
  128. package/dist/output_parsers/openai_functions.js +1 -1
  129. package/dist/output_parsers/structured.d.ts +1 -1
  130. package/dist/prompts/base.cjs +8 -8
  131. package/dist/prompts/base.d.ts +3 -3
  132. package/dist/prompts/base.js +3 -3
  133. package/dist/prompts/chat.cjs +13 -15
  134. package/dist/prompts/chat.d.ts +2 -1
  135. package/dist/prompts/chat.js +2 -1
  136. package/dist/prompts/few_shot.cjs +4 -15
  137. package/dist/prompts/few_shot.d.ts +1 -1
  138. package/dist/prompts/few_shot.js +1 -1
  139. package/dist/prompts/index.cjs +2 -2
  140. package/dist/prompts/index.d.ts +1 -1
  141. package/dist/prompts/index.js +1 -1
  142. package/dist/prompts/pipeline.cjs +3 -15
  143. package/dist/prompts/pipeline.d.ts +1 -1
  144. package/dist/prompts/pipeline.js +1 -1
  145. package/dist/prompts/prompt.cjs +3 -15
  146. package/dist/prompts/prompt.d.ts +1 -1
  147. package/dist/prompts/prompt.js +1 -1
  148. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +3 -15
  149. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -1
  150. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -1
  151. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +1 -1
  152. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -1
  153. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -1
  154. package/dist/prompts/selectors/conditional.cjs +6 -15
  155. package/dist/prompts/selectors/conditional.d.ts +1 -1
  156. package/dist/prompts/selectors/conditional.js +1 -1
  157. package/dist/prompts/serde.cjs +0 -15
  158. package/dist/prompts/serde.d.ts +1 -1
  159. package/dist/prompts/serde.js +1 -1
  160. package/dist/prompts/template.cjs +9 -15
  161. package/dist/prompts/template.d.ts +1 -1
  162. package/dist/prompts/template.js +1 -1
  163. package/dist/runnables/index.cjs +1 -1
  164. package/dist/runnables/index.d.ts +1 -1
  165. package/dist/runnables/index.js +1 -1
  166. package/dist/schema/document.cjs +3 -3
  167. package/dist/schema/document.d.ts +1 -1
  168. package/dist/schema/document.js +1 -1
  169. package/dist/schema/index.cjs +12 -12
  170. package/dist/schema/index.d.ts +11 -11
  171. package/dist/schema/index.js +7 -7
  172. package/dist/schema/output_parser.cjs +1 -1
  173. package/dist/schema/output_parser.d.ts +1 -1
  174. package/dist/schema/output_parser.js +1 -1
  175. package/dist/schema/retriever.cjs +1 -1
  176. package/dist/schema/retriever.d.ts +1 -1
  177. package/dist/schema/retriever.js +1 -1
  178. package/dist/schema/runnable/base.cjs +1 -1
  179. package/dist/schema/runnable/base.d.ts +1 -1
  180. package/dist/schema/runnable/base.js +1 -1
  181. package/dist/schema/runnable/branch.cjs +1 -1
  182. package/dist/schema/runnable/branch.d.ts +1 -1
  183. package/dist/schema/runnable/branch.js +1 -1
  184. package/dist/schema/runnable/config.d.ts +1 -1
  185. package/dist/schema/runnable/index.cjs +1 -1
  186. package/dist/schema/runnable/index.d.ts +1 -1
  187. package/dist/schema/runnable/index.js +1 -1
  188. package/dist/schema/runnable/passthrough.cjs +1 -1
  189. package/dist/schema/runnable/passthrough.d.ts +1 -1
  190. package/dist/schema/runnable/passthrough.js +1 -1
  191. package/dist/schema/runnable/router.cjs +1 -1
  192. package/dist/schema/runnable/router.d.ts +1 -1
  193. package/dist/schema/runnable/router.js +1 -1
  194. package/dist/schema/storage.cjs +1 -1
  195. package/dist/schema/storage.d.ts +1 -1
  196. package/dist/schema/storage.js +1 -1
  197. package/dist/tools/base.cjs +4 -108
  198. package/dist/tools/base.d.ts +1 -72
  199. package/dist/tools/base.js +1 -105
  200. package/dist/tools/bingserpapi.d.ts +1 -1
  201. package/dist/tools/convert_to_openai.cjs +4 -38
  202. package/dist/tools/convert_to_openai.d.ts +1 -11
  203. package/dist/tools/convert_to_openai.js +1 -35
  204. package/dist/tools/searchapi.d.ts +1 -1
  205. package/dist/tools/serpapi.d.ts +1 -1
  206. package/dist/tools/serper.d.ts +1 -1
  207. package/dist/types/openai-types.d.ts +1 -133
  208. package/dist/util/async_caller.cjs +1 -1
  209. package/dist/util/async_caller.d.ts +1 -1
  210. package/dist/util/async_caller.js +1 -1
  211. package/dist/util/openai.cjs +2 -18
  212. package/dist/util/openai.d.ts +1 -1
  213. package/dist/util/openai.js +1 -17
  214. package/dist/util/openapi.d.ts +2 -2
  215. package/dist/util/prompt-layer.d.ts +1 -1
  216. package/dist/vectorstores/momento_vector_index.cjs +39 -0
  217. package/dist/vectorstores/momento_vector_index.d.ts +17 -1
  218. package/dist/vectorstores/momento_vector_index.js +40 -1
  219. package/dist/vectorstores/mongodb_atlas.cjs +22 -2
  220. package/dist/vectorstores/mongodb_atlas.d.ts +13 -0
  221. package/dist/vectorstores/mongodb_atlas.js +22 -2
  222. package/package.json +12 -10
  223. package/dist/util/openai-format-fndef.cjs +0 -81
  224. package/dist/util/openai-format-fndef.d.ts +0 -44
  225. package/dist/util/openai-format-fndef.js +0 -77
@@ -1,82 +1 @@
1
- import { type ClientOptions } from "openai";
2
- import { AzureOpenAIInput, LegacyOpenAIInput } from "../types/openai-types.js";
3
- import { Embeddings, EmbeddingsParams } from "./base.js";
4
- /**
5
- * Interface for OpenAIEmbeddings parameters. Extends EmbeddingsParams and
6
- * defines additional parameters specific to the OpenAIEmbeddings class.
7
- */
8
- export interface OpenAIEmbeddingsParams extends EmbeddingsParams {
9
- /** Model name to use */
10
- modelName: string;
11
- /**
12
- * Timeout to use when making requests to OpenAI.
13
- */
14
- timeout?: number;
15
- /**
16
- * The maximum number of documents to embed in a single request. This is
17
- * limited by the OpenAI API to a maximum of 2048.
18
- */
19
- batchSize?: number;
20
- /**
21
- * Whether to strip new lines from the input text. This is recommended by
22
- * OpenAI, but may not be suitable for all use cases.
23
- */
24
- stripNewLines?: boolean;
25
- }
26
- /**
27
- * Class for generating embeddings using the OpenAI API. Extends the
28
- * Embeddings class and implements OpenAIEmbeddingsParams and
29
- * AzureOpenAIInput.
30
- * @example
31
- * ```typescript
32
- * // Embed a query using OpenAIEmbeddings to generate embeddings for a given text
33
- * const model = new OpenAIEmbeddings();
34
- * const res = await model.embedQuery(
35
- * "What would be a good company name for a company that makes colorful socks?",
36
- * );
37
- * console.log({ res });
38
- *
39
- * ```
40
- */
41
- export declare class OpenAIEmbeddings extends Embeddings implements OpenAIEmbeddingsParams, AzureOpenAIInput {
42
- modelName: string;
43
- batchSize: number;
44
- stripNewLines: boolean;
45
- timeout?: number;
46
- azureOpenAIApiVersion?: string;
47
- azureOpenAIApiKey?: string;
48
- azureOpenAIApiInstanceName?: string;
49
- azureOpenAIApiDeploymentName?: string;
50
- azureOpenAIBasePath?: string;
51
- organization?: string;
52
- private client;
53
- private clientConfig;
54
- constructor(fields?: Partial<OpenAIEmbeddingsParams> & Partial<AzureOpenAIInput> & {
55
- verbose?: boolean;
56
- openAIApiKey?: string;
57
- configuration?: ClientOptions;
58
- }, configuration?: ClientOptions & LegacyOpenAIInput);
59
- /**
60
- * Method to generate embeddings for an array of documents. Splits the
61
- * documents into batches and makes requests to the OpenAI API to generate
62
- * embeddings.
63
- * @param texts Array of documents to generate embeddings for.
64
- * @returns Promise that resolves to a 2D array of embeddings for each document.
65
- */
66
- embedDocuments(texts: string[]): Promise<number[][]>;
67
- /**
68
- * Method to generate an embedding for a single document. Calls the
69
- * embeddingWithRetry method with the document as the input.
70
- * @param text Document to generate an embedding for.
71
- * @returns Promise that resolves to an embedding for the document.
72
- */
73
- embedQuery(text: string): Promise<number[]>;
74
- /**
75
- * Private method to make a request to the OpenAI API to generate
76
- * embeddings. Handles the retry logic and returns the response from the
77
- * API.
78
- * @param request Request to send to the OpenAI API.
79
- * @returns Promise that resolves to the response from the API.
80
- */
81
- private embeddingWithRetry;
82
- }
1
+ export { type OpenAIEmbeddingsParams, OpenAIEmbeddings, } from "@langchain/openai";
@@ -1,239 +1 @@
1
- import { OpenAI as OpenAIClient } from "openai";
2
- import { getEnvironmentVariable } from "../util/env.js";
3
- import { chunkArray } from "../util/chunk.js";
4
- import { Embeddings } from "./base.js";
5
- import { getEndpoint } from "../util/azure.js";
6
- import { wrapOpenAIClientError } from "../util/openai.js";
7
- /**
8
- * Class for generating embeddings using the OpenAI API. Extends the
9
- * Embeddings class and implements OpenAIEmbeddingsParams and
10
- * AzureOpenAIInput.
11
- * @example
12
- * ```typescript
13
- * // Embed a query using OpenAIEmbeddings to generate embeddings for a given text
14
- * const model = new OpenAIEmbeddings();
15
- * const res = await model.embedQuery(
16
- * "What would be a good company name for a company that makes colorful socks?",
17
- * );
18
- * console.log({ res });
19
- *
20
- * ```
21
- */
22
- export class OpenAIEmbeddings extends Embeddings {
23
- constructor(fields, configuration) {
24
- const fieldsWithDefaults = { maxConcurrency: 2, ...fields };
25
- super(fieldsWithDefaults);
26
- Object.defineProperty(this, "modelName", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: "text-embedding-ada-002"
31
- });
32
- Object.defineProperty(this, "batchSize", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: 512
37
- });
38
- Object.defineProperty(this, "stripNewLines", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: true
43
- });
44
- Object.defineProperty(this, "timeout", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: void 0
49
- });
50
- Object.defineProperty(this, "azureOpenAIApiVersion", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: void 0
55
- });
56
- Object.defineProperty(this, "azureOpenAIApiKey", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: void 0
61
- });
62
- Object.defineProperty(this, "azureOpenAIApiInstanceName", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: void 0
67
- });
68
- Object.defineProperty(this, "azureOpenAIApiDeploymentName", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: void 0
73
- });
74
- Object.defineProperty(this, "azureOpenAIBasePath", {
75
- enumerable: true,
76
- configurable: true,
77
- writable: true,
78
- value: void 0
79
- });
80
- Object.defineProperty(this, "organization", {
81
- enumerable: true,
82
- configurable: true,
83
- writable: true,
84
- value: void 0
85
- });
86
- Object.defineProperty(this, "client", {
87
- enumerable: true,
88
- configurable: true,
89
- writable: true,
90
- value: void 0
91
- });
92
- Object.defineProperty(this, "clientConfig", {
93
- enumerable: true,
94
- configurable: true,
95
- writable: true,
96
- value: void 0
97
- });
98
- let apiKey = fieldsWithDefaults?.openAIApiKey ??
99
- getEnvironmentVariable("OPENAI_API_KEY");
100
- const azureApiKey = fieldsWithDefaults?.azureOpenAIApiKey ??
101
- getEnvironmentVariable("AZURE_OPENAI_API_KEY");
102
- if (!azureApiKey && !apiKey) {
103
- throw new Error("OpenAI or Azure OpenAI API key not found");
104
- }
105
- const azureApiInstanceName = fieldsWithDefaults?.azureOpenAIApiInstanceName ??
106
- getEnvironmentVariable("AZURE_OPENAI_API_INSTANCE_NAME");
107
- const azureApiDeploymentName = (fieldsWithDefaults?.azureOpenAIApiEmbeddingsDeploymentName ||
108
- fieldsWithDefaults?.azureOpenAIApiDeploymentName) ??
109
- (getEnvironmentVariable("AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME") ||
110
- getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME"));
111
- const azureApiVersion = fieldsWithDefaults?.azureOpenAIApiVersion ??
112
- getEnvironmentVariable("AZURE_OPENAI_API_VERSION");
113
- this.azureOpenAIBasePath =
114
- fieldsWithDefaults?.azureOpenAIBasePath ??
115
- getEnvironmentVariable("AZURE_OPENAI_BASE_PATH");
116
- this.organization =
117
- fieldsWithDefaults?.configuration?.organization ??
118
- getEnvironmentVariable("OPENAI_ORGANIZATION");
119
- this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
120
- this.batchSize =
121
- fieldsWithDefaults?.batchSize ?? (azureApiKey ? 1 : this.batchSize);
122
- this.stripNewLines =
123
- fieldsWithDefaults?.stripNewLines ?? this.stripNewLines;
124
- this.timeout = fieldsWithDefaults?.timeout;
125
- this.azureOpenAIApiVersion = azureApiVersion;
126
- this.azureOpenAIApiKey = azureApiKey;
127
- this.azureOpenAIApiInstanceName = azureApiInstanceName;
128
- this.azureOpenAIApiDeploymentName = azureApiDeploymentName;
129
- if (this.azureOpenAIApiKey) {
130
- if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
131
- throw new Error("Azure OpenAI API instance name not found");
132
- }
133
- if (!this.azureOpenAIApiDeploymentName) {
134
- throw new Error("Azure OpenAI API deployment name not found");
135
- }
136
- if (!this.azureOpenAIApiVersion) {
137
- throw new Error("Azure OpenAI API version not found");
138
- }
139
- apiKey = apiKey ?? "";
140
- }
141
- this.clientConfig = {
142
- apiKey,
143
- organization: this.organization,
144
- baseURL: configuration?.basePath,
145
- dangerouslyAllowBrowser: true,
146
- defaultHeaders: configuration?.baseOptions?.headers,
147
- defaultQuery: configuration?.baseOptions?.params,
148
- ...configuration,
149
- ...fields?.configuration,
150
- };
151
- }
152
- /**
153
- * Method to generate embeddings for an array of documents. Splits the
154
- * documents into batches and makes requests to the OpenAI API to generate
155
- * embeddings.
156
- * @param texts Array of documents to generate embeddings for.
157
- * @returns Promise that resolves to a 2D array of embeddings for each document.
158
- */
159
- async embedDocuments(texts) {
160
- const batches = chunkArray(this.stripNewLines ? texts.map((t) => t.replace(/\n/g, " ")) : texts, this.batchSize);
161
- const batchRequests = batches.map((batch) => this.embeddingWithRetry({
162
- model: this.modelName,
163
- input: batch,
164
- }));
165
- const batchResponses = await Promise.all(batchRequests);
166
- const embeddings = [];
167
- for (let i = 0; i < batchResponses.length; i += 1) {
168
- const batch = batches[i];
169
- const { data: batchResponse } = batchResponses[i];
170
- for (let j = 0; j < batch.length; j += 1) {
171
- embeddings.push(batchResponse[j].embedding);
172
- }
173
- }
174
- return embeddings;
175
- }
176
- /**
177
- * Method to generate an embedding for a single document. Calls the
178
- * embeddingWithRetry method with the document as the input.
179
- * @param text Document to generate an embedding for.
180
- * @returns Promise that resolves to an embedding for the document.
181
- */
182
- async embedQuery(text) {
183
- const { data } = await this.embeddingWithRetry({
184
- model: this.modelName,
185
- input: this.stripNewLines ? text.replace(/\n/g, " ") : text,
186
- });
187
- return data[0].embedding;
188
- }
189
- /**
190
- * Private method to make a request to the OpenAI API to generate
191
- * embeddings. Handles the retry logic and returns the response from the
192
- * API.
193
- * @param request Request to send to the OpenAI API.
194
- * @returns Promise that resolves to the response from the API.
195
- */
196
- async embeddingWithRetry(request) {
197
- if (!this.client) {
198
- const openAIEndpointConfig = {
199
- azureOpenAIApiDeploymentName: this.azureOpenAIApiDeploymentName,
200
- azureOpenAIApiInstanceName: this.azureOpenAIApiInstanceName,
201
- azureOpenAIApiKey: this.azureOpenAIApiKey,
202
- azureOpenAIBasePath: this.azureOpenAIBasePath,
203
- baseURL: this.clientConfig.baseURL,
204
- };
205
- const endpoint = getEndpoint(openAIEndpointConfig);
206
- const params = {
207
- ...this.clientConfig,
208
- baseURL: endpoint,
209
- timeout: this.timeout,
210
- maxRetries: 0,
211
- };
212
- if (!params.baseURL) {
213
- delete params.baseURL;
214
- }
215
- this.client = new OpenAIClient(params);
216
- }
217
- const requestOptions = {};
218
- if (this.azureOpenAIApiKey) {
219
- requestOptions.headers = {
220
- "api-key": this.azureOpenAIApiKey,
221
- ...requestOptions.headers,
222
- };
223
- requestOptions.query = {
224
- "api-version": this.azureOpenAIApiVersion,
225
- ...requestOptions.query,
226
- };
227
- }
228
- return this.caller.call(async () => {
229
- try {
230
- const res = await this.client.embeddings.create(request, requestOptions);
231
- return res;
232
- }
233
- catch (e) {
234
- const error = wrapOpenAIClientError(e);
235
- throw error;
236
- }
237
- });
238
- }
239
- }
1
+ export { OpenAIEmbeddings, } from "@langchain/openai";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpenAIAssistantRunnable = void 0;
4
- const openai_1 = require("openai");
4
+ const openai_1 = require("@langchain/openai");
5
5
  const base_js_1 = require("../../schema/runnable/base.cjs");
6
6
  const time_js_1 = require("../../util/time.cjs");
7
7
  const base_js_2 = require("../../tools/base.cjs");
@@ -39,7 +39,7 @@ class OpenAIAssistantRunnable extends base_js_1.Runnable {
39
39
  writable: true,
40
40
  value: void 0
41
41
  });
42
- this.client = fields.client ?? new openai_1.OpenAI(fields?.clientOptions);
42
+ this.client = fields.client ?? new openai_1.OpenAIClient(fields?.clientOptions);
43
43
  this.assistantId = fields.assistantId;
44
44
  this.asAgent = fields.asAgent ?? this.asAgent;
45
45
  }
@@ -51,7 +51,7 @@ class OpenAIAssistantRunnable extends base_js_1.Runnable {
51
51
  }
52
52
  return tool;
53
53
  }) ?? [];
54
- const oaiClient = client ?? new openai_1.OpenAI(clientOptions);
54
+ const oaiClient = client ?? new openai_1.OpenAIClient(clientOptions);
55
55
  const assistant = await oaiClient.beta.assistants.create({
56
56
  name,
57
57
  instructions,
@@ -1,4 +1,4 @@
1
- import { type ClientOptions, OpenAI as OpenAIClient } from "openai";
1
+ import { type ClientOptions, OpenAIClient } from "@langchain/openai";
2
2
  import { Runnable } from "../../schema/runnable/base.js";
3
3
  import type { RunnableConfig } from "../../schema/runnable/config.js";
4
4
  import type { OpenAIAssistantFinish, OpenAIAssistantAction, OpenAIToolType } from "./schema.js";
@@ -1,4 +1,4 @@
1
- import { OpenAI as OpenAIClient } from "openai";
1
+ import { OpenAIClient } from "@langchain/openai";
2
2
  import { Runnable } from "../../schema/runnable/base.js";
3
3
  import { sleep } from "../../util/time.js";
4
4
  import { StructuredTool } from "../../tools/base.js";
@@ -1,4 +1,4 @@
1
- import type { OpenAI as OpenAIClient } from "openai";
1
+ import type { OpenAIClient } from "@langchain/openai";
2
2
  import type { AgentFinish, AgentAction } from "../../schema/index.js";
3
3
  export type OpenAIAssistantFinish = AgentFinish & {
4
4
  runId: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpenAIFiles = void 0;
4
- const openai_1 = require("openai");
4
+ const openai_1 = require("@langchain/openai");
5
5
  const serializable_js_1 = require("../../load/serializable.cjs");
6
6
  class OpenAIFiles extends serializable_js_1.Serializable {
7
7
  constructor(fields) {
@@ -18,7 +18,7 @@ class OpenAIFiles extends serializable_js_1.Serializable {
18
18
  writable: true,
19
19
  value: void 0
20
20
  });
21
- this.oaiClient = fields?.client ?? new openai_1.OpenAI(fields?.clientOptions);
21
+ this.oaiClient = fields?.client ?? new openai_1.OpenAIClient(fields?.clientOptions);
22
22
  }
23
23
  /**
24
24
  * Upload file
@@ -1,4 +1,4 @@
1
- import { ClientOptions, OpenAI as OpenAIClient } from "openai";
1
+ import { OpenAIClient, type ClientOptions } from "@langchain/openai";
2
2
  import { Serializable } from "../../load/serializable.js";
3
3
  export type OpenAIFilesInput = {
4
4
  client?: OpenAIClient;
@@ -1,4 +1,4 @@
1
- import { OpenAI as OpenAIClient } from "openai";
1
+ import { OpenAIClient } from "@langchain/openai";
2
2
  import { Serializable } from "../../load/serializable.js";
3
3
  export class OpenAIFiles extends Serializable {
4
4
  constructor(fields) {
@@ -10,4 +10,4 @@ export declare const DEFAULT_STEP_EXECUTOR_HUMAN_CHAT_MESSAGE_TEMPLATE = "Previo
10
10
  * @param tools the tools available to the `planner`
11
11
  * @returns
12
12
  */
13
- export declare const getPlannerChatPrompt: (tools: Tool[] | DynamicStructuredTool[]) => Promise<ChatPromptTemplate<import("langchain-core/schema").InputValues<string>, any>>;
13
+ export declare const getPlannerChatPrompt: (tools: Tool[] | DynamicStructuredTool[]) => Promise<ChatPromptTemplate<import("@langchain/core/utils/types").InputValues<string>, any>>;
@@ -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/llm"), exports);
17
+ __exportStar(require("@langchain/core/language_models/llms"), exports);
@@ -1 +1 @@
1
- export * from "langchain-core/llm";
1
+ export * from "@langchain/core/language_models/llms";
package/dist/llms/base.js CHANGED
@@ -1 +1 @@
1
- export * from "langchain-core/llm";
1
+ export * from "@langchain/core/language_models/llms";
@@ -278,11 +278,31 @@ class Bedrock extends base_js_1.LLM {
278
278
  }
279
279
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
280
280
  _readChunks(reader) {
281
+ function _concatChunks(a, b) {
282
+ const newBuffer = new Uint8Array(a.length + b.length);
283
+ newBuffer.set(a);
284
+ newBuffer.set(b, a.length);
285
+ return newBuffer;
286
+ }
287
+ function getMessageLength(buffer) {
288
+ if (buffer.byteLength === 0)
289
+ return 0;
290
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
291
+ return view.getUint32(0, false);
292
+ }
281
293
  return {
282
294
  async *[Symbol.asyncIterator]() {
283
295
  let readResult = await reader.read();
296
+ let buffer = new Uint8Array(0);
284
297
  while (!readResult.done) {
285
- yield readResult.value;
298
+ const chunk = readResult.value;
299
+ buffer = _concatChunks(buffer, chunk);
300
+ let messageLength = getMessageLength(buffer);
301
+ while (buffer.byteLength > 0 && buffer.byteLength >= messageLength) {
302
+ yield buffer.slice(0, messageLength);
303
+ buffer = buffer.slice(messageLength);
304
+ messageLength = getMessageLength(buffer);
305
+ }
286
306
  readResult = await reader.read();
287
307
  }
288
308
  },
@@ -61,6 +61,6 @@ export declare class Bedrock extends LLM implements BaseBedrockInput {
61
61
  };
62
62
  _streamResponseChunks(prompt: string, options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;
63
63
  _readChunks(reader: any): {
64
- [Symbol.asyncIterator](): AsyncGenerator<any, void, unknown>;
64
+ [Symbol.asyncIterator](): AsyncGenerator<Uint8Array, void, unknown>;
65
65
  };
66
66
  }
@@ -275,11 +275,31 @@ export class Bedrock extends LLM {
275
275
  }
276
276
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
277
277
  _readChunks(reader) {
278
+ function _concatChunks(a, b) {
279
+ const newBuffer = new Uint8Array(a.length + b.length);
280
+ newBuffer.set(a);
281
+ newBuffer.set(b, a.length);
282
+ return newBuffer;
283
+ }
284
+ function getMessageLength(buffer) {
285
+ if (buffer.byteLength === 0)
286
+ return 0;
287
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
288
+ return view.getUint32(0, false);
289
+ }
278
290
  return {
279
291
  async *[Symbol.asyncIterator]() {
280
292
  let readResult = await reader.read();
293
+ let buffer = new Uint8Array(0);
281
294
  while (!readResult.done) {
282
- yield readResult.value;
295
+ const chunk = readResult.value;
296
+ buffer = _concatChunks(buffer, chunk);
297
+ let messageLength = getMessageLength(buffer);
298
+ while (buffer.byteLength > 0 && buffer.byteLength >= messageLength) {
299
+ yield buffer.slice(0, messageLength);
300
+ buffer = buffer.slice(messageLength);
301
+ messageLength = getMessageLength(buffer);
302
+ }
283
303
  readResult = await reader.read();
284
304
  }
285
305
  },
@@ -1,4 +1,4 @@
1
- import type { OpenAI as OpenAIClient } from "openai";
1
+ import type { OpenAIClient } from "@langchain/openai";
2
2
  import type { BaseLLMParams } from "./base.js";
3
3
  import type { OpenAICallOptions, OpenAIInput } from "./openai.js";
4
4
  import type { OpenAICoreRequestOptions } from "../types/openai-types.js";
@@ -26,7 +26,7 @@ export declare class Fireworks extends OpenAI<FireworksCallOptions> {
26
26
  constructor(fields?: Partial<Omit<OpenAIInput, "openAIApiKey" | FireworksUnsupportedArgs>> & BaseLLMParams & {
27
27
  fireworksApiKey?: string;
28
28
  });
29
- toJSON(): import("langchain-core/load/serializable").Serialized;
29
+ toJSON(): import("@langchain/core/load/serializable").Serialized;
30
30
  completionWithRetry(request: OpenAIClient.CompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Completion>>;
31
31
  completionWithRetry(request: OpenAIClient.CompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Completions.Completion>;
32
32
  }