@langchain/core 0.1.52 → 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.d.ts +1 -1
- 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/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
|
/**
|
|
@@ -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.
|
|
@@ -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
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RemoteRunnable = void 0;
|
|
4
4
|
const base_js_1 = require("./base.cjs");
|
|
5
|
+
const config_js_1 = require("./config.cjs");
|
|
5
6
|
const index_js_1 = require("../documents/index.cjs");
|
|
6
7
|
const prompt_values_js_1 = require("../prompt_values.cjs");
|
|
7
8
|
const log_stream_js_1 = require("../tracers/log_stream.cjs");
|
|
@@ -261,7 +262,7 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
261
262
|
signal: AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
262
263
|
});
|
|
263
264
|
}
|
|
264
|
-
async
|
|
265
|
+
async _invoke(input, options, _) {
|
|
265
266
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
266
267
|
const response = await this.post("/invoke", {
|
|
267
268
|
input,
|
|
@@ -273,6 +274,9 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
273
274
|
}
|
|
274
275
|
return revive((await response.json()).output);
|
|
275
276
|
}
|
|
277
|
+
async invoke(input, options) {
|
|
278
|
+
return this._callWithConfig(this._invoke, input, options);
|
|
279
|
+
}
|
|
276
280
|
async _batch(inputs, options, _, batchOptions) {
|
|
277
281
|
if (batchOptions?.returnExceptions) {
|
|
278
282
|
throw new Error("returnExceptions is not supported for remote clients");
|
|
@@ -303,50 +307,60 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
303
307
|
}
|
|
304
308
|
return this._batchWithConfig(this._batch.bind(this), inputs, options, batchOptions);
|
|
305
309
|
}
|
|
306
|
-
async
|
|
310
|
+
async *_streamIterator(input, options) {
|
|
307
311
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
312
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
|
|
313
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), (0, base_js_1._coerceToDict)(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
314
|
+
let finalOutput;
|
|
315
|
+
let finalOutputSupported = true;
|
|
316
|
+
try {
|
|
317
|
+
const response = await this.post("/stream", {
|
|
318
|
+
input,
|
|
319
|
+
config: removeCallbacks(config),
|
|
320
|
+
kwargs,
|
|
321
|
+
});
|
|
322
|
+
if (!response.ok) {
|
|
323
|
+
const json = await response.json();
|
|
324
|
+
const error = new Error(`RemoteRunnable call failed with status code ${response.status}: ${json.message}`);
|
|
325
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
326
|
+
error.response = response;
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
const { body } = response;
|
|
330
|
+
if (!body) {
|
|
331
|
+
throw new Error("Could not begin remote stream. Please check the given URL and try again.");
|
|
332
|
+
}
|
|
333
|
+
const runnableStream = (0, event_source_parse_js_1.convertEventStreamToIterableReadableDataStream)(body);
|
|
326
334
|
for await (const chunk of runnableStream) {
|
|
327
|
-
|
|
335
|
+
const deserializedChunk = deserialize(chunk);
|
|
336
|
+
yield deserializedChunk;
|
|
337
|
+
if (finalOutputSupported) {
|
|
338
|
+
if (finalOutput === undefined) {
|
|
339
|
+
finalOutput = deserializedChunk;
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
try {
|
|
343
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
344
|
+
finalOutput = (0, stream_js_1.concat)(finalOutput, deserializedChunk);
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
finalOutput = undefined;
|
|
348
|
+
finalOutputSupported = false;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
328
352
|
}
|
|
329
353
|
}
|
|
330
|
-
|
|
354
|
+
catch (err) {
|
|
355
|
+
await runManager?.handleChainError(err);
|
|
356
|
+
throw err;
|
|
357
|
+
}
|
|
358
|
+
await runManager?.handleChainEnd(finalOutput ?? {});
|
|
331
359
|
}
|
|
332
360
|
async *streamLog(input, options, streamOptions) {
|
|
333
361
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
autoClose: false,
|
|
337
|
-
});
|
|
338
|
-
const { callbacks } = config;
|
|
339
|
-
if (callbacks === undefined) {
|
|
340
|
-
config.callbacks = [stream];
|
|
341
|
-
}
|
|
342
|
-
else if (Array.isArray(callbacks)) {
|
|
343
|
-
config.callbacks = callbacks.concat([stream]);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
const copiedCallbacks = callbacks.copy();
|
|
347
|
-
copiedCallbacks.inheritableHandlers.push(stream);
|
|
348
|
-
config.callbacks = copiedCallbacks;
|
|
349
|
-
}
|
|
362
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
|
|
363
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), (0, base_js_1._coerceToDict)(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
350
364
|
// The type is in camelCase but the API only accepts snake_case.
|
|
351
365
|
const camelCaseStreamOptions = {
|
|
352
366
|
include_names: streamOptions?.includeNames,
|
|
@@ -356,31 +370,48 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
356
370
|
exclude_types: streamOptions?.excludeTypes,
|
|
357
371
|
exclude_tags: streamOptions?.excludeTags,
|
|
358
372
|
};
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
373
|
+
let runLog;
|
|
374
|
+
try {
|
|
375
|
+
const response = await this.post("/stream_log", {
|
|
376
|
+
input,
|
|
377
|
+
config: removeCallbacks(config),
|
|
378
|
+
kwargs,
|
|
379
|
+
...camelCaseStreamOptions,
|
|
380
|
+
diff: false,
|
|
381
|
+
});
|
|
382
|
+
const { body, ok } = response;
|
|
383
|
+
if (!ok) {
|
|
384
|
+
throw new Error(`${response.status} Error: ${await response.text()}`);
|
|
385
|
+
}
|
|
386
|
+
if (!body) {
|
|
387
|
+
throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
|
|
388
|
+
}
|
|
389
|
+
const runnableStream = (0, event_source_parse_js_1.convertEventStreamToIterableReadableDataStream)(body);
|
|
390
|
+
for await (const log of runnableStream) {
|
|
391
|
+
const chunk = revive(JSON.parse(log));
|
|
392
|
+
const logPatch = new log_stream_js_1.RunLogPatch({ ops: chunk.ops });
|
|
393
|
+
yield logPatch;
|
|
394
|
+
if (runLog === undefined) {
|
|
395
|
+
runLog = log_stream_js_1.RunLog.fromRunLogPatch(logPatch);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
runLog = runLog.concat(logPatch);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
372
401
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
yield new log_stream_js_1.RunLogPatch({ ops: chunk.ops });
|
|
402
|
+
catch (err) {
|
|
403
|
+
await runManager?.handleChainError(err);
|
|
404
|
+
throw err;
|
|
377
405
|
}
|
|
406
|
+
await runManager?.handleChainEnd(runLog?.state.final_output);
|
|
378
407
|
}
|
|
379
408
|
async *streamEvents(input, options, streamOptions) {
|
|
380
409
|
if (options?.version !== "v1") {
|
|
381
410
|
throw new Error(`Only version "v1" of the events schema is currently supported.`);
|
|
382
411
|
}
|
|
383
412
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
413
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
|
|
414
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), (0, base_js_1._coerceToDict)(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
384
415
|
// The type is in camelCase but the API only accepts snake_case.
|
|
385
416
|
const camelCaseStreamOptions = {
|
|
386
417
|
include_names: streamOptions?.includeNames,
|
|
@@ -390,32 +421,42 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
390
421
|
exclude_types: streamOptions?.excludeTypes,
|
|
391
422
|
exclude_tags: streamOptions?.excludeTags,
|
|
392
423
|
};
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
424
|
+
const events = [];
|
|
425
|
+
try {
|
|
426
|
+
const response = await this.post("/stream_events", {
|
|
427
|
+
input,
|
|
428
|
+
config: removeCallbacks(config),
|
|
429
|
+
kwargs,
|
|
430
|
+
...camelCaseStreamOptions,
|
|
431
|
+
diff: false,
|
|
432
|
+
});
|
|
433
|
+
const { body, ok } = response;
|
|
434
|
+
if (!ok) {
|
|
435
|
+
throw new Error(`${response.status} Error: ${await response.text()}`);
|
|
436
|
+
}
|
|
437
|
+
if (!body) {
|
|
438
|
+
throw new Error("Could not begin remote stream events. Please check the given URL and try again.");
|
|
439
|
+
}
|
|
440
|
+
const runnableStream = (0, event_source_parse_js_1.convertEventStreamToIterableReadableDataStream)(body);
|
|
441
|
+
for await (const log of runnableStream) {
|
|
442
|
+
const chunk = revive(JSON.parse(log));
|
|
443
|
+
const event = {
|
|
444
|
+
event: chunk.event,
|
|
445
|
+
name: chunk.name,
|
|
446
|
+
run_id: chunk.run_id,
|
|
447
|
+
tags: chunk.tags,
|
|
448
|
+
metadata: chunk.metadata,
|
|
449
|
+
data: chunk.data,
|
|
450
|
+
};
|
|
451
|
+
yield event;
|
|
452
|
+
events.push(event);
|
|
453
|
+
}
|
|
406
454
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
yield {
|
|
411
|
-
event: chunk.event,
|
|
412
|
-
name: chunk.name,
|
|
413
|
-
run_id: chunk.run_id,
|
|
414
|
-
tags: chunk.tags,
|
|
415
|
-
metadata: chunk.metadata,
|
|
416
|
-
data: chunk.data,
|
|
417
|
-
};
|
|
455
|
+
catch (err) {
|
|
456
|
+
await runManager?.handleChainError(err);
|
|
457
|
+
throw err;
|
|
418
458
|
}
|
|
459
|
+
await runManager?.handleChainEnd(events);
|
|
419
460
|
}
|
|
420
461
|
}
|
|
421
462
|
exports.RemoteRunnable = RemoteRunnable;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Runnable, RunnableBatchOptions } from "./base.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type RunnableConfig } from "./config.js";
|
|
3
3
|
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
4
4
|
import { RunLogPatch, type LogStreamCallbackHandlerInput, type StreamEvent } from "../tracers/log_stream.js";
|
|
5
|
-
import { IterableReadableStream } from "../utils/stream.js";
|
|
6
5
|
type RemoteRunnableOptions = {
|
|
7
6
|
timeout?: number;
|
|
8
7
|
headers?: Record<string, unknown>;
|
|
@@ -16,6 +15,7 @@ export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends Run
|
|
|
16
15
|
options?: RemoteRunnableOptions;
|
|
17
16
|
});
|
|
18
17
|
private post;
|
|
18
|
+
_invoke(input: RunInput, options?: Partial<CallOptions>, _?: CallbackManagerForChainRun): Promise<RunOutput>;
|
|
19
19
|
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
20
20
|
_batch(inputs: RunInput[], options?: Partial<CallOptions>[], _?: (CallbackManagerForChainRun | undefined)[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
21
21
|
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
@@ -25,7 +25,7 @@ export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends Run
|
|
|
25
25
|
returnExceptions: true;
|
|
26
26
|
}): Promise<(RunOutput | Error)[]>;
|
|
27
27
|
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
28
|
-
|
|
28
|
+
_streamIterator(input: RunInput, options?: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
29
29
|
streamLog(input: RunInput, options?: Partial<CallOptions>, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): AsyncGenerator<RunLogPatch>;
|
|
30
30
|
streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
31
31
|
version: "v1";
|
package/dist/runnables/remote.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Runnable } from "./base.js";
|
|
1
|
+
import { Runnable, _coerceToDict } from "./base.js";
|
|
2
|
+
import { getCallbackManagerForConfig } from "./config.js";
|
|
2
3
|
import { Document } from "../documents/index.js";
|
|
3
4
|
import { ChatPromptValue, StringPromptValue } from "../prompt_values.js";
|
|
4
|
-
import {
|
|
5
|
+
import { RunLogPatch, RunLog, } from "../tracers/log_stream.js";
|
|
5
6
|
import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk, isBaseMessage, } from "../messages/index.js";
|
|
6
7
|
import { GenerationChunk, ChatGenerationChunk, RUN_KEY } from "../outputs.js";
|
|
7
8
|
import { convertEventStreamToIterableReadableDataStream } from "../utils/event_source_parse.js";
|
|
8
|
-
import {
|
|
9
|
+
import { concat } from "../utils/stream.js";
|
|
9
10
|
function isSuperset(set, subset) {
|
|
10
11
|
for (const elem of subset) {
|
|
11
12
|
if (!set.has(elem)) {
|
|
@@ -258,7 +259,7 @@ export class RemoteRunnable extends Runnable {
|
|
|
258
259
|
signal: AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
259
260
|
});
|
|
260
261
|
}
|
|
261
|
-
async
|
|
262
|
+
async _invoke(input, options, _) {
|
|
262
263
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
263
264
|
const response = await this.post("/invoke", {
|
|
264
265
|
input,
|
|
@@ -270,6 +271,9 @@ export class RemoteRunnable extends Runnable {
|
|
|
270
271
|
}
|
|
271
272
|
return revive((await response.json()).output);
|
|
272
273
|
}
|
|
274
|
+
async invoke(input, options) {
|
|
275
|
+
return this._callWithConfig(this._invoke, input, options);
|
|
276
|
+
}
|
|
273
277
|
async _batch(inputs, options, _, batchOptions) {
|
|
274
278
|
if (batchOptions?.returnExceptions) {
|
|
275
279
|
throw new Error("returnExceptions is not supported for remote clients");
|
|
@@ -300,50 +304,60 @@ export class RemoteRunnable extends Runnable {
|
|
|
300
304
|
}
|
|
301
305
|
return this._batchWithConfig(this._batch.bind(this), inputs, options, batchOptions);
|
|
302
306
|
}
|
|
303
|
-
async
|
|
307
|
+
async *_streamIterator(input, options) {
|
|
304
308
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
309
|
+
const callbackManager_ = await getCallbackManagerForConfig(options);
|
|
310
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
311
|
+
let finalOutput;
|
|
312
|
+
let finalOutputSupported = true;
|
|
313
|
+
try {
|
|
314
|
+
const response = await this.post("/stream", {
|
|
315
|
+
input,
|
|
316
|
+
config: removeCallbacks(config),
|
|
317
|
+
kwargs,
|
|
318
|
+
});
|
|
319
|
+
if (!response.ok) {
|
|
320
|
+
const json = await response.json();
|
|
321
|
+
const error = new Error(`RemoteRunnable call failed with status code ${response.status}: ${json.message}`);
|
|
322
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
323
|
+
error.response = response;
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
const { body } = response;
|
|
327
|
+
if (!body) {
|
|
328
|
+
throw new Error("Could not begin remote stream. Please check the given URL and try again.");
|
|
329
|
+
}
|
|
330
|
+
const runnableStream = convertEventStreamToIterableReadableDataStream(body);
|
|
323
331
|
for await (const chunk of runnableStream) {
|
|
324
|
-
|
|
332
|
+
const deserializedChunk = deserialize(chunk);
|
|
333
|
+
yield deserializedChunk;
|
|
334
|
+
if (finalOutputSupported) {
|
|
335
|
+
if (finalOutput === undefined) {
|
|
336
|
+
finalOutput = deserializedChunk;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
try {
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
341
|
+
finalOutput = concat(finalOutput, deserializedChunk);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
finalOutput = undefined;
|
|
345
|
+
finalOutputSupported = false;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
325
349
|
}
|
|
326
350
|
}
|
|
327
|
-
|
|
351
|
+
catch (err) {
|
|
352
|
+
await runManager?.handleChainError(err);
|
|
353
|
+
throw err;
|
|
354
|
+
}
|
|
355
|
+
await runManager?.handleChainEnd(finalOutput ?? {});
|
|
328
356
|
}
|
|
329
357
|
async *streamLog(input, options, streamOptions) {
|
|
330
358
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
autoClose: false,
|
|
334
|
-
});
|
|
335
|
-
const { callbacks } = config;
|
|
336
|
-
if (callbacks === undefined) {
|
|
337
|
-
config.callbacks = [stream];
|
|
338
|
-
}
|
|
339
|
-
else if (Array.isArray(callbacks)) {
|
|
340
|
-
config.callbacks = callbacks.concat([stream]);
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
const copiedCallbacks = callbacks.copy();
|
|
344
|
-
copiedCallbacks.inheritableHandlers.push(stream);
|
|
345
|
-
config.callbacks = copiedCallbacks;
|
|
346
|
-
}
|
|
359
|
+
const callbackManager_ = await getCallbackManagerForConfig(options);
|
|
360
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
347
361
|
// The type is in camelCase but the API only accepts snake_case.
|
|
348
362
|
const camelCaseStreamOptions = {
|
|
349
363
|
include_names: streamOptions?.includeNames,
|
|
@@ -353,31 +367,48 @@ export class RemoteRunnable extends Runnable {
|
|
|
353
367
|
exclude_types: streamOptions?.excludeTypes,
|
|
354
368
|
exclude_tags: streamOptions?.excludeTags,
|
|
355
369
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
370
|
+
let runLog;
|
|
371
|
+
try {
|
|
372
|
+
const response = await this.post("/stream_log", {
|
|
373
|
+
input,
|
|
374
|
+
config: removeCallbacks(config),
|
|
375
|
+
kwargs,
|
|
376
|
+
...camelCaseStreamOptions,
|
|
377
|
+
diff: false,
|
|
378
|
+
});
|
|
379
|
+
const { body, ok } = response;
|
|
380
|
+
if (!ok) {
|
|
381
|
+
throw new Error(`${response.status} Error: ${await response.text()}`);
|
|
382
|
+
}
|
|
383
|
+
if (!body) {
|
|
384
|
+
throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
|
|
385
|
+
}
|
|
386
|
+
const runnableStream = convertEventStreamToIterableReadableDataStream(body);
|
|
387
|
+
for await (const log of runnableStream) {
|
|
388
|
+
const chunk = revive(JSON.parse(log));
|
|
389
|
+
const logPatch = new RunLogPatch({ ops: chunk.ops });
|
|
390
|
+
yield logPatch;
|
|
391
|
+
if (runLog === undefined) {
|
|
392
|
+
runLog = RunLog.fromRunLogPatch(logPatch);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
runLog = runLog.concat(logPatch);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
369
398
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
yield new RunLogPatch({ ops: chunk.ops });
|
|
399
|
+
catch (err) {
|
|
400
|
+
await runManager?.handleChainError(err);
|
|
401
|
+
throw err;
|
|
374
402
|
}
|
|
403
|
+
await runManager?.handleChainEnd(runLog?.state.final_output);
|
|
375
404
|
}
|
|
376
405
|
async *streamEvents(input, options, streamOptions) {
|
|
377
406
|
if (options?.version !== "v1") {
|
|
378
407
|
throw new Error(`Only version "v1" of the events schema is currently supported.`);
|
|
379
408
|
}
|
|
380
409
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
410
|
+
const callbackManager_ = await getCallbackManagerForConfig(options);
|
|
411
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
381
412
|
// The type is in camelCase but the API only accepts snake_case.
|
|
382
413
|
const camelCaseStreamOptions = {
|
|
383
414
|
include_names: streamOptions?.includeNames,
|
|
@@ -387,31 +418,41 @@ export class RemoteRunnable extends Runnable {
|
|
|
387
418
|
exclude_types: streamOptions?.excludeTypes,
|
|
388
419
|
exclude_tags: streamOptions?.excludeTags,
|
|
389
420
|
};
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
421
|
+
const events = [];
|
|
422
|
+
try {
|
|
423
|
+
const response = await this.post("/stream_events", {
|
|
424
|
+
input,
|
|
425
|
+
config: removeCallbacks(config),
|
|
426
|
+
kwargs,
|
|
427
|
+
...camelCaseStreamOptions,
|
|
428
|
+
diff: false,
|
|
429
|
+
});
|
|
430
|
+
const { body, ok } = response;
|
|
431
|
+
if (!ok) {
|
|
432
|
+
throw new Error(`${response.status} Error: ${await response.text()}`);
|
|
433
|
+
}
|
|
434
|
+
if (!body) {
|
|
435
|
+
throw new Error("Could not begin remote stream events. Please check the given URL and try again.");
|
|
436
|
+
}
|
|
437
|
+
const runnableStream = convertEventStreamToIterableReadableDataStream(body);
|
|
438
|
+
for await (const log of runnableStream) {
|
|
439
|
+
const chunk = revive(JSON.parse(log));
|
|
440
|
+
const event = {
|
|
441
|
+
event: chunk.event,
|
|
442
|
+
name: chunk.name,
|
|
443
|
+
run_id: chunk.run_id,
|
|
444
|
+
tags: chunk.tags,
|
|
445
|
+
metadata: chunk.metadata,
|
|
446
|
+
data: chunk.data,
|
|
447
|
+
};
|
|
448
|
+
yield event;
|
|
449
|
+
events.push(event);
|
|
450
|
+
}
|
|
403
451
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
yield {
|
|
408
|
-
event: chunk.event,
|
|
409
|
-
name: chunk.name,
|
|
410
|
-
run_id: chunk.run_id,
|
|
411
|
-
tags: chunk.tags,
|
|
412
|
-
metadata: chunk.metadata,
|
|
413
|
-
data: chunk.data,
|
|
414
|
-
};
|
|
452
|
+
catch (err) {
|
|
453
|
+
await runManager?.handleChainError(err);
|
|
454
|
+
throw err;
|
|
415
455
|
}
|
|
456
|
+
await runManager?.handleChainEnd(events);
|
|
416
457
|
}
|
|
417
458
|
}
|
package/dist/tracers/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KVMap, BaseRun } from "langsmith/schemas";
|
|
2
|
-
import type { ChainValues } from "../utils/types.js";
|
|
2
|
+
import type { ChainValues } from "../utils/types/index.js";
|
|
3
3
|
import type { AgentAction, AgentFinish } from "../agents.js";
|
|
4
4
|
import type { LLMResult } from "../outputs.js";
|
|
5
5
|
import type { BaseMessage } from "../messages/index.js";
|
|
@@ -8,7 +8,7 @@ const llms_js_1 = require("../../language_models/llms.cjs");
|
|
|
8
8
|
const index_js_1 = require("../../messages/index.cjs");
|
|
9
9
|
const base_js_1 = require("../../output_parsers/base.cjs");
|
|
10
10
|
const outputs_js_1 = require("../../outputs.cjs");
|
|
11
|
-
const
|
|
11
|
+
const index_js_2 = require("../../retrievers/index.cjs");
|
|
12
12
|
const base_js_2 = require("../../runnables/base.cjs");
|
|
13
13
|
const tools_js_1 = require("../../tools.cjs");
|
|
14
14
|
const base_js_3 = require("../../tracers/base.cjs");
|
|
@@ -172,7 +172,7 @@ class FakeChatModel extends chat_models_js_1.BaseChatModel {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
exports.FakeChatModel = FakeChatModel;
|
|
175
|
-
class FakeRetriever extends
|
|
175
|
+
class FakeRetriever extends index_js_2.BaseRetriever {
|
|
176
176
|
constructor(fields) {
|
|
177
177
|
super();
|
|
178
178
|
Object.defineProperty(this, "lc_namespace", {
|
|
@@ -7,7 +7,7 @@ import { BaseLLMParams, LLM } from "../../language_models/llms.js";
|
|
|
7
7
|
import { BaseMessage, AIMessage } from "../../messages/index.js";
|
|
8
8
|
import { BaseOutputParser } from "../../output_parsers/base.js";
|
|
9
9
|
import { GenerationChunk, type ChatResult, ChatGenerationChunk } from "../../outputs.js";
|
|
10
|
-
import { BaseRetriever } from "../../retrievers.js";
|
|
10
|
+
import { BaseRetriever } from "../../retrievers/index.js";
|
|
11
11
|
import { Runnable } from "../../runnables/base.js";
|
|
12
12
|
import { StructuredTool, ToolParams } from "../../tools.js";
|
|
13
13
|
import { BaseTracer, Run } from "../../tracers/base.js";
|
|
@@ -5,7 +5,7 @@ import { LLM } from "../../language_models/llms.js";
|
|
|
5
5
|
import { AIMessage, AIMessageChunk, HumanMessage, } from "../../messages/index.js";
|
|
6
6
|
import { BaseOutputParser } from "../../output_parsers/base.js";
|
|
7
7
|
import { ChatGenerationChunk, } from "../../outputs.js";
|
|
8
|
-
import { BaseRetriever } from "../../retrievers.js";
|
|
8
|
+
import { BaseRetriever } from "../../retrievers/index.js";
|
|
9
9
|
import { Runnable, RunnableLambda } from "../../runnables/base.js";
|
|
10
10
|
import { StructuredTool } from "../../tools.js";
|
|
11
11
|
import { BaseTracer } from "../../tracers/base.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./is_zod_schema.cjs"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./is_zod_schema.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isZodSchema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Given either a Zod schema, or plain object, determine if the input is a Zod schema.
|
|
6
|
+
*
|
|
7
|
+
* @param {z.ZodType<RunOutput> | Record<string, any>} input
|
|
8
|
+
* @returns {boolean} Whether or not the provided input is a Zod schema.
|
|
9
|
+
*/
|
|
10
|
+
function isZodSchema(
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
input) {
|
|
13
|
+
// Check for a characteristic method of Zod schemas
|
|
14
|
+
return typeof input?.parse === "function";
|
|
15
|
+
}
|
|
16
|
+
exports.isZodSchema = isZodSchema;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Given either a Zod schema, or plain object, determine if the input is a Zod schema.
|
|
4
|
+
*
|
|
5
|
+
* @param {z.ZodType<RunOutput> | Record<string, any>} input
|
|
6
|
+
* @returns {boolean} Whether or not the provided input is a Zod schema.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isZodSchema<RunOutput extends Record<string, any> = Record<string, any>>(input: z.ZodType<RunOutput> | Record<string, any>): input is z.ZodType<RunOutput>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given either a Zod schema, or plain object, determine if the input is a Zod schema.
|
|
3
|
+
*
|
|
4
|
+
* @param {z.ZodType<RunOutput> | Record<string, any>} input
|
|
5
|
+
* @returns {boolean} Whether or not the provided input is a Zod schema.
|
|
6
|
+
*/
|
|
7
|
+
export function isZodSchema(
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
input) {
|
|
10
|
+
// Check for a characteristic method of Zod schemas
|
|
11
|
+
return typeof input?.parse === "function";
|
|
12
|
+
}
|
package/dist/vectorstores.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SaveableVectorStore = exports.VectorStore = exports.VectorStoreRetriever = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("./retrievers/index.cjs");
|
|
5
5
|
const serializable_js_1 = require("./load/serializable.cjs");
|
|
6
6
|
/**
|
|
7
7
|
* Class for performing document retrieval from a VectorStore. Can perform
|
|
8
8
|
* similarity search or maximal marginal relevance search.
|
|
9
9
|
*/
|
|
10
|
-
class VectorStoreRetriever extends
|
|
10
|
+
class VectorStoreRetriever extends index_js_1.BaseRetriever {
|
|
11
11
|
static lc_name() {
|
|
12
12
|
return "VectorStoreRetriever";
|
|
13
13
|
}
|
package/dist/vectorstores.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EmbeddingsInterface } from "./embeddings.js";
|
|
2
2
|
import type { DocumentInterface } from "./documents/document.js";
|
|
3
|
-
import { BaseRetriever, BaseRetrieverInterface, type BaseRetrieverInput } from "./retrievers.js";
|
|
3
|
+
import { BaseRetriever, BaseRetrieverInterface, type BaseRetrieverInput } from "./retrievers/index.js";
|
|
4
4
|
import { Serializable } from "./load/serializable.js";
|
|
5
5
|
import { CallbackManagerForRetrieverRun, Callbacks } from "./callbacks/manager.js";
|
|
6
6
|
/**
|
package/dist/vectorstores.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -318,6 +318,15 @@
|
|
|
318
318
|
"import": "./retrievers.js",
|
|
319
319
|
"require": "./retrievers.cjs"
|
|
320
320
|
},
|
|
321
|
+
"./retrievers/document_compressors": {
|
|
322
|
+
"types": {
|
|
323
|
+
"import": "./retrievers/document_compressors.d.ts",
|
|
324
|
+
"require": "./retrievers/document_compressors.d.cts",
|
|
325
|
+
"default": "./retrievers/document_compressors.d.ts"
|
|
326
|
+
},
|
|
327
|
+
"import": "./retrievers/document_compressors.js",
|
|
328
|
+
"require": "./retrievers/document_compressors.cjs"
|
|
329
|
+
},
|
|
321
330
|
"./singletons": {
|
|
322
331
|
"types": {
|
|
323
332
|
"import": "./singletons.d.ts",
|
|
@@ -417,6 +426,15 @@
|
|
|
417
426
|
"import": "./utils/async_caller.js",
|
|
418
427
|
"require": "./utils/async_caller.cjs"
|
|
419
428
|
},
|
|
429
|
+
"./utils/beta_warning": {
|
|
430
|
+
"types": {
|
|
431
|
+
"import": "./utils/beta_warning.d.ts",
|
|
432
|
+
"require": "./utils/beta_warning.d.cts",
|
|
433
|
+
"default": "./utils/beta_warning.d.ts"
|
|
434
|
+
},
|
|
435
|
+
"import": "./utils/beta_warning.js",
|
|
436
|
+
"require": "./utils/beta_warning.cjs"
|
|
437
|
+
},
|
|
420
438
|
"./utils/chunk_array": {
|
|
421
439
|
"types": {
|
|
422
440
|
"import": "./utils/chunk_array.d.ts",
|
|
@@ -525,15 +543,6 @@
|
|
|
525
543
|
"import": "./utils/types.js",
|
|
526
544
|
"require": "./utils/types.cjs"
|
|
527
545
|
},
|
|
528
|
-
"./utils/beta_warning": {
|
|
529
|
-
"types": {
|
|
530
|
-
"import": "./utils/beta_warning.d.ts",
|
|
531
|
-
"require": "./utils/beta_warning.d.cts",
|
|
532
|
-
"default": "./utils/beta_warning.d.ts"
|
|
533
|
-
},
|
|
534
|
-
"import": "./utils/beta_warning.js",
|
|
535
|
-
"require": "./utils/beta_warning.cjs"
|
|
536
|
-
},
|
|
537
546
|
"./vectorstores": {
|
|
538
547
|
"types": {
|
|
539
548
|
"import": "./vectorstores.d.ts",
|
|
@@ -647,6 +656,10 @@
|
|
|
647
656
|
"retrievers.js",
|
|
648
657
|
"retrievers.d.ts",
|
|
649
658
|
"retrievers.d.cts",
|
|
659
|
+
"retrievers/document_compressors.cjs",
|
|
660
|
+
"retrievers/document_compressors.js",
|
|
661
|
+
"retrievers/document_compressors.d.ts",
|
|
662
|
+
"retrievers/document_compressors.d.cts",
|
|
650
663
|
"singletons.cjs",
|
|
651
664
|
"singletons.js",
|
|
652
665
|
"singletons.d.ts",
|
|
@@ -691,6 +704,10 @@
|
|
|
691
704
|
"utils/async_caller.js",
|
|
692
705
|
"utils/async_caller.d.ts",
|
|
693
706
|
"utils/async_caller.d.cts",
|
|
707
|
+
"utils/beta_warning.cjs",
|
|
708
|
+
"utils/beta_warning.js",
|
|
709
|
+
"utils/beta_warning.d.ts",
|
|
710
|
+
"utils/beta_warning.d.cts",
|
|
694
711
|
"utils/chunk_array.cjs",
|
|
695
712
|
"utils/chunk_array.js",
|
|
696
713
|
"utils/chunk_array.d.ts",
|
|
@@ -739,10 +756,6 @@
|
|
|
739
756
|
"utils/types.js",
|
|
740
757
|
"utils/types.d.ts",
|
|
741
758
|
"utils/types.d.cts",
|
|
742
|
-
"utils/beta_warning.cjs",
|
|
743
|
-
"utils/beta_warning.js",
|
|
744
|
-
"utils/beta_warning.d.ts",
|
|
745
|
-
"utils/beta_warning.d.cts",
|
|
746
759
|
"vectorstores.cjs",
|
|
747
760
|
"vectorstores.js",
|
|
748
761
|
"vectorstores.d.ts",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/retrievers/document_compressors/base.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/retrievers/document_compressors/base.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/retrievers/document_compressors/base.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/retrievers/document_compressors/base.js'
|
package/retrievers.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./dist/retrievers.cjs');
|
|
1
|
+
module.exports = require('./dist/retrievers/index.cjs');
|
package/retrievers.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './dist/retrievers.js'
|
|
1
|
+
export * from './dist/retrievers/index.js'
|
package/retrievers.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './dist/retrievers.js'
|
|
1
|
+
export * from './dist/retrievers/index.js'
|
package/retrievers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './dist/retrievers.js'
|
|
1
|
+
export * from './dist/retrievers/index.js'
|
package/utils/types.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('../dist/utils/types.cjs');
|
|
1
|
+
module.exports = require('../dist/utils/types/index.cjs');
|
package/utils/types.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../dist/utils/types.js'
|
|
1
|
+
export * from '../dist/utils/types/index.js'
|
package/utils/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../dist/utils/types.js'
|
|
1
|
+
export * from '../dist/utils/types/index.js'
|
package/utils/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../dist/utils/types.js'
|
|
1
|
+
export * from '../dist/utils/types/index.js'
|
package/dist/utils/types.cjs
DELETED
package/dist/utils/types.js
DELETED