langchain 0.0.176 → 0.0.178

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 (84) hide show
  1. package/chat_models/iflytek_xinghuo/web.cjs +1 -0
  2. package/chat_models/iflytek_xinghuo/web.d.ts +1 -0
  3. package/chat_models/iflytek_xinghuo/web.js +1 -0
  4. package/chat_models/iflytek_xinghuo.cjs +1 -0
  5. package/chat_models/iflytek_xinghuo.d.ts +1 -0
  6. package/chat_models/iflytek_xinghuo.js +1 -0
  7. package/dist/chat_models/bedrock.cjs +25 -4
  8. package/dist/chat_models/bedrock.d.ts +2 -1
  9. package/dist/chat_models/bedrock.js +25 -4
  10. package/dist/chat_models/cloudflare_workersai.cjs +70 -24
  11. package/dist/chat_models/cloudflare_workersai.d.ts +6 -2
  12. package/dist/chat_models/cloudflare_workersai.js +71 -25
  13. package/dist/chat_models/iflytek_xinghuo/common.cjs +335 -0
  14. package/dist/chat_models/iflytek_xinghuo/common.d.ts +165 -0
  15. package/dist/chat_models/iflytek_xinghuo/common.js +331 -0
  16. package/dist/chat_models/iflytek_xinghuo/index.cjs +35 -0
  17. package/dist/chat_models/iflytek_xinghuo/index.d.ts +5 -0
  18. package/dist/chat_models/iflytek_xinghuo/index.js +28 -0
  19. package/dist/chat_models/iflytek_xinghuo/web.cjs +30 -0
  20. package/dist/chat_models/iflytek_xinghuo/web.d.ts +5 -0
  21. package/dist/chat_models/iflytek_xinghuo/web.js +26 -0
  22. package/dist/chat_models/llama_cpp.cjs +31 -79
  23. package/dist/chat_models/llama_cpp.d.ts +15 -58
  24. package/dist/chat_models/llama_cpp.js +32 -80
  25. package/dist/chat_models/openai.cjs +91 -6
  26. package/dist/chat_models/openai.d.ts +10 -0
  27. package/dist/chat_models/openai.js +91 -6
  28. package/dist/embeddings/hf.cjs +10 -1
  29. package/dist/embeddings/hf.d.ts +4 -2
  30. package/dist/embeddings/hf.js +10 -1
  31. package/dist/embeddings/llama_cpp.cjs +67 -0
  32. package/dist/embeddings/llama_cpp.d.ts +26 -0
  33. package/dist/embeddings/llama_cpp.js +63 -0
  34. package/dist/embeddings/ollama.cjs +7 -1
  35. package/dist/embeddings/ollama.js +7 -1
  36. package/dist/graphs/neo4j_graph.cjs +36 -5
  37. package/dist/graphs/neo4j_graph.js +14 -3
  38. package/dist/llms/bedrock.cjs +25 -3
  39. package/dist/llms/bedrock.d.ts +2 -1
  40. package/dist/llms/bedrock.js +25 -3
  41. package/dist/llms/cloudflare_workersai.cjs +59 -13
  42. package/dist/llms/cloudflare_workersai.d.ts +9 -3
  43. package/dist/llms/cloudflare_workersai.js +59 -13
  44. package/dist/llms/hf.cjs +10 -1
  45. package/dist/llms/hf.d.ts +3 -0
  46. package/dist/llms/hf.js +10 -1
  47. package/dist/llms/llama_cpp.cjs +25 -65
  48. package/dist/llms/llama_cpp.d.ts +7 -43
  49. package/dist/llms/llama_cpp.js +25 -65
  50. package/dist/load/import_constants.cjs +3 -0
  51. package/dist/load/import_constants.js +3 -0
  52. package/dist/prompts/chat.cjs +8 -0
  53. package/dist/prompts/chat.d.ts +5 -0
  54. package/dist/prompts/chat.js +8 -0
  55. package/dist/prompts/few_shot.cjs +162 -1
  56. package/dist/prompts/few_shot.d.ts +90 -2
  57. package/dist/prompts/few_shot.js +160 -0
  58. package/dist/prompts/index.cjs +2 -1
  59. package/dist/prompts/index.d.ts +1 -1
  60. package/dist/prompts/index.js +1 -1
  61. package/dist/retrievers/zep.cjs +26 -3
  62. package/dist/retrievers/zep.d.ts +11 -2
  63. package/dist/retrievers/zep.js +26 -3
  64. package/dist/util/bedrock.d.ts +2 -0
  65. package/dist/util/event-source-parse.cjs +20 -1
  66. package/dist/util/event-source-parse.d.ts +2 -0
  67. package/dist/util/event-source-parse.js +18 -0
  68. package/dist/util/iflytek_websocket_stream.cjs +81 -0
  69. package/dist/util/iflytek_websocket_stream.d.ts +27 -0
  70. package/dist/util/iflytek_websocket_stream.js +77 -0
  71. package/dist/util/llama_cpp.cjs +34 -0
  72. package/dist/util/llama_cpp.d.ts +46 -0
  73. package/dist/util/llama_cpp.js +28 -0
  74. package/dist/util/openai-format-fndef.cjs +81 -0
  75. package/dist/util/openai-format-fndef.d.ts +44 -0
  76. package/dist/util/openai-format-fndef.js +77 -0
  77. package/dist/util/openapi.d.ts +2 -2
  78. package/dist/vectorstores/pinecone.cjs +5 -5
  79. package/dist/vectorstores/pinecone.d.ts +2 -2
  80. package/dist/vectorstores/pinecone.js +5 -5
  81. package/embeddings/llama_cpp.cjs +1 -0
  82. package/embeddings/llama_cpp.d.ts +1 -0
  83. package/embeddings/llama_cpp.js +1 -0
  84. package/package.json +34 -5
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FewShotPromptTemplate = void 0;
3
+ exports.FewShotChatMessagePromptTemplate = exports.FewShotPromptTemplate = void 0;
4
4
  const base_js_1 = require("./base.cjs");
5
5
  const template_js_1 = require("./template.cjs");
6
6
  const prompt_js_1 = require("./prompt.cjs");
7
+ const chat_js_1 = require("./chat.cjs");
7
8
  /**
8
9
  * Prompt template that contains few-shot examples.
9
10
  * @augments BasePromptTemplate
@@ -84,6 +85,9 @@ class FewShotPromptTemplate extends base_js_1.BaseStringPromptTemplate {
84
85
  _getPromptType() {
85
86
  return "few_shot";
86
87
  }
88
+ static lc_name() {
89
+ return "FewShotPromptTemplate";
90
+ }
87
91
  async getExamples(inputVariables) {
88
92
  if (this.examples !== undefined) {
89
93
  return this.examples;
@@ -161,3 +165,160 @@ class FewShotPromptTemplate extends base_js_1.BaseStringPromptTemplate {
161
165
  }
162
166
  }
163
167
  exports.FewShotPromptTemplate = FewShotPromptTemplate;
168
+ /**
169
+ * Chat prompt template that contains few-shot examples.
170
+ * @augments BasePromptTemplateInput
171
+ * @augments FewShotChatMessagePromptTemplateInput
172
+ */
173
+ class FewShotChatMessagePromptTemplate extends chat_js_1.BaseChatPromptTemplate {
174
+ _getPromptType() {
175
+ return "few_shot_chat";
176
+ }
177
+ static lc_name() {
178
+ return "FewShotChatMessagePromptTemplate";
179
+ }
180
+ constructor(fields) {
181
+ super(fields);
182
+ Object.defineProperty(this, "lc_serializable", {
183
+ enumerable: true,
184
+ configurable: true,
185
+ writable: true,
186
+ value: true
187
+ });
188
+ Object.defineProperty(this, "examples", {
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true,
192
+ value: void 0
193
+ });
194
+ Object.defineProperty(this, "exampleSelector", {
195
+ enumerable: true,
196
+ configurable: true,
197
+ writable: true,
198
+ value: void 0
199
+ });
200
+ Object.defineProperty(this, "examplePrompt", {
201
+ enumerable: true,
202
+ configurable: true,
203
+ writable: true,
204
+ value: void 0
205
+ });
206
+ Object.defineProperty(this, "suffix", {
207
+ enumerable: true,
208
+ configurable: true,
209
+ writable: true,
210
+ value: ""
211
+ });
212
+ Object.defineProperty(this, "exampleSeparator", {
213
+ enumerable: true,
214
+ configurable: true,
215
+ writable: true,
216
+ value: "\n\n"
217
+ });
218
+ Object.defineProperty(this, "prefix", {
219
+ enumerable: true,
220
+ configurable: true,
221
+ writable: true,
222
+ value: ""
223
+ });
224
+ Object.defineProperty(this, "templateFormat", {
225
+ enumerable: true,
226
+ configurable: true,
227
+ writable: true,
228
+ value: "f-string"
229
+ });
230
+ Object.defineProperty(this, "validateTemplate", {
231
+ enumerable: true,
232
+ configurable: true,
233
+ writable: true,
234
+ value: true
235
+ });
236
+ this.examples = fields.examples;
237
+ this.examplePrompt = fields.examplePrompt;
238
+ this.exampleSeparator = fields.exampleSeparator ?? "\n\n";
239
+ this.exampleSelector = fields.exampleSelector;
240
+ this.prefix = fields.prefix ?? "";
241
+ this.suffix = fields.suffix ?? "";
242
+ this.templateFormat = fields.templateFormat ?? "f-string";
243
+ this.validateTemplate = fields.validateTemplate ?? true;
244
+ if (this.examples !== undefined && this.exampleSelector !== undefined) {
245
+ throw new Error("Only one of 'examples' and 'example_selector' should be provided");
246
+ }
247
+ if (this.examples === undefined && this.exampleSelector === undefined) {
248
+ throw new Error("One of 'examples' and 'example_selector' should be provided");
249
+ }
250
+ if (this.validateTemplate) {
251
+ let totalInputVariables = this.inputVariables;
252
+ if (this.partialVariables) {
253
+ totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
254
+ }
255
+ (0, template_js_1.checkValidTemplate)(this.prefix + this.suffix, this.templateFormat, totalInputVariables);
256
+ }
257
+ }
258
+ async getExamples(inputVariables) {
259
+ if (this.examples !== undefined) {
260
+ return this.examples;
261
+ }
262
+ if (this.exampleSelector !== undefined) {
263
+ return this.exampleSelector.selectExamples(inputVariables);
264
+ }
265
+ throw new Error("One of 'examples' and 'example_selector' should be provided");
266
+ }
267
+ /**
268
+ * Formats the list of values and returns a list of formatted messages.
269
+ * @param values The values to format the prompt with.
270
+ * @returns A promise that resolves to a string representing the formatted prompt.
271
+ */
272
+ async formatMessages(values) {
273
+ const allValues = await this.mergePartialAndUserVariables(values);
274
+ let examples = await this.getExamples(allValues);
275
+ examples = examples.map((example) => {
276
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
277
+ const result = {};
278
+ this.examplePrompt.inputVariables.forEach((inputVariable) => {
279
+ result[inputVariable] = example[inputVariable];
280
+ });
281
+ return result;
282
+ });
283
+ const messages = [];
284
+ for (const example of examples) {
285
+ const exampleMessages = await this.examplePrompt.formatMessages(example);
286
+ messages.push(...exampleMessages);
287
+ }
288
+ return messages;
289
+ }
290
+ /**
291
+ * Formats the prompt with the given values.
292
+ * @param values The values to format the prompt with.
293
+ * @returns A promise that resolves to a string representing the formatted prompt.
294
+ */
295
+ async format(values) {
296
+ const allValues = await this.mergePartialAndUserVariables(values);
297
+ const examples = await this.getExamples(allValues);
298
+ const exampleMessages = await Promise.all(examples.map((example) => this.examplePrompt.formatMessages(example)));
299
+ const exampleStrings = exampleMessages
300
+ .flat()
301
+ .map((message) => message.content);
302
+ const template = [this.prefix, ...exampleStrings, this.suffix].join(this.exampleSeparator);
303
+ return (0, template_js_1.renderTemplate)(template, this.templateFormat, allValues);
304
+ }
305
+ /**
306
+ * Partially formats the prompt with the given values.
307
+ * @param values The values to partially format the prompt with.
308
+ * @returns A promise that resolves to an instance of `FewShotChatMessagePromptTemplate` with the given values partially formatted.
309
+ */
310
+ async partial(values) {
311
+ const newInputVariables = this.inputVariables.filter((variable) => !(variable in values));
312
+ const newPartialVariables = {
313
+ ...(this.partialVariables ?? {}),
314
+ ...values,
315
+ };
316
+ const promptDict = {
317
+ ...this,
318
+ inputVariables: newInputVariables,
319
+ partialVariables: newPartialVariables,
320
+ };
321
+ return new FewShotChatMessagePromptTemplate(promptDict);
322
+ }
323
+ }
324
+ exports.FewShotChatMessagePromptTemplate = FewShotChatMessagePromptTemplate;
@@ -1,8 +1,9 @@
1
- import { BaseStringPromptTemplate, BasePromptTemplateInput, BaseExampleSelector } from "./base.js";
1
+ import { BaseStringPromptTemplate, BasePromptTemplateInput, BaseExampleSelector, TypedPromptInputValues } from "./base.js";
2
2
  import { TemplateFormat } from "./template.js";
3
3
  import { PromptTemplate } from "./prompt.js";
4
4
  import { SerializedFewShotTemplate } from "./serde.js";
5
- import { Example, InputValues, PartialValues } from "../schema/index.js";
5
+ import { BaseMessage, Example, InputValues, PartialValues } from "../schema/index.js";
6
+ import { BaseChatPromptTemplate, BaseMessagePromptTemplate } from "./chat.js";
6
7
  export interface FewShotPromptTemplateInput extends BasePromptTemplateInput<InputValues> {
7
8
  /**
8
9
  * Examples to format into the prompt. Exactly one of this or
@@ -60,6 +61,7 @@ export declare class FewShotPromptTemplate extends BaseStringPromptTemplate impl
60
61
  validateTemplate: boolean;
61
62
  constructor(input: FewShotPromptTemplateInput);
62
63
  _getPromptType(): "few_shot";
64
+ static lc_name(): string;
63
65
  private getExamples;
64
66
  partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<FewShotPromptTemplate>;
65
67
  /**
@@ -71,3 +73,89 @@ export declare class FewShotPromptTemplate extends BaseStringPromptTemplate impl
71
73
  serialize(): SerializedFewShotTemplate;
72
74
  static deserialize(data: SerializedFewShotTemplate): Promise<FewShotPromptTemplate>;
73
75
  }
76
+ export interface FewShotChatMessagePromptTemplateInput extends BasePromptTemplateInput<InputValues> {
77
+ /**
78
+ * Examples to format into the prompt. Exactly one of this or
79
+ * {@link exampleSelector} must be
80
+ * provided.
81
+ */
82
+ examples?: Example[];
83
+ /**
84
+ * An {@link BaseMessagePromptTemplate} | {@link BaseChatPromptTemplate} used to format a single example.
85
+ */
86
+ examplePrompt: BaseMessagePromptTemplate | BaseChatPromptTemplate;
87
+ /**
88
+ * String separator used to join the prefix, the examples, and suffix.
89
+ *
90
+ * @defaultValue `"\n\n"`
91
+ */
92
+ exampleSeparator?: string;
93
+ /**
94
+ * An {@link BaseExampleSelector} Examples to format into the prompt. Exactly one of this or
95
+ * {@link examples} must be
96
+ * provided.
97
+ */
98
+ exampleSelector?: BaseExampleSelector | undefined;
99
+ /**
100
+ * A prompt template string to put before the examples.
101
+ *
102
+ * @defaultValue `""`
103
+ */
104
+ prefix?: string;
105
+ /**
106
+ * A prompt template string to put after the examples.
107
+ *
108
+ * @defaultValue `""`
109
+ */
110
+ suffix?: string;
111
+ /**
112
+ * The format of the prompt template. Options are: 'f-string'
113
+ *
114
+ * @defaultValue `f-string`
115
+ */
116
+ templateFormat?: TemplateFormat;
117
+ /**
118
+ * Whether or not to try validating the template on initialization.
119
+ *
120
+ * @defaultValue `true`
121
+ */
122
+ validateTemplate?: boolean;
123
+ }
124
+ /**
125
+ * Chat prompt template that contains few-shot examples.
126
+ * @augments BasePromptTemplateInput
127
+ * @augments FewShotChatMessagePromptTemplateInput
128
+ */
129
+ export declare class FewShotChatMessagePromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends BaseChatPromptTemplate implements FewShotChatMessagePromptTemplateInput {
130
+ lc_serializable: boolean;
131
+ examples?: InputValues[];
132
+ exampleSelector?: BaseExampleSelector | undefined;
133
+ examplePrompt: BaseMessagePromptTemplate | BaseChatPromptTemplate;
134
+ suffix: string;
135
+ exampleSeparator: string;
136
+ prefix: string;
137
+ templateFormat: TemplateFormat;
138
+ validateTemplate: boolean;
139
+ _getPromptType(): "few_shot_chat";
140
+ static lc_name(): string;
141
+ constructor(fields: FewShotChatMessagePromptTemplateInput);
142
+ private getExamples;
143
+ /**
144
+ * Formats the list of values and returns a list of formatted messages.
145
+ * @param values The values to format the prompt with.
146
+ * @returns A promise that resolves to a string representing the formatted prompt.
147
+ */
148
+ formatMessages(values: TypedPromptInputValues<RunInput>): Promise<BaseMessage[]>;
149
+ /**
150
+ * Formats the prompt with the given values.
151
+ * @param values The values to format the prompt with.
152
+ * @returns A promise that resolves to a string representing the formatted prompt.
153
+ */
154
+ format(values: TypedPromptInputValues<RunInput>): Promise<string>;
155
+ /**
156
+ * Partially formats the prompt with the given values.
157
+ * @param values The values to partially format the prompt with.
158
+ * @returns A promise that resolves to an instance of `FewShotChatMessagePromptTemplate` with the given values partially formatted.
159
+ */
160
+ partial(values: PartialValues<PartialVariableName>): Promise<FewShotChatMessagePromptTemplate<RunInput, PartialVariableName>>;
161
+ }
@@ -1,6 +1,7 @@
1
1
  import { BaseStringPromptTemplate, } from "./base.js";
2
2
  import { checkValidTemplate, renderTemplate, } from "./template.js";
3
3
  import { PromptTemplate } from "./prompt.js";
4
+ import { BaseChatPromptTemplate } from "./chat.js";
4
5
  /**
5
6
  * Prompt template that contains few-shot examples.
6
7
  * @augments BasePromptTemplate
@@ -81,6 +82,9 @@ export class FewShotPromptTemplate extends BaseStringPromptTemplate {
81
82
  _getPromptType() {
82
83
  return "few_shot";
83
84
  }
85
+ static lc_name() {
86
+ return "FewShotPromptTemplate";
87
+ }
84
88
  async getExamples(inputVariables) {
85
89
  if (this.examples !== undefined) {
86
90
  return this.examples;
@@ -157,3 +161,159 @@ export class FewShotPromptTemplate extends BaseStringPromptTemplate {
157
161
  });
158
162
  }
159
163
  }
164
+ /**
165
+ * Chat prompt template that contains few-shot examples.
166
+ * @augments BasePromptTemplateInput
167
+ * @augments FewShotChatMessagePromptTemplateInput
168
+ */
169
+ export class FewShotChatMessagePromptTemplate extends BaseChatPromptTemplate {
170
+ _getPromptType() {
171
+ return "few_shot_chat";
172
+ }
173
+ static lc_name() {
174
+ return "FewShotChatMessagePromptTemplate";
175
+ }
176
+ constructor(fields) {
177
+ super(fields);
178
+ Object.defineProperty(this, "lc_serializable", {
179
+ enumerable: true,
180
+ configurable: true,
181
+ writable: true,
182
+ value: true
183
+ });
184
+ Object.defineProperty(this, "examples", {
185
+ enumerable: true,
186
+ configurable: true,
187
+ writable: true,
188
+ value: void 0
189
+ });
190
+ Object.defineProperty(this, "exampleSelector", {
191
+ enumerable: true,
192
+ configurable: true,
193
+ writable: true,
194
+ value: void 0
195
+ });
196
+ Object.defineProperty(this, "examplePrompt", {
197
+ enumerable: true,
198
+ configurable: true,
199
+ writable: true,
200
+ value: void 0
201
+ });
202
+ Object.defineProperty(this, "suffix", {
203
+ enumerable: true,
204
+ configurable: true,
205
+ writable: true,
206
+ value: ""
207
+ });
208
+ Object.defineProperty(this, "exampleSeparator", {
209
+ enumerable: true,
210
+ configurable: true,
211
+ writable: true,
212
+ value: "\n\n"
213
+ });
214
+ Object.defineProperty(this, "prefix", {
215
+ enumerable: true,
216
+ configurable: true,
217
+ writable: true,
218
+ value: ""
219
+ });
220
+ Object.defineProperty(this, "templateFormat", {
221
+ enumerable: true,
222
+ configurable: true,
223
+ writable: true,
224
+ value: "f-string"
225
+ });
226
+ Object.defineProperty(this, "validateTemplate", {
227
+ enumerable: true,
228
+ configurable: true,
229
+ writable: true,
230
+ value: true
231
+ });
232
+ this.examples = fields.examples;
233
+ this.examplePrompt = fields.examplePrompt;
234
+ this.exampleSeparator = fields.exampleSeparator ?? "\n\n";
235
+ this.exampleSelector = fields.exampleSelector;
236
+ this.prefix = fields.prefix ?? "";
237
+ this.suffix = fields.suffix ?? "";
238
+ this.templateFormat = fields.templateFormat ?? "f-string";
239
+ this.validateTemplate = fields.validateTemplate ?? true;
240
+ if (this.examples !== undefined && this.exampleSelector !== undefined) {
241
+ throw new Error("Only one of 'examples' and 'example_selector' should be provided");
242
+ }
243
+ if (this.examples === undefined && this.exampleSelector === undefined) {
244
+ throw new Error("One of 'examples' and 'example_selector' should be provided");
245
+ }
246
+ if (this.validateTemplate) {
247
+ let totalInputVariables = this.inputVariables;
248
+ if (this.partialVariables) {
249
+ totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
250
+ }
251
+ checkValidTemplate(this.prefix + this.suffix, this.templateFormat, totalInputVariables);
252
+ }
253
+ }
254
+ async getExamples(inputVariables) {
255
+ if (this.examples !== undefined) {
256
+ return this.examples;
257
+ }
258
+ if (this.exampleSelector !== undefined) {
259
+ return this.exampleSelector.selectExamples(inputVariables);
260
+ }
261
+ throw new Error("One of 'examples' and 'example_selector' should be provided");
262
+ }
263
+ /**
264
+ * Formats the list of values and returns a list of formatted messages.
265
+ * @param values The values to format the prompt with.
266
+ * @returns A promise that resolves to a string representing the formatted prompt.
267
+ */
268
+ async formatMessages(values) {
269
+ const allValues = await this.mergePartialAndUserVariables(values);
270
+ let examples = await this.getExamples(allValues);
271
+ examples = examples.map((example) => {
272
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
273
+ const result = {};
274
+ this.examplePrompt.inputVariables.forEach((inputVariable) => {
275
+ result[inputVariable] = example[inputVariable];
276
+ });
277
+ return result;
278
+ });
279
+ const messages = [];
280
+ for (const example of examples) {
281
+ const exampleMessages = await this.examplePrompt.formatMessages(example);
282
+ messages.push(...exampleMessages);
283
+ }
284
+ return messages;
285
+ }
286
+ /**
287
+ * Formats the prompt with the given values.
288
+ * @param values The values to format the prompt with.
289
+ * @returns A promise that resolves to a string representing the formatted prompt.
290
+ */
291
+ async format(values) {
292
+ const allValues = await this.mergePartialAndUserVariables(values);
293
+ const examples = await this.getExamples(allValues);
294
+ const exampleMessages = await Promise.all(examples.map((example) => this.examplePrompt.formatMessages(example)));
295
+ const exampleStrings = exampleMessages
296
+ .flat()
297
+ .map((message) => message.content);
298
+ const template = [this.prefix, ...exampleStrings, this.suffix].join(this.exampleSeparator);
299
+ return renderTemplate(template, this.templateFormat, allValues);
300
+ }
301
+ /**
302
+ * Partially formats the prompt with the given values.
303
+ * @param values The values to partially format the prompt with.
304
+ * @returns A promise that resolves to an instance of `FewShotChatMessagePromptTemplate` with the given values partially formatted.
305
+ */
306
+ async partial(values) {
307
+ const newInputVariables = this.inputVariables.filter((variable) => !(variable in values));
308
+ const newPartialVariables = {
309
+ ...(this.partialVariables ?? {}),
310
+ ...values,
311
+ };
312
+ const promptDict = {
313
+ ...this,
314
+ inputVariables: newInputVariables,
315
+ partialVariables: newPartialVariables,
316
+ };
317
+ return new FewShotChatMessagePromptTemplate(promptDict);
318
+ }
319
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PipelinePromptTemplate = exports.checkValidTemplate = exports.renderTemplate = exports.parseTemplate = exports.BaseChatPromptTemplate = exports.MessagesPlaceholder = exports.ChatMessagePromptTemplate = exports.SystemMessagePromptTemplate = exports.AIMessagePromptTemplate = exports.HumanMessagePromptTemplate = exports.ChatPromptTemplate = exports.FewShotPromptTemplate = exports.SemanticSimilarityExampleSelector = exports.LengthBasedExampleSelector = exports.isLLM = exports.isChatModel = exports.ConditionalPromptSelector = exports.BasePromptSelector = exports.PromptTemplate = exports.BaseStringPromptTemplate = exports.StringPromptValue = exports.BasePromptTemplate = exports.BaseExampleSelector = void 0;
3
+ exports.PipelinePromptTemplate = exports.checkValidTemplate = exports.renderTemplate = exports.parseTemplate = exports.BaseChatPromptTemplate = exports.MessagesPlaceholder = exports.ChatMessagePromptTemplate = exports.SystemMessagePromptTemplate = exports.AIMessagePromptTemplate = exports.HumanMessagePromptTemplate = exports.ChatPromptTemplate = exports.FewShotChatMessagePromptTemplate = exports.FewShotPromptTemplate = exports.SemanticSimilarityExampleSelector = exports.LengthBasedExampleSelector = exports.isLLM = exports.isChatModel = exports.ConditionalPromptSelector = exports.BasePromptSelector = exports.PromptTemplate = exports.BaseStringPromptTemplate = exports.StringPromptValue = exports.BasePromptTemplate = exports.BaseExampleSelector = void 0;
4
4
  var base_js_1 = require("./base.cjs");
5
5
  Object.defineProperty(exports, "BaseExampleSelector", { enumerable: true, get: function () { return base_js_1.BaseExampleSelector; } });
6
6
  Object.defineProperty(exports, "BasePromptTemplate", { enumerable: true, get: function () { return base_js_1.BasePromptTemplate; } });
@@ -19,6 +19,7 @@ var SemanticSimilarityExampleSelector_js_1 = require("./selectors/SemanticSimila
19
19
  Object.defineProperty(exports, "SemanticSimilarityExampleSelector", { enumerable: true, get: function () { return SemanticSimilarityExampleSelector_js_1.SemanticSimilarityExampleSelector; } });
20
20
  var few_shot_js_1 = require("./few_shot.cjs");
21
21
  Object.defineProperty(exports, "FewShotPromptTemplate", { enumerable: true, get: function () { return few_shot_js_1.FewShotPromptTemplate; } });
22
+ Object.defineProperty(exports, "FewShotChatMessagePromptTemplate", { enumerable: true, get: function () { return few_shot_js_1.FewShotChatMessagePromptTemplate; } });
22
23
  var chat_js_1 = require("./chat.cjs");
23
24
  Object.defineProperty(exports, "ChatPromptTemplate", { enumerable: true, get: function () { return chat_js_1.ChatPromptTemplate; } });
24
25
  Object.defineProperty(exports, "HumanMessagePromptTemplate", { enumerable: true, get: function () { return chat_js_1.HumanMessagePromptTemplate; } });
@@ -3,7 +3,7 @@ export { PromptTemplate, type PromptTemplateInput } from "./prompt.js";
3
3
  export { BasePromptSelector, ConditionalPromptSelector, isChatModel, isLLM, } from "./selectors/conditional.js";
4
4
  export { LengthBasedExampleSelector, type LengthBasedExampleSelectorInput, } from "./selectors/LengthBasedExampleSelector.js";
5
5
  export { SemanticSimilarityExampleSelector, type SemanticSimilarityExampleSelectorInput, } from "./selectors/SemanticSimilarityExampleSelector.js";
6
- export { FewShotPromptTemplate, type FewShotPromptTemplateInput, } from "./few_shot.js";
6
+ export { FewShotPromptTemplate, type FewShotPromptTemplateInput, type FewShotChatMessagePromptTemplateInput, FewShotChatMessagePromptTemplate, } from "./few_shot.js";
7
7
  export { ChatPromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, SystemMessagePromptTemplate, ChatMessagePromptTemplate, MessagesPlaceholder, BaseChatPromptTemplate, } from "./chat.js";
8
8
  export { type SerializedPromptTemplate, type SerializedBasePromptTemplate, type SerializedFewShotTemplate, } from "./serde.js";
9
9
  export { parseTemplate, renderTemplate, checkValidTemplate, type TemplateFormat, } from "./template.js";
@@ -3,7 +3,7 @@ export { PromptTemplate } from "./prompt.js";
3
3
  export { BasePromptSelector, ConditionalPromptSelector, isChatModel, isLLM, } from "./selectors/conditional.js";
4
4
  export { LengthBasedExampleSelector, } from "./selectors/LengthBasedExampleSelector.js";
5
5
  export { SemanticSimilarityExampleSelector, } from "./selectors/SemanticSimilarityExampleSelector.js";
6
- export { FewShotPromptTemplate, } from "./few_shot.js";
6
+ export { FewShotPromptTemplate, FewShotChatMessagePromptTemplate, } from "./few_shot.js";
7
7
  export { ChatPromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, SystemMessagePromptTemplate, ChatMessagePromptTemplate, MessagesPlaceholder, BaseChatPromptTemplate, } from "./chat.js";
8
8
  export { parseTemplate, renderTemplate, checkValidTemplate, } from "./template.js";
9
9
  export { PipelinePromptTemplate, } from "./pipeline.js";
@@ -47,6 +47,12 @@ class ZepRetriever extends retriever_js_1.BaseRetriever {
47
47
  writable: true,
48
48
  value: void 0
49
49
  });
50
+ Object.defineProperty(this, "searchScope", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: void 0
55
+ });
50
56
  Object.defineProperty(this, "searchType", {
51
57
  enumerable: true,
52
58
  configurable: true,
@@ -67,17 +73,18 @@ class ZepRetriever extends retriever_js_1.BaseRetriever {
67
73
  });
68
74
  this.sessionId = config.sessionId;
69
75
  this.topK = config.topK;
76
+ this.searchScope = config.searchScope;
70
77
  this.searchType = config.searchType;
71
78
  this.mmrLambda = config.mmrLambda;
72
79
  this.filter = config.filter;
73
80
  this.zepClientPromise = zep_js_1.ZepClient.init(config.url, config.apiKey);
74
81
  }
75
82
  /**
76
- * Converts an array of search results to an array of Document objects.
83
+ * Converts an array of message search results to an array of Document objects.
77
84
  * @param {MemorySearchResult[]} results - The array of search results.
78
85
  * @returns {Document[]} An array of Document objects representing the search results.
79
86
  */
80
- searchResultToDoc(results) {
87
+ searchMessageResultToDoc(results) {
81
88
  return results
82
89
  .filter((r) => r.message)
83
90
  .map(({ message: { content, metadata: messageMetadata } = {}, dist, ...rest }) => new document_js_1.Document({
@@ -85,6 +92,19 @@ class ZepRetriever extends retriever_js_1.BaseRetriever {
85
92
  metadata: { score: dist, ...messageMetadata, ...rest },
86
93
  }));
87
94
  }
95
+ /**
96
+ * Converts an array of summary search results to an array of Document objects.
97
+ * @param {MemorySearchResult[]} results - The array of search results.
98
+ * @returns {Document[]} An array of Document objects representing the search results.
99
+ */
100
+ searchSummaryResultToDoc(results) {
101
+ return results
102
+ .filter((r) => r.summary)
103
+ .map(({ summary: { content, metadata: summaryMetadata } = {}, dist, ...rest }) => new document_js_1.Document({
104
+ pageContent: content ?? "",
105
+ metadata: { score: dist, ...summaryMetadata, ...rest },
106
+ }));
107
+ }
88
108
  /**
89
109
  * Retrieves the relevant documents based on the given query.
90
110
  * @param {string} query - The query string.
@@ -94,6 +114,7 @@ class ZepRetriever extends retriever_js_1.BaseRetriever {
94
114
  const payload = {
95
115
  text: query,
96
116
  metadata: this.filter,
117
+ search_scope: this.searchScope,
97
118
  search_type: this.searchType,
98
119
  mmr_lambda: this.mmrLambda,
99
120
  };
@@ -104,7 +125,9 @@ class ZepRetriever extends retriever_js_1.BaseRetriever {
104
125
  }
105
126
  try {
106
127
  const results = await zepClient.memory.searchMemory(this.sessionId, payload, this.topK);
107
- return this.searchResultToDoc(results);
128
+ return this.searchScope === "summary"
129
+ ? this.searchSummaryResultToDoc(results)
130
+ : this.searchMessageResultToDoc(results);
108
131
  }
109
132
  catch (error) {
110
133
  // eslint-disable-next-line no-instanceof/no-instanceof
@@ -9,6 +9,7 @@ import { Document } from "../document.js";
9
9
  * @argument {string} url - The URL of the Zep API.
10
10
  * @argument {number} [topK] - The number of results to return.
11
11
  * @argument {string} [apiKey] - The API key for the Zep API.
12
+ * @argument [searchScope] [searchScope] - The scope of the search: "messages" or "summary".
12
13
  * @argument [searchType] [searchType] - The type of search to perform: "similarity" or "mmr".
13
14
  * @argument {number} [mmrLambda] - The lambda value for the MMR search.
14
15
  * @argument {Record<string, unknown>} [filter] - The metadata filter to apply to the search.
@@ -18,6 +19,7 @@ export interface ZepRetrieverConfig extends BaseRetrieverInput {
18
19
  url: string;
19
20
  topK?: number;
20
21
  apiKey?: string;
22
+ searchScope?: "messages" | "summary";
21
23
  searchType?: "similarity" | "mmr";
22
24
  mmrLambda?: number;
23
25
  filter?: Record<string, unknown>;
@@ -38,16 +40,23 @@ export declare class ZepRetriever extends BaseRetriever {
38
40
  zepClientPromise: Promise<ZepClient>;
39
41
  private sessionId;
40
42
  private topK?;
43
+ private searchScope?;
41
44
  private searchType?;
42
45
  private mmrLambda?;
43
46
  private filter?;
44
47
  constructor(config: ZepRetrieverConfig);
45
48
  /**
46
- * Converts an array of search results to an array of Document objects.
49
+ * Converts an array of message search results to an array of Document objects.
47
50
  * @param {MemorySearchResult[]} results - The array of search results.
48
51
  * @returns {Document[]} An array of Document objects representing the search results.
49
52
  */
50
- private searchResultToDoc;
53
+ private searchMessageResultToDoc;
54
+ /**
55
+ * Converts an array of summary search results to an array of Document objects.
56
+ * @param {MemorySearchResult[]} results - The array of search results.
57
+ * @returns {Document[]} An array of Document objects representing the search results.
58
+ */
59
+ private searchSummaryResultToDoc;
51
60
  /**
52
61
  * Retrieves the relevant documents based on the given query.
53
62
  * @param {string} query - The query string.