langchain 0.3.34 → 0.3.35

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.
@@ -47,7 +47,7 @@ class LocalFileCache extends caches_1.BaseCache {
47
47
  * @returns An array of Generations if found, null otherwise.
48
48
  */
49
49
  async lookup(prompt, llmKey) {
50
- const key = `${(0, caches_1.getCacheKey)(prompt, llmKey)}.json`;
50
+ const key = `${this.keyEncoder(prompt, llmKey)}.json`;
51
51
  try {
52
52
  const content = await promises_1.default.readFile(node_path_1.default.join(this.cacheDir, key));
53
53
  return JSON.parse(content.toString()).map(caches_1.deserializeStoredGeneration);
@@ -65,7 +65,7 @@ class LocalFileCache extends caches_1.BaseCache {
65
65
  * @param generations The value to be stored in the cache.
66
66
  */
67
67
  async update(prompt, llmKey, generations) {
68
- const key = `${(0, caches_1.getCacheKey)(prompt, llmKey)}.json`;
68
+ const key = `${this.keyEncoder(prompt, llmKey)}.json`;
69
69
  await promises_1.default.writeFile(node_path_1.default.join(this.cacheDir, key), JSON.stringify(generations.map(caches_1.serializeGeneration)));
70
70
  }
71
71
  }
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs/promises";
3
- import { BaseCache, getCacheKey, serializeGeneration, deserializeStoredGeneration, } from "@langchain/core/caches";
3
+ import { BaseCache, serializeGeneration, deserializeStoredGeneration, } from "@langchain/core/caches";
4
4
  /**
5
5
  * A cache that uses the local filesystem as the backing store.
6
6
  * This is useful for local development and testing. But it is not recommended for production use.
@@ -41,7 +41,7 @@ export class LocalFileCache extends BaseCache {
41
41
  * @returns An array of Generations if found, null otherwise.
42
42
  */
43
43
  async lookup(prompt, llmKey) {
44
- const key = `${getCacheKey(prompt, llmKey)}.json`;
44
+ const key = `${this.keyEncoder(prompt, llmKey)}.json`;
45
45
  try {
46
46
  const content = await fs.readFile(path.join(this.cacheDir, key));
47
47
  return JSON.parse(content.toString()).map(deserializeStoredGeneration);
@@ -59,7 +59,7 @@ export class LocalFileCache extends BaseCache {
59
59
  * @param generations The value to be stored in the cache.
60
60
  */
61
61
  async update(prompt, llmKey, generations) {
62
- const key = `${getCacheKey(prompt, llmKey)}.json`;
62
+ const key = `${this.keyEncoder(prompt, llmKey)}.json`;
63
63
  await fs.writeFile(path.join(this.cacheDir, key), JSON.stringify(generations.map(serializeGeneration)));
64
64
  }
65
65
  }
@@ -56,6 +56,7 @@ const _SUPPORTED_PROVIDERS = [
56
56
  "cerebras",
57
57
  "deepseek",
58
58
  "xai",
59
+ "perplexity",
59
60
  ];
60
61
  async function _initChatModelHelper(model, modelProvider,
61
62
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -148,6 +149,18 @@ params = {}) {
148
149
  "@langchain/community/chat_models/togetherai")));
149
150
  return new ChatTogetherAI({ model, ...passedParams });
150
151
  }
152
+ case "perplexity": {
153
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
154
+ // @ts-ignore - Can not install as a proper dependency due to circular dependency
155
+ const { ChatPerplexity } = await Promise.resolve().then(() => __importStar(require(
156
+ // We can not 'expect-error' because if you explicitly build `@langchain/community`
157
+ // this import will be able to be resolved, thus there will be no error. However
158
+ // this will never be the case in CI.
159
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
160
+ // @ts-ignore - Can not install as a proper dependency due to circular dependency
161
+ "@langchain/community/chat_models/perplexity")));
162
+ return new ChatPerplexity({ model, ...passedParams });
163
+ }
151
164
  default: {
152
165
  const supported = _SUPPORTED_PROVIDERS.join(", ");
153
166
  throw new Error(`Unsupported { modelProvider: ${modelProviderCopy} }.\n\nSupported model providers are: ${supported}`);
@@ -203,6 +216,9 @@ function _inferModelProvider(modelName) {
203
216
  else if (modelName.startsWith("mistral")) {
204
217
  return "mistralai";
205
218
  }
219
+ else if (modelName.startsWith("sonar") || modelName.startsWith("pplx")) {
220
+ return "perplexity";
221
+ }
206
222
  else {
207
223
  return undefined;
208
224
  }
@@ -456,6 +472,7 @@ exports.ConfigurableModel = ConfigurableModel;
456
472
  * - mistralai (@langchain/mistralai)
457
473
  * - groq (@langchain/groq)
458
474
  * - ollama (@langchain/ollama)
475
+ * - perplexity (@langchain/community/chat_models/perplexity)
459
476
  * - cerebras (@langchain/cerebras)
460
477
  * - deepseek (@langchain/deepseek)
461
478
  * - xai (@langchain/xai)
@@ -9,7 +9,7 @@ import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
9
9
  import { ChatResult } from "@langchain/core/outputs";
10
10
  interface EventStreamCallbackHandlerInput extends Omit<LogStreamCallbackHandlerInput, "_schemaFormat"> {
11
11
  }
12
- declare const _SUPPORTED_PROVIDERS: readonly ["openai", "anthropic", "azure_openai", "cohere", "google-vertexai", "google-vertexai-web", "google-genai", "ollama", "together", "fireworks", "mistralai", "groq", "bedrock", "cerebras", "deepseek", "xai"];
12
+ declare const _SUPPORTED_PROVIDERS: readonly ["openai", "anthropic", "azure_openai", "cohere", "google-vertexai", "google-vertexai-web", "google-genai", "ollama", "together", "fireworks", "mistralai", "groq", "bedrock", "cerebras", "deepseek", "xai", "perplexity"];
13
13
  export type ChatModelProvider = (typeof _SUPPORTED_PROVIDERS)[number];
14
14
  export interface ConfigurableChatModelCallOptions extends BaseChatModelCallOptions {
15
15
  tools?: (StructuredToolInterface | Record<string, unknown> | ToolDefinition | RunnableToolLike)[];
@@ -18,6 +18,7 @@ const _SUPPORTED_PROVIDERS = [
18
18
  "cerebras",
19
19
  "deepseek",
20
20
  "xai",
21
+ "perplexity",
21
22
  ];
22
23
  async function _initChatModelHelper(model, modelProvider,
23
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -110,6 +111,18 @@ params = {}) {
110
111
  "@langchain/community/chat_models/togetherai");
111
112
  return new ChatTogetherAI({ model, ...passedParams });
112
113
  }
114
+ case "perplexity": {
115
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
116
+ // @ts-ignore - Can not install as a proper dependency due to circular dependency
117
+ const { ChatPerplexity } = await import(
118
+ // We can not 'expect-error' because if you explicitly build `@langchain/community`
119
+ // this import will be able to be resolved, thus there will be no error. However
120
+ // this will never be the case in CI.
121
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
122
+ // @ts-ignore - Can not install as a proper dependency due to circular dependency
123
+ "@langchain/community/chat_models/perplexity");
124
+ return new ChatPerplexity({ model, ...passedParams });
125
+ }
113
126
  default: {
114
127
  const supported = _SUPPORTED_PROVIDERS.join(", ");
115
128
  throw new Error(`Unsupported { modelProvider: ${modelProviderCopy} }.\n\nSupported model providers are: ${supported}`);
@@ -165,6 +178,9 @@ export function _inferModelProvider(modelName) {
165
178
  else if (modelName.startsWith("mistral")) {
166
179
  return "mistralai";
167
180
  }
181
+ else if (modelName.startsWith("sonar") || modelName.startsWith("pplx")) {
182
+ return "perplexity";
183
+ }
168
184
  else {
169
185
  return undefined;
170
186
  }
@@ -417,6 +433,7 @@ export class ConfigurableModel extends BaseChatModel {
417
433
  * - mistralai (@langchain/mistralai)
418
434
  * - groq (@langchain/groq)
419
435
  * - ollama (@langchain/ollama)
436
+ * - perplexity (@langchain/community/chat_models/perplexity)
420
437
  * - cerebras (@langchain/cerebras)
421
438
  * - deepseek (@langchain/deepseek)
422
439
  * - xai (@langchain/xai)
package/dist/hub/base.cjs CHANGED
@@ -146,14 +146,21 @@ function bindOutputSchema(loadedSequence) {
146
146
  "schema" in loadedSequence.first &&
147
147
  "last" in loadedSequence &&
148
148
  loadedSequence.last !== null &&
149
- typeof loadedSequence.last === "object" &&
150
- "bound" in loadedSequence.last &&
151
- loadedSequence.last.bound !== null &&
152
- typeof loadedSequence.last.bound === "object" &&
153
- "withStructuredOutput" in loadedSequence.last.bound &&
154
- typeof loadedSequence.last.bound.withStructuredOutput === "function") {
155
- // eslint-disable-next-line no-param-reassign
156
- loadedSequence.last.bound = loadedSequence.last.bound.withStructuredOutput(loadedSequence.first.schema);
149
+ typeof loadedSequence.last === "object") {
150
+ if ("bound" in loadedSequence.last &&
151
+ loadedSequence.last.bound !== null &&
152
+ typeof loadedSequence.last.bound === "object" &&
153
+ "withStructuredOutput" in loadedSequence.last.bound &&
154
+ typeof loadedSequence.last.bound.withStructuredOutput === "function") {
155
+ // eslint-disable-next-line no-param-reassign
156
+ loadedSequence.last.bound =
157
+ loadedSequence.last.bound.withStructuredOutput(loadedSequence.first.schema);
158
+ }
159
+ else if ("withStructuredOutput" in loadedSequence.last &&
160
+ typeof loadedSequence.last.withStructuredOutput === "function") {
161
+ // eslint-disable-next-line no-param-reassign
162
+ loadedSequence.last = loadedSequence.last.withStructuredOutput(loadedSequence.first.schema);
163
+ }
157
164
  }
158
165
  return loadedSequence;
159
166
  }
package/dist/hub/base.js CHANGED
@@ -139,14 +139,21 @@ export function bindOutputSchema(loadedSequence) {
139
139
  "schema" in loadedSequence.first &&
140
140
  "last" in loadedSequence &&
141
141
  loadedSequence.last !== null &&
142
- typeof loadedSequence.last === "object" &&
143
- "bound" in loadedSequence.last &&
144
- loadedSequence.last.bound !== null &&
145
- typeof loadedSequence.last.bound === "object" &&
146
- "withStructuredOutput" in loadedSequence.last.bound &&
147
- typeof loadedSequence.last.bound.withStructuredOutput === "function") {
148
- // eslint-disable-next-line no-param-reassign
149
- loadedSequence.last.bound = loadedSequence.last.bound.withStructuredOutput(loadedSequence.first.schema);
142
+ typeof loadedSequence.last === "object") {
143
+ if ("bound" in loadedSequence.last &&
144
+ loadedSequence.last.bound !== null &&
145
+ typeof loadedSequence.last.bound === "object" &&
146
+ "withStructuredOutput" in loadedSequence.last.bound &&
147
+ typeof loadedSequence.last.bound.withStructuredOutput === "function") {
148
+ // eslint-disable-next-line no-param-reassign
149
+ loadedSequence.last.bound =
150
+ loadedSequence.last.bound.withStructuredOutput(loadedSequence.first.schema);
151
+ }
152
+ else if ("withStructuredOutput" in loadedSequence.last &&
153
+ typeof loadedSequence.last.withStructuredOutput === "function") {
154
+ // eslint-disable-next-line no-param-reassign
155
+ loadedSequence.last = loadedSequence.last.withStructuredOutput(loadedSequence.first.schema);
156
+ }
150
157
  }
151
158
  return loadedSequence;
152
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.3.34",
3
+ "version": "0.3.35",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {