langchain 0.0.141 → 0.0.142
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.
- package/dist/prompts/chat.cjs +21 -9
- package/dist/prompts/chat.d.ts +3 -3
- package/dist/prompts/chat.js +22 -10
- package/dist/schema/runnable.cjs +3 -0
- package/dist/schema/runnable.d.ts +1 -0
- package/dist/schema/runnable.js +3 -0
- package/package.json +1 -1
package/dist/prompts/chat.cjs
CHANGED
|
@@ -265,6 +265,9 @@ class ChatPromptTemplate extends BaseChatPromptTemplate {
|
|
|
265
265
|
if (this.validateTemplate) {
|
|
266
266
|
const inputVariablesMessages = new Set();
|
|
267
267
|
for (const promptMessage of this.promptMessages) {
|
|
268
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
269
|
+
if (promptMessage instanceof index_js_1.BaseMessage)
|
|
270
|
+
continue;
|
|
268
271
|
for (const inputVariable of promptMessage.inputVariables) {
|
|
269
272
|
inputVariablesMessages.add(inputVariable);
|
|
270
273
|
}
|
|
@@ -294,15 +297,21 @@ class ChatPromptTemplate extends BaseChatPromptTemplate {
|
|
|
294
297
|
const allValues = await this.mergePartialAndUserVariables(values);
|
|
295
298
|
let resultMessages = [];
|
|
296
299
|
for (const promptMessage of this.promptMessages) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
300
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
301
|
+
if (promptMessage instanceof index_js_1.BaseMessage) {
|
|
302
|
+
resultMessages.push(promptMessage);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
const inputValues = promptMessage.inputVariables.reduce((acc, inputVariable) => {
|
|
306
|
+
if (!(inputVariable in allValues)) {
|
|
307
|
+
throw new Error(`Missing value for input variable \`${inputVariable.toString()}\``);
|
|
308
|
+
}
|
|
309
|
+
acc[inputVariable] = allValues[inputVariable];
|
|
310
|
+
return acc;
|
|
311
|
+
}, {});
|
|
312
|
+
const message = await promptMessage.formatMessages(inputValues);
|
|
313
|
+
resultMessages = resultMessages.concat(message);
|
|
314
|
+
}
|
|
306
315
|
}
|
|
307
316
|
return resultMessages;
|
|
308
317
|
}
|
|
@@ -335,6 +344,9 @@ class ChatPromptTemplate extends BaseChatPromptTemplate {
|
|
|
335
344
|
: acc, Object.create(null));
|
|
336
345
|
const inputVariables = new Set();
|
|
337
346
|
for (const promptMessage of flattenedMessages) {
|
|
347
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
348
|
+
if (promptMessage instanceof index_js_1.BaseMessage)
|
|
349
|
+
continue;
|
|
338
350
|
for (const inputVariable of promptMessage.inputVariables) {
|
|
339
351
|
if (inputVariable in flattenedPartialVariables) {
|
|
340
352
|
continue;
|
package/dist/prompts/chat.d.ts
CHANGED
|
@@ -144,7 +144,7 @@ export interface ChatPromptTemplateInput<RunInput extends InputValues = any, Par
|
|
|
144
144
|
/**
|
|
145
145
|
* The prompt messages
|
|
146
146
|
*/
|
|
147
|
-
promptMessages: BaseMessagePromptTemplate
|
|
147
|
+
promptMessages: Array<BaseMessagePromptTemplate | BaseMessage>;
|
|
148
148
|
/**
|
|
149
149
|
* Whether to try validating the template on initialization
|
|
150
150
|
*
|
|
@@ -162,11 +162,11 @@ export declare class ChatPromptTemplate<RunInput extends InputValues = any, Part
|
|
|
162
162
|
get lc_aliases(): {
|
|
163
163
|
promptMessages: string;
|
|
164
164
|
};
|
|
165
|
-
promptMessages: BaseMessagePromptTemplate
|
|
165
|
+
promptMessages: Array<BaseMessagePromptTemplate | BaseMessage>;
|
|
166
166
|
validateTemplate: boolean;
|
|
167
167
|
constructor(input: ChatPromptTemplateInput<RunInput, PartialVariableName>);
|
|
168
168
|
_getPromptType(): "chat";
|
|
169
169
|
formatMessages(values: TypedPromptInputValues<RunInput>): Promise<BaseMessage[]>;
|
|
170
170
|
partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<ChatPromptTemplate<InputValues<Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>>, any>>;
|
|
171
|
-
static fromPromptMessages<RunInput extends InputValues = any>(promptMessages: (BaseMessagePromptTemplate<InputValues> | ChatPromptTemplate<InputValues, string>)[]): ChatPromptTemplate<RunInput>;
|
|
171
|
+
static fromPromptMessages<RunInput extends InputValues = any>(promptMessages: (BaseMessagePromptTemplate<InputValues> | ChatPromptTemplate<InputValues, string> | BaseMessage)[]): ChatPromptTemplate<RunInput>;
|
|
172
172
|
}
|
package/dist/prompts/chat.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Default generic "any" values are for backwards compatibility.
|
|
2
2
|
// Replace with "string" when we are comfortable with a breaking change.
|
|
3
|
-
import { AIMessage, BasePromptValue, ChatMessage, HumanMessage, SystemMessage, } from "../schema/index.js";
|
|
3
|
+
import { AIMessage, BaseMessage, BasePromptValue, ChatMessage, HumanMessage, SystemMessage, } from "../schema/index.js";
|
|
4
4
|
import { Runnable } from "../schema/runnable.js";
|
|
5
5
|
import { BasePromptTemplate, } from "./base.js";
|
|
6
6
|
import { PromptTemplate } from "./prompt.js";
|
|
@@ -253,6 +253,9 @@ export class ChatPromptTemplate extends BaseChatPromptTemplate {
|
|
|
253
253
|
if (this.validateTemplate) {
|
|
254
254
|
const inputVariablesMessages = new Set();
|
|
255
255
|
for (const promptMessage of this.promptMessages) {
|
|
256
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
257
|
+
if (promptMessage instanceof BaseMessage)
|
|
258
|
+
continue;
|
|
256
259
|
for (const inputVariable of promptMessage.inputVariables) {
|
|
257
260
|
inputVariablesMessages.add(inputVariable);
|
|
258
261
|
}
|
|
@@ -282,15 +285,21 @@ export class ChatPromptTemplate extends BaseChatPromptTemplate {
|
|
|
282
285
|
const allValues = await this.mergePartialAndUserVariables(values);
|
|
283
286
|
let resultMessages = [];
|
|
284
287
|
for (const promptMessage of this.promptMessages) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
288
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
289
|
+
if (promptMessage instanceof BaseMessage) {
|
|
290
|
+
resultMessages.push(promptMessage);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
const inputValues = promptMessage.inputVariables.reduce((acc, inputVariable) => {
|
|
294
|
+
if (!(inputVariable in allValues)) {
|
|
295
|
+
throw new Error(`Missing value for input variable \`${inputVariable.toString()}\``);
|
|
296
|
+
}
|
|
297
|
+
acc[inputVariable] = allValues[inputVariable];
|
|
298
|
+
return acc;
|
|
299
|
+
}, {});
|
|
300
|
+
const message = await promptMessage.formatMessages(inputValues);
|
|
301
|
+
resultMessages = resultMessages.concat(message);
|
|
302
|
+
}
|
|
294
303
|
}
|
|
295
304
|
return resultMessages;
|
|
296
305
|
}
|
|
@@ -323,6 +332,9 @@ export class ChatPromptTemplate extends BaseChatPromptTemplate {
|
|
|
323
332
|
: acc, Object.create(null));
|
|
324
333
|
const inputVariables = new Set();
|
|
325
334
|
for (const promptMessage of flattenedMessages) {
|
|
335
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
336
|
+
if (promptMessage instanceof BaseMessage)
|
|
337
|
+
continue;
|
|
326
338
|
for (const inputVariable of promptMessage.inputVariables) {
|
|
327
339
|
if (inputVariable in flattenedPartialVariables) {
|
|
328
340
|
continue;
|
package/dist/schema/runnable.cjs
CHANGED
|
@@ -552,6 +552,9 @@ class RunnableBinding extends Runnable {
|
|
|
552
552
|
: { ...options, ...this.kwargs };
|
|
553
553
|
return this.bound.batch(inputs, mergedOptions, batchOptions);
|
|
554
554
|
}
|
|
555
|
+
async *_streamIterator(input, options) {
|
|
556
|
+
yield* this.bound._streamIterator(input, { ...options, ...this.kwargs });
|
|
557
|
+
}
|
|
555
558
|
async stream(input, options) {
|
|
556
559
|
return this.bound.stream(input, { ...options, ...this.kwargs });
|
|
557
560
|
}
|
|
@@ -166,6 +166,7 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ba
|
|
|
166
166
|
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: {
|
|
167
167
|
maxConcurrency?: number;
|
|
168
168
|
}): Promise<RunOutput[]>;
|
|
169
|
+
_streamIterator(input: RunInput, options?: Partial<CallOptions> | undefined): AsyncGenerator<Awaited<RunOutput>, void, unknown>;
|
|
169
170
|
stream(input: RunInput, options?: Partial<CallOptions> | undefined): Promise<IterableReadableStream<RunOutput>>;
|
|
170
171
|
}
|
|
171
172
|
export type RouterInput = {
|
package/dist/schema/runnable.js
CHANGED
|
@@ -544,6 +544,9 @@ export class RunnableBinding extends Runnable {
|
|
|
544
544
|
: { ...options, ...this.kwargs };
|
|
545
545
|
return this.bound.batch(inputs, mergedOptions, batchOptions);
|
|
546
546
|
}
|
|
547
|
+
async *_streamIterator(input, options) {
|
|
548
|
+
yield* this.bound._streamIterator(input, { ...options, ...this.kwargs });
|
|
549
|
+
}
|
|
547
550
|
async stream(input, options) {
|
|
548
551
|
return this.bound.stream(input, { ...options, ...this.kwargs });
|
|
549
552
|
}
|