@langchain/core 0.1.51 → 0.1.52

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.
@@ -2,6 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StructuredPrompt = void 0;
4
4
  const chat_js_1 = require("./chat.cjs");
5
+ function isWithStructuredOutput(x
6
+ // eslint-disable-next-line @typescript-eslint/ban-types
7
+ ) {
8
+ return (typeof x === "object" &&
9
+ x != null &&
10
+ "withStructuredOutput" in x &&
11
+ typeof x.withStructuredOutput === "function");
12
+ }
13
+ function isRunnableBinding(x) {
14
+ return (typeof x === "object" &&
15
+ x != null &&
16
+ "lc_id" in x &&
17
+ Array.isArray(x.lc_id) &&
18
+ x.lc_id.join("/") === "langchain_core/runnables/RunnableBinding");
19
+ }
5
20
  class StructuredPrompt extends chat_js_1.ChatPromptTemplate {
6
21
  get lc_aliases() {
7
22
  return {
@@ -18,17 +33,26 @@ class StructuredPrompt extends chat_js_1.ChatPromptTemplate {
18
33
  writable: true,
19
34
  value: void 0
20
35
  });
36
+ Object.defineProperty(this, "lc_namespace", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: ["langchain_core", "prompts", "structured"]
41
+ });
21
42
  this.schema = input.schema;
22
43
  }
23
44
  pipe(coerceable) {
24
- if (typeof coerceable === "object" &&
25
- "withStructuredOutput" in coerceable &&
26
- typeof coerceable.withStructuredOutput === "function") {
45
+ if (isWithStructuredOutput(coerceable)) {
27
46
  return super.pipe(coerceable.withStructuredOutput(this.schema));
28
47
  }
29
- else {
30
- throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
48
+ if (isRunnableBinding(coerceable) &&
49
+ isWithStructuredOutput(coerceable.bound)) {
50
+ return super.pipe(coerceable.bound
51
+ .withStructuredOutput(this.schema)
52
+ .bind(coerceable.kwargs ?? {})
53
+ .withConfig(coerceable.config));
31
54
  }
55
+ throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
32
56
  }
33
57
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
58
  static fromMessagesAndSchema(promptMessages, schema
@@ -11,6 +11,7 @@ export interface StructuredPromptInput<RunInput extends InputValues = any, Parti
11
11
  }
12
12
  export declare class StructuredPrompt<RunInput extends InputValues = any, PartialVariableName extends string = any> extends ChatPromptTemplate<RunInput, PartialVariableName> implements StructuredPromptInput<RunInput, PartialVariableName> {
13
13
  schema: Record<string, any>;
14
+ lc_namespace: string[];
14
15
  get lc_aliases(): Record<string, string>;
15
16
  constructor(input: StructuredPromptInput<RunInput, PartialVariableName>);
16
17
  pipe<NewRunOutput>(coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>): Runnable<RunInput, Exclude<NewRunOutput, Error>, RunnableConfig>;
@@ -1,4 +1,19 @@
1
1
  import { ChatPromptTemplate, } from "./chat.js";
2
+ function isWithStructuredOutput(x
3
+ // eslint-disable-next-line @typescript-eslint/ban-types
4
+ ) {
5
+ return (typeof x === "object" &&
6
+ x != null &&
7
+ "withStructuredOutput" in x &&
8
+ typeof x.withStructuredOutput === "function");
9
+ }
10
+ function isRunnableBinding(x) {
11
+ return (typeof x === "object" &&
12
+ x != null &&
13
+ "lc_id" in x &&
14
+ Array.isArray(x.lc_id) &&
15
+ x.lc_id.join("/") === "langchain_core/runnables/RunnableBinding");
16
+ }
2
17
  export class StructuredPrompt extends ChatPromptTemplate {
3
18
  get lc_aliases() {
4
19
  return {
@@ -15,17 +30,26 @@ export class StructuredPrompt extends ChatPromptTemplate {
15
30
  writable: true,
16
31
  value: void 0
17
32
  });
33
+ Object.defineProperty(this, "lc_namespace", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: ["langchain_core", "prompts", "structured"]
38
+ });
18
39
  this.schema = input.schema;
19
40
  }
20
41
  pipe(coerceable) {
21
- if (typeof coerceable === "object" &&
22
- "withStructuredOutput" in coerceable &&
23
- typeof coerceable.withStructuredOutput === "function") {
42
+ if (isWithStructuredOutput(coerceable)) {
24
43
  return super.pipe(coerceable.withStructuredOutput(this.schema));
25
44
  }
26
- else {
27
- throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
45
+ if (isRunnableBinding(coerceable) &&
46
+ isWithStructuredOutput(coerceable.bound)) {
47
+ return super.pipe(coerceable.bound
48
+ .withStructuredOutput(this.schema)
49
+ .bind(coerceable.kwargs ?? {})
50
+ .withConfig(coerceable.config));
28
51
  }
52
+ throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
29
53
  }
30
54
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
55
  static fromMessagesAndSchema(promptMessages, schema
@@ -232,7 +232,7 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ru
232
232
  lc_serializable: boolean;
233
233
  bound: Runnable<RunInput, RunOutput, CallOptions>;
234
234
  config: RunnableConfig;
235
- protected kwargs?: Partial<CallOptions>;
235
+ kwargs?: Partial<CallOptions>;
236
236
  configFactories?: Array<(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>>;
237
237
  constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>);
238
238
  getName(suffix?: string | undefined): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {