@langchain/core 0.1.51 → 0.1.53
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/callbacks/base.d.ts +1 -1
- package/dist/callbacks/manager.d.ts +1 -1
- package/dist/example_selectors/conditional.d.ts +1 -1
- package/dist/load/import_map.cjs +2 -2
- package/dist/load/import_map.d.ts +2 -2
- package/dist/load/import_map.js +2 -2
- package/dist/messages/index.d.ts +5 -2
- package/dist/prompts/base.d.ts +1 -1
- package/dist/prompts/chat.cjs +11 -0
- package/dist/prompts/chat.d.ts +1 -1
- package/dist/prompts/chat.js +11 -0
- package/dist/prompts/few_shot.d.ts +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/pipeline.d.ts +1 -1
- package/dist/prompts/prompt.d.ts +1 -1
- package/dist/prompts/string.d.ts +1 -1
- package/dist/prompts/structured.cjs +29 -5
- package/dist/prompts/structured.d.ts +2 -1
- package/dist/prompts/structured.js +29 -5
- package/dist/prompts/template.d.ts +1 -1
- package/dist/retrievers/document_compressors/base.cjs +13 -0
- package/dist/retrievers/document_compressors/base.d.ts +18 -0
- package/dist/retrievers/document_compressors/base.js +9 -0
- package/dist/{retrievers.cjs → retrievers/index.cjs} +3 -3
- package/dist/{retrievers.d.ts → retrievers/index.d.ts} +4 -4
- package/dist/{retrievers.js → retrievers/index.js} +3 -3
- package/dist/runnables/base.d.ts +1 -1
- package/dist/runnables/remote.cjs +120 -79
- package/dist/runnables/remote.d.ts +3 -3
- package/dist/runnables/remote.js +123 -82
- package/dist/tracers/base.d.ts +1 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +1 -1
- package/dist/utils/testing/index.cjs +2 -2
- package/dist/utils/testing/index.d.ts +1 -1
- package/dist/utils/testing/index.js +1 -1
- package/dist/utils/types/index.cjs +17 -0
- package/dist/utils/{types.d.ts → types/index.d.ts} +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/is_zod_schema.cjs +16 -0
- package/dist/utils/types/is_zod_schema.d.ts +8 -0
- package/dist/utils/types/is_zod_schema.js +12 -0
- package/dist/vectorstores.cjs +2 -2
- package/dist/vectorstores.d.ts +1 -1
- package/dist/vectorstores.js +1 -1
- package/package.json +27 -14
- package/retrievers/document_compressors.cjs +1 -0
- package/retrievers/document_compressors.d.cts +1 -0
- package/retrievers/document_compressors.d.ts +1 -0
- package/retrievers/document_compressors.js +1 -0
- package/retrievers.cjs +1 -1
- package/retrievers.d.cts +1 -1
- package/retrievers.d.ts +1 -1
- package/retrievers.js +1 -1
- package/utils/types.cjs +1 -1
- package/utils/types.d.cts +1 -1
- package/utils/types.d.ts +1 -1
- package/utils/types.js +1 -1
- package/dist/utils/types.cjs +0 -5
- package/dist/utils/types.js +0 -4
package/dist/callbacks/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChainValues } from "../utils/types.js";
|
|
1
|
+
import type { ChainValues } from "../utils/types/index.js";
|
|
2
2
|
import type { BaseMessage } from "../messages/index.js";
|
|
3
3
|
import type { AgentAction, AgentFinish } from "../agents.js";
|
|
4
4
|
import type { ChatGenerationChunk, GenerationChunk, LLMResult } from "../outputs.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentAction, AgentFinish } from "../agents.js";
|
|
2
|
-
import type { ChainValues } from "../utils/types.js";
|
|
2
|
+
import type { ChainValues } from "../utils/types/index.js";
|
|
3
3
|
import { LLMResult } from "../outputs.js";
|
|
4
4
|
import { BaseCallbackHandler, CallbackHandlerMethods, HandleLLMNewTokenCallbackFields, NewTokenIndices } from "./base.js";
|
|
5
5
|
import { type BaseMessage } from "../messages/index.js";
|
|
@@ -2,7 +2,7 @@ import type { BaseChatModel } from "../language_models/chat_models.js";
|
|
|
2
2
|
import type { BasePromptTemplate } from "../prompts/base.js";
|
|
3
3
|
import type { BaseLanguageModelInterface } from "../language_models/base.js";
|
|
4
4
|
import type { BaseLLM } from "../language_models/llms.js";
|
|
5
|
-
import type { PartialValues } from "../utils/types.js";
|
|
5
|
+
import type { PartialValues } from "../utils/types/index.js";
|
|
6
6
|
export type BaseGetPromptAsyncOptions = {
|
|
7
7
|
partialVariables?: PartialValues;
|
|
8
8
|
};
|
package/dist/load/import_map.cjs
CHANGED
|
@@ -45,7 +45,7 @@ exports.outputs = __importStar(require("../outputs.cjs"));
|
|
|
45
45
|
exports.prompts = __importStar(require("../prompts/index.cjs"));
|
|
46
46
|
exports.prompt_values = __importStar(require("../prompt_values.cjs"));
|
|
47
47
|
exports.runnables = __importStar(require("../runnables/index.cjs"));
|
|
48
|
-
exports.retrievers = __importStar(require("../retrievers.cjs"));
|
|
48
|
+
exports.retrievers = __importStar(require("../retrievers/index.cjs"));
|
|
49
49
|
exports.stores = __importStar(require("../stores.cjs"));
|
|
50
50
|
exports.tools = __importStar(require("../tools.cjs"));
|
|
51
51
|
exports.tracers__base = __importStar(require("../tracers/base.cjs"));
|
|
@@ -66,5 +66,5 @@ exports.utils__math = __importStar(require("../utils/math.cjs"));
|
|
|
66
66
|
exports.utils__stream = __importStar(require("../utils/stream.cjs"));
|
|
67
67
|
exports.utils__testing = __importStar(require("../utils/testing/index.cjs"));
|
|
68
68
|
exports.utils__tiktoken = __importStar(require("../utils/tiktoken.cjs"));
|
|
69
|
-
exports.utils__types = __importStar(require("../utils/types.cjs"));
|
|
69
|
+
exports.utils__types = __importStar(require("../utils/types/index.cjs"));
|
|
70
70
|
exports.vectorstores = __importStar(require("../vectorstores.cjs"));
|
|
@@ -18,7 +18,7 @@ export * as outputs from "../outputs.js";
|
|
|
18
18
|
export * as prompts from "../prompts/index.js";
|
|
19
19
|
export * as prompt_values from "../prompt_values.js";
|
|
20
20
|
export * as runnables from "../runnables/index.js";
|
|
21
|
-
export * as retrievers from "../retrievers.js";
|
|
21
|
+
export * as retrievers from "../retrievers/index.js";
|
|
22
22
|
export * as stores from "../stores.js";
|
|
23
23
|
export * as tools from "../tools.js";
|
|
24
24
|
export * as tracers__base from "../tracers/base.js";
|
|
@@ -39,5 +39,5 @@ export * as utils__math from "../utils/math.js";
|
|
|
39
39
|
export * as utils__stream from "../utils/stream.js";
|
|
40
40
|
export * as utils__testing from "../utils/testing/index.js";
|
|
41
41
|
export * as utils__tiktoken from "../utils/tiktoken.js";
|
|
42
|
-
export * as utils__types from "../utils/types.js";
|
|
42
|
+
export * as utils__types from "../utils/types/index.js";
|
|
43
43
|
export * as vectorstores from "../vectorstores.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -19,7 +19,7 @@ export * as outputs from "../outputs.js";
|
|
|
19
19
|
export * as prompts from "../prompts/index.js";
|
|
20
20
|
export * as prompt_values from "../prompt_values.js";
|
|
21
21
|
export * as runnables from "../runnables/index.js";
|
|
22
|
-
export * as retrievers from "../retrievers.js";
|
|
22
|
+
export * as retrievers from "../retrievers/index.js";
|
|
23
23
|
export * as stores from "../stores.js";
|
|
24
24
|
export * as tools from "../tools.js";
|
|
25
25
|
export * as tracers__base from "../tracers/base.js";
|
|
@@ -40,5 +40,5 @@ export * as utils__math from "../utils/math.js";
|
|
|
40
40
|
export * as utils__stream from "../utils/stream.js";
|
|
41
41
|
export * as utils__testing from "../utils/testing/index.js";
|
|
42
42
|
export * as utils__tiktoken from "../utils/tiktoken.js";
|
|
43
|
-
export * as utils__types from "../utils/types.js";
|
|
43
|
+
export * as utils__types from "../utils/types/index.js";
|
|
44
44
|
export * as vectorstores from "../vectorstores.js";
|
package/dist/messages/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Serializable } from "../load/serializable.js";
|
|
2
|
-
import type { StringWithAutocomplete } from "../utils/types.js";
|
|
2
|
+
import type { StringWithAutocomplete } from "../utils/types/index.js";
|
|
3
3
|
export interface StoredMessageData {
|
|
4
4
|
content: string;
|
|
5
5
|
role: string | undefined;
|
|
@@ -225,7 +225,10 @@ export declare class ChatMessage extends BaseMessage implements ChatMessageField
|
|
|
225
225
|
_getType(): MessageType;
|
|
226
226
|
static isInstance(message: BaseMessage): message is ChatMessage;
|
|
227
227
|
}
|
|
228
|
-
export type BaseMessageLike = BaseMessage | [
|
|
228
|
+
export type BaseMessageLike = BaseMessage | [
|
|
229
|
+
StringWithAutocomplete<MessageType | "user" | "assistant" | "placeholder">,
|
|
230
|
+
MessageContent
|
|
231
|
+
] | string;
|
|
229
232
|
export declare function isBaseMessage(messageLike?: unknown): messageLike is BaseMessage;
|
|
230
233
|
export declare function isBaseMessageChunk(messageLike?: unknown): messageLike is BaseMessageChunk;
|
|
231
234
|
export declare function coerceMessageLikeToMessage(messageLike: BaseMessageLike): BaseMessage;
|
package/dist/prompts/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InputValues, PartialValues, StringWithAutocomplete } from "../utils/types.js";
|
|
1
|
+
import type { InputValues, PartialValues, StringWithAutocomplete } from "../utils/types/index.js";
|
|
2
2
|
import { type BasePromptValueInterface } from "../prompt_values.js";
|
|
3
3
|
import { BaseOutputParser } from "../output_parsers/index.js";
|
|
4
4
|
import type { SerializedFields } from "../load/map_keys.js";
|
package/dist/prompts/chat.cjs
CHANGED
|
@@ -451,6 +451,17 @@ function _coerceMessagePromptTemplateLike(messagePromptTemplateLike) {
|
|
|
451
451
|
(0, index_js_1.isBaseMessage)(messagePromptTemplateLike)) {
|
|
452
452
|
return messagePromptTemplateLike;
|
|
453
453
|
}
|
|
454
|
+
if (Array.isArray(messagePromptTemplateLike) &&
|
|
455
|
+
messagePromptTemplateLike[0] === "placeholder") {
|
|
456
|
+
const messageContent = messagePromptTemplateLike[1];
|
|
457
|
+
if (typeof messageContent !== "string" ||
|
|
458
|
+
messageContent[0] !== "{" ||
|
|
459
|
+
messageContent[messageContent.length - 1] !== "}") {
|
|
460
|
+
throw new Error(`Invalid placeholder template: "${messagePromptTemplateLike[1]}". Expected a variable name surrounded by curly braces.`);
|
|
461
|
+
}
|
|
462
|
+
const variableName = messageContent.slice(1, -1);
|
|
463
|
+
return new MessagesPlaceholder({ variableName, optional: true });
|
|
464
|
+
}
|
|
454
465
|
const message = (0, index_js_1.coerceMessageLikeToMessage)(messagePromptTemplateLike);
|
|
455
466
|
if (message._getType() === "human") {
|
|
456
467
|
return HumanMessagePromptTemplate.fromTemplate(message.content);
|
package/dist/prompts/chat.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BaseCallbackConfig } from "../callbacks/manager.js";
|
|
2
2
|
import { AIMessage, HumanMessage, SystemMessage, BaseMessage, ChatMessage, type BaseMessageLike, MessageContent } from "../messages/index.js";
|
|
3
3
|
import { type ChatPromptValueInterface } from "../prompt_values.js";
|
|
4
|
-
import type { InputValues, PartialValues } from "../utils/types.js";
|
|
4
|
+
import type { InputValues, PartialValues } from "../utils/types/index.js";
|
|
5
5
|
import { Runnable } from "../runnables/base.js";
|
|
6
6
|
import { BaseStringPromptTemplate } from "./string.js";
|
|
7
7
|
import { BasePromptTemplate, type BasePromptTemplateInput, type TypedPromptInputValues } from "./base.js";
|
package/dist/prompts/chat.js
CHANGED
|
@@ -440,6 +440,17 @@ function _coerceMessagePromptTemplateLike(messagePromptTemplateLike) {
|
|
|
440
440
|
isBaseMessage(messagePromptTemplateLike)) {
|
|
441
441
|
return messagePromptTemplateLike;
|
|
442
442
|
}
|
|
443
|
+
if (Array.isArray(messagePromptTemplateLike) &&
|
|
444
|
+
messagePromptTemplateLike[0] === "placeholder") {
|
|
445
|
+
const messageContent = messagePromptTemplateLike[1];
|
|
446
|
+
if (typeof messageContent !== "string" ||
|
|
447
|
+
messageContent[0] !== "{" ||
|
|
448
|
+
messageContent[messageContent.length - 1] !== "}") {
|
|
449
|
+
throw new Error(`Invalid placeholder template: "${messagePromptTemplateLike[1]}". Expected a variable name surrounded by curly braces.`);
|
|
450
|
+
}
|
|
451
|
+
const variableName = messageContent.slice(1, -1);
|
|
452
|
+
return new MessagesPlaceholder({ variableName, optional: true });
|
|
453
|
+
}
|
|
443
454
|
const message = coerceMessageLikeToMessage(messagePromptTemplateLike);
|
|
444
455
|
if (message._getType() === "human") {
|
|
445
456
|
return HumanMessagePromptTemplate.fromTemplate(message.content);
|
|
@@ -4,7 +4,7 @@ import type { BaseExampleSelector } from "../example_selectors/base.js";
|
|
|
4
4
|
import { type TemplateFormat } from "./template.js";
|
|
5
5
|
import { PromptTemplate } from "./prompt.js";
|
|
6
6
|
import type { SerializedFewShotTemplate } from "./serde.js";
|
|
7
|
-
import type { InputValues, PartialValues } from "../utils/types.js";
|
|
7
|
+
import type { InputValues, PartialValues } from "../utils/types/index.js";
|
|
8
8
|
import type { BaseMessage } from "../messages/index.js";
|
|
9
9
|
import { BaseChatPromptTemplate, type BaseMessagePromptTemplate } from "./chat.js";
|
|
10
10
|
export interface FewShotPromptTemplateInput extends BasePromptTemplateInput<InputValues> {
|
package/dist/prompts/image.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ImagePromptValue, ImageContent } from "../prompt_values.js";
|
|
2
|
-
import type { InputValues, PartialValues } from "../utils/types.js";
|
|
2
|
+
import type { InputValues, PartialValues } from "../utils/types/index.js";
|
|
3
3
|
import { BasePromptTemplate, BasePromptTemplateInput, TypedPromptInputValues } from "./base.js";
|
|
4
4
|
import { TemplateFormat } from "./template.js";
|
|
5
5
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InputValues, PartialValues } from "../utils/types.js";
|
|
1
|
+
import type { InputValues, PartialValues } from "../utils/types/index.js";
|
|
2
2
|
import type { SerializedBasePromptTemplate } from "./serde.js";
|
|
3
3
|
import { BasePromptTemplate, type BasePromptTemplateInput } from "./base.js";
|
|
4
4
|
/**
|
package/dist/prompts/prompt.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BaseStringPromptTemplate } from "./string.js";
|
|
|
2
2
|
import type { BasePromptTemplateInput, TypedPromptInputValues } from "./base.js";
|
|
3
3
|
import { type TemplateFormat } from "./template.js";
|
|
4
4
|
import type { SerializedPromptTemplate } from "./serde.js";
|
|
5
|
-
import type { InputValues, PartialValues } from "../utils/types.js";
|
|
5
|
+
import type { InputValues, PartialValues } from "../utils/types/index.js";
|
|
6
6
|
import { MessageContent } from "../messages/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Inputs to create a {@link PromptTemplate}
|
package/dist/prompts/string.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InputValues } from "../utils/types.js";
|
|
1
|
+
import type { InputValues } from "../utils/types/index.js";
|
|
2
2
|
import { type StringPromptValueInterface } from "../prompt_values.js";
|
|
3
3
|
import { BasePromptTemplate, type TypedPromptInputValues } from "./base.js";
|
|
4
4
|
/**
|
|
@@ -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 (
|
|
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
|
-
|
|
30
|
-
|
|
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChatPromptValueInterface } from "../prompt_values.js";
|
|
2
2
|
import { RunnableLike, Runnable } from "../runnables/base.js";
|
|
3
3
|
import { RunnableConfig } from "../runnables/config.js";
|
|
4
|
-
import { InputValues } from "../utils/types.js";
|
|
4
|
+
import { InputValues } from "../utils/types/index.js";
|
|
5
5
|
import { BaseMessagePromptTemplateLike, ChatPromptTemplate, ChatPromptTemplateInput } from "./chat.js";
|
|
6
6
|
/**
|
|
7
7
|
* Interface for the input of a ChatPromptTemplate.
|
|
@@ -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 (
|
|
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
|
-
|
|
27
|
-
|
|
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
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MessageContent } from "../messages/index.js";
|
|
2
|
-
import type { InputValues } from "../utils/types.js";
|
|
2
|
+
import type { InputValues } from "../utils/types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Type that specifies the format of a template. Only
|
|
5
5
|
* "f-string" is supported currently.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseDocumentCompressor = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base Document Compression class. All compressors should extend this class.
|
|
6
|
+
*/
|
|
7
|
+
class BaseDocumentCompressor {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
static isBaseDocumentCompressor(x) {
|
|
10
|
+
return x?.compressDocuments !== undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BaseDocumentCompressor = BaseDocumentCompressor;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Callbacks } from "../../callbacks/manager.js";
|
|
2
|
+
import { DocumentInterface } from "../../documents/document.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base Document Compression class. All compressors should extend this class.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseDocumentCompressor {
|
|
7
|
+
/**
|
|
8
|
+
* Abstract method that must be implemented by any class that extends
|
|
9
|
+
* `BaseDocumentCompressor`. This method takes an array of `Document`
|
|
10
|
+
* objects and a query string as parameters and returns a Promise that
|
|
11
|
+
* resolves with an array of compressed `Document` objects.
|
|
12
|
+
* @param documents An array of `Document` objects to be compressed.
|
|
13
|
+
* @param query A query string.
|
|
14
|
+
* @returns A Promise that resolves with an array of compressed `Document` objects.
|
|
15
|
+
*/
|
|
16
|
+
abstract compressDocuments(documents: DocumentInterface[], query: string, callbacks?: Callbacks): Promise<DocumentInterface[]>;
|
|
17
|
+
static isBaseDocumentCompressor(x: any): x is BaseDocumentCompressor;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Document Compression class. All compressors should extend this class.
|
|
3
|
+
*/
|
|
4
|
+
export class BaseDocumentCompressor {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
static isBaseDocumentCompressor(x) {
|
|
7
|
+
return x?.compressDocuments !== undefined;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseRetriever = void 0;
|
|
4
|
-
const manager_js_1 = require("
|
|
5
|
-
const base_js_1 = require("
|
|
6
|
-
const config_js_1 = require("
|
|
4
|
+
const manager_js_1 = require("../callbacks/manager.cjs");
|
|
5
|
+
const base_js_1 = require("../runnables/base.cjs");
|
|
6
|
+
const config_js_1 = require("../runnables/config.cjs");
|
|
7
7
|
/**
|
|
8
8
|
* Abstract base class for a Document retrieval system. A retrieval system
|
|
9
9
|
* is defined as something that can take string queries and return the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseCallbackConfig, CallbackManagerForRetrieverRun, Callbacks } from "
|
|
2
|
-
import type { DocumentInterface } from "
|
|
3
|
-
import { Runnable, type RunnableInterface } from "
|
|
4
|
-
import { RunnableConfig } from "
|
|
1
|
+
import { BaseCallbackConfig, CallbackManagerForRetrieverRun, Callbacks } from "../callbacks/manager.js";
|
|
2
|
+
import type { DocumentInterface } from "../documents/document.js";
|
|
3
|
+
import { Runnable, type RunnableInterface } from "../runnables/base.js";
|
|
4
|
+
import { RunnableConfig } from "../runnables/config.js";
|
|
5
5
|
/**
|
|
6
6
|
* Base Retriever class. All indexes should extend this class.
|
|
7
7
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CallbackManager, parseCallbackConfigArg, } from "
|
|
2
|
-
import { Runnable } from "
|
|
3
|
-
import { ensureConfig } from "
|
|
1
|
+
import { CallbackManager, parseCallbackConfigArg, } from "../callbacks/manager.js";
|
|
2
|
+
import { Runnable } from "../runnables/base.js";
|
|
3
|
+
import { ensureConfig } from "../runnables/config.js";
|
|
4
4
|
/**
|
|
5
5
|
* Abstract base class for a Document retrieval system. A retrieval system
|
|
6
6
|
* is defined as something that can take string queries and return the
|
package/dist/runnables/base.d.ts
CHANGED
|
@@ -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
|
-
|
|
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;
|