langchain 0.0.149 → 0.0.150

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.
@@ -44,6 +44,12 @@ class Replicate extends base_js_1.LLM {
44
44
  writable: true,
45
45
  value: void 0
46
46
  });
47
+ Object.defineProperty(this, "promptKey", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
47
53
  const apiKey = fields?.apiKey ??
48
54
  (0, env_js_1.getEnvironmentVariable)("REPLICATE_API_KEY") ?? // previous environment variable for backwards compatibility
49
55
  (0, env_js_1.getEnvironmentVariable)("REPLICATE_API_TOKEN"); // current environment variable, matching the Python library
@@ -53,6 +59,7 @@ class Replicate extends base_js_1.LLM {
53
59
  this.apiKey = apiKey;
54
60
  this.model = fields.model;
55
61
  this.input = fields.input ?? {};
62
+ this.promptKey = fields.promptKey;
56
63
  }
57
64
  _llmType() {
58
65
  return "replicate";
@@ -64,11 +71,30 @@ class Replicate extends base_js_1.LLM {
64
71
  userAgent: "langchain",
65
72
  auth: this.apiKey,
66
73
  });
74
+ if (this.promptKey === undefined) {
75
+ const [modelString, versionString] = this.model.split(":");
76
+ const version = await replicate.models.versions.get(modelString.split("/")[0], modelString.split("/")[1], versionString);
77
+ const openapiSchema = version.openapi_schema;
78
+ const inputProperties =
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ openapiSchema?.components?.schemas?.Input?.properties;
81
+ if (inputProperties === undefined) {
82
+ this.promptKey = "prompt";
83
+ }
84
+ else {
85
+ const sortedInputProperties = Object.entries(inputProperties).sort(([_keyA, valueA], [_keyB, valueB]) => {
86
+ const orderA = valueA["x-order"] || 0;
87
+ const orderB = valueB["x-order"] || 0;
88
+ return orderA - orderB;
89
+ });
90
+ this.promptKey = sortedInputProperties[0][0] ?? "prompt";
91
+ }
92
+ }
67
93
  const output = await this.caller.callWithOptions({ signal: options.signal }, () => replicate.run(this.model, {
68
- wait: true,
69
94
  input: {
95
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96
+ [this.promptKey]: prompt,
70
97
  ...this.input,
71
- prompt,
72
98
  },
73
99
  }));
74
100
  if (typeof output === "string") {
@@ -10,6 +10,8 @@ export interface ReplicateInput {
10
10
  [key: string]: string | number | boolean;
11
11
  };
12
12
  apiKey?: string;
13
+ /** The key used to pass prompts to the model. */
14
+ promptKey?: string;
13
15
  }
14
16
  /**
15
17
  * Class responsible for managing the interaction with the Replicate API.
@@ -26,6 +28,7 @@ export declare class Replicate extends LLM implements ReplicateInput {
26
28
  model: ReplicateInput["model"];
27
29
  input: ReplicateInput["input"];
28
30
  apiKey: string;
31
+ promptKey?: string;
29
32
  constructor(fields: ReplicateInput & BaseLLMParams);
30
33
  _llmType(): string;
31
34
  /** @ignore */
@@ -41,6 +41,12 @@ export class Replicate extends LLM {
41
41
  writable: true,
42
42
  value: void 0
43
43
  });
44
+ Object.defineProperty(this, "promptKey", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
44
50
  const apiKey = fields?.apiKey ??
45
51
  getEnvironmentVariable("REPLICATE_API_KEY") ?? // previous environment variable for backwards compatibility
46
52
  getEnvironmentVariable("REPLICATE_API_TOKEN"); // current environment variable, matching the Python library
@@ -50,6 +56,7 @@ export class Replicate extends LLM {
50
56
  this.apiKey = apiKey;
51
57
  this.model = fields.model;
52
58
  this.input = fields.input ?? {};
59
+ this.promptKey = fields.promptKey;
53
60
  }
54
61
  _llmType() {
55
62
  return "replicate";
@@ -61,11 +68,30 @@ export class Replicate extends LLM {
61
68
  userAgent: "langchain",
62
69
  auth: this.apiKey,
63
70
  });
71
+ if (this.promptKey === undefined) {
72
+ const [modelString, versionString] = this.model.split(":");
73
+ const version = await replicate.models.versions.get(modelString.split("/")[0], modelString.split("/")[1], versionString);
74
+ const openapiSchema = version.openapi_schema;
75
+ const inputProperties =
76
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
+ openapiSchema?.components?.schemas?.Input?.properties;
78
+ if (inputProperties === undefined) {
79
+ this.promptKey = "prompt";
80
+ }
81
+ else {
82
+ const sortedInputProperties = Object.entries(inputProperties).sort(([_keyA, valueA], [_keyB, valueB]) => {
83
+ const orderA = valueA["x-order"] || 0;
84
+ const orderB = valueB["x-order"] || 0;
85
+ return orderA - orderB;
86
+ });
87
+ this.promptKey = sortedInputProperties[0][0] ?? "prompt";
88
+ }
89
+ }
64
90
  const output = await this.caller.callWithOptions({ signal: options.signal }, () => replicate.run(this.model, {
65
- wait: true,
66
91
  input: {
92
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
93
+ [this.promptKey]: prompt,
67
94
  ...this.input,
68
- prompt,
69
95
  },
70
96
  }));
71
97
  if (typeof output === "string") {
@@ -99,6 +99,8 @@ class PromptTemplate extends base_js_1.BaseStringPromptTemplate {
99
99
  }
100
100
  });
101
101
  return new PromptTemplate({
102
+ // Rely on extracted types
103
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
104
  inputVariables: [...names],
103
105
  templateFormat,
104
106
  template,
@@ -32,7 +32,7 @@ type NonAlphanumeric = " " | "\t" | "\n" | "\r" | '"' | "'" | "{" | "[" | "(" |
32
32
  */
33
33
  type ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;
34
34
  export type ParamsFromFString<T extends string> = {
35
- [Key in ExtractTemplateParamsRecursive<T>[number]]: string;
35
+ [Key in ExtractTemplateParamsRecursive<T>[number] | (string & Record<never, never>)]: string;
36
36
  };
37
37
  /**
38
38
  * Schema to represent a basic prompt for an LLM.
@@ -96,6 +96,8 @@ export class PromptTemplate extends BaseStringPromptTemplate {
96
96
  }
97
97
  });
98
98
  return new PromptTemplate({
99
+ // Rely on extracted types
100
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
101
  inputVariables: [...names],
100
102
  templateFormat,
101
103
  template,
@@ -700,6 +700,7 @@ class RunnableSequence extends Runnable {
700
700
  static isRunnableSequence(thing) {
701
701
  return Array.isArray(thing.middle) && Runnable.isRunnable(thing);
702
702
  }
703
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
703
704
  static from([first, ...runnables]) {
704
705
  return new RunnableSequence({
705
706
  first: _coerceToRunnable(first),
@@ -242,7 +242,7 @@ export declare class RunnableSequence<RunInput = any, RunOutput = any> extends R
242
242
  _streamIterator(input: RunInput, options?: RunnableConfig): AsyncGenerator<RunOutput>;
243
243
  pipe<NewRunOutput>(coerceable: RunnableLike<RunOutput, NewRunOutput>): RunnableSequence<RunInput, Exclude<NewRunOutput, Error>>;
244
244
  static isRunnableSequence(thing: any): thing is RunnableSequence;
245
- static from<RunInput, RunOutput>([first, ...runnables]: [
245
+ static from<RunInput = any, RunOutput = any>([first, ...runnables]: [
246
246
  RunnableLike<RunInput>,
247
247
  ...RunnableLike[],
248
248
  RunnableLike<any, RunOutput>
@@ -690,6 +690,7 @@ export class RunnableSequence extends Runnable {
690
690
  static isRunnableSequence(thing) {
691
691
  return Array.isArray(thing.middle) && Runnable.isRunnable(thing);
692
692
  }
693
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
693
694
  static from([first, ...runnables]) {
694
695
  return new RunnableSequence({
695
696
  first: _coerceToRunnable(first),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.149",
3
+ "version": "0.0.150",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -728,7 +728,7 @@
728
728
  "puppeteer": "^19.7.2",
729
729
  "redis": "^4.6.6",
730
730
  "release-it": "^15.10.1",
731
- "replicate": "^0.12.3",
731
+ "replicate": "^0.18.0",
732
732
  "rimraf": "^5.0.1",
733
733
  "rollup": "^3.19.1",
734
734
  "sonix-speech-recognition": "^2.1.1",
@@ -815,7 +815,7 @@
815
815
  "playwright": "^1.32.1",
816
816
  "puppeteer": "^19.7.2",
817
817
  "redis": "^4.6.4",
818
- "replicate": "^0.12.3",
818
+ "replicate": "^0.18.0",
819
819
  "sonix-speech-recognition": "^2.1.1",
820
820
  "srt-parser-2": "^1.2.2",
821
821
  "typeorm": "^0.3.12",