@langchain/core 0.2.7 → 0.2.8
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/caches.cjs +2 -2
- package/dist/caches.d.ts +1 -1
- package/dist/caches.js +1 -1
- package/dist/callbacks/base.d.ts +1 -1
- package/dist/callbacks/manager.cjs +2 -2
- package/dist/callbacks/manager.d.ts +1 -1
- package/dist/callbacks/manager.js +1 -1
- package/dist/language_models/base.cjs +2 -2
- package/dist/language_models/base.d.ts +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/messages/ai.cjs +2 -1
- package/dist/messages/ai.js +2 -1
- package/dist/messages/base.cjs +11 -0
- package/dist/messages/base.d.ts +10 -0
- package/dist/messages/base.js +11 -0
- package/dist/messages/chat.cjs +1 -0
- package/dist/messages/chat.js +1 -0
- package/dist/messages/function.cjs +1 -0
- package/dist/messages/function.js +1 -0
- package/dist/messages/human.cjs +1 -0
- package/dist/messages/human.js +1 -0
- package/dist/messages/index.cjs +1 -0
- package/dist/messages/index.d.ts +1 -0
- package/dist/messages/index.js +1 -0
- package/dist/messages/system.cjs +1 -0
- package/dist/messages/system.js +1 -0
- package/dist/messages/tests/message_utils.test.d.ts +1 -0
- package/dist/messages/tests/message_utils.test.js +382 -0
- package/dist/messages/tool.cjs +1 -0
- package/dist/messages/tool.js +1 -0
- package/dist/messages/transformers.cjs +421 -0
- package/dist/messages/transformers.d.ts +465 -0
- package/dist/messages/transformers.js +414 -0
- package/dist/messages/utils.cjs +17 -4
- package/dist/messages/utils.d.ts +3 -3
- package/dist/messages/utils.js +17 -4
- package/dist/outputs.d.ts +1 -1
- package/dist/prompt_values.cjs +5 -4
- package/dist/prompt_values.d.ts +2 -1
- package/dist/prompt_values.js +2 -1
- package/dist/tracers/base.d.ts +1 -1
- package/dist/tracers/log_stream.cjs +2 -2
- package/dist/tracers/log_stream.js +1 -1
- package/dist/tracers/tracer_langchain_v1.cjs +2 -2
- package/dist/tracers/tracer_langchain_v1.js +1 -1
- package/package.json +1 -1
package/dist/caches.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryCache = exports.BaseCache = exports.serializeGeneration = exports.deserializeStoredGeneration = exports.getCacheKey = void 0;
|
|
4
4
|
const hash_js_1 = require("./utils/hash.cjs");
|
|
5
|
-
const
|
|
5
|
+
const utils_js_1 = require("./messages/utils.cjs");
|
|
6
6
|
/**
|
|
7
7
|
* This cache key should be consistent across all versions of langchain.
|
|
8
8
|
* It is currently NOT consistent across versions of langchain.
|
|
@@ -19,7 +19,7 @@ function deserializeStoredGeneration(storedGeneration) {
|
|
|
19
19
|
if (storedGeneration.message !== undefined) {
|
|
20
20
|
return {
|
|
21
21
|
text: storedGeneration.text,
|
|
22
|
-
message: (0,
|
|
22
|
+
message: (0, utils_js_1.mapStoredMessageToChatMessage)(storedGeneration.message),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
else {
|
package/dist/caches.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Generation } from "./outputs.js";
|
|
2
|
-
import { type StoredGeneration } from "./messages/
|
|
2
|
+
import { type StoredGeneration } from "./messages/base.js";
|
|
3
3
|
/**
|
|
4
4
|
* This cache key should be consistent across all versions of langchain.
|
|
5
5
|
* It is currently NOT consistent across versions of langchain.
|
package/dist/caches.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { insecureHash } from "./utils/hash.js";
|
|
2
|
-
import { mapStoredMessageToChatMessage
|
|
2
|
+
import { mapStoredMessageToChatMessage } from "./messages/utils.js";
|
|
3
3
|
/**
|
|
4
4
|
* This cache key should be consistent across all versions of langchain.
|
|
5
5
|
* It is currently NOT consistent across versions of langchain.
|
package/dist/callbacks/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChainValues } from "../utils/types/index.js";
|
|
2
|
-
import type { BaseMessage } from "../messages/
|
|
2
|
+
import type { BaseMessage } from "../messages/base.js";
|
|
3
3
|
import type { AgentAction, AgentFinish } from "../agents.js";
|
|
4
4
|
import type { ChatGenerationChunk, GenerationChunk, LLMResult } from "../outputs.js";
|
|
5
5
|
import { Serializable, Serialized, SerializedNotImplemented } from "../load/serializable.js";
|
|
@@ -5,7 +5,7 @@ const uuid_1 = require("uuid");
|
|
|
5
5
|
const base_js_1 = require("./base.cjs");
|
|
6
6
|
const console_js_1 = require("../tracers/console.cjs");
|
|
7
7
|
const initialize_js_1 = require("../tracers/initialize.cjs");
|
|
8
|
-
const
|
|
8
|
+
const utils_js_1 = require("../messages/utils.cjs");
|
|
9
9
|
const env_js_1 = require("../utils/env.cjs");
|
|
10
10
|
const tracer_langchain_js_1 = require("../tracers/tracer_langchain.cjs");
|
|
11
11
|
const promises_js_1 = require("./promises.cjs");
|
|
@@ -439,7 +439,7 @@ class CallbackManager extends BaseCallbackManager {
|
|
|
439
439
|
await handler.handleChatModelStart?.(llm, [messageGroup], runId_, this._parentRunId, extraParams, this.tags, this.metadata, runName);
|
|
440
440
|
}
|
|
441
441
|
else if (handler.handleLLMStart) {
|
|
442
|
-
const messageString = (0,
|
|
442
|
+
const messageString = (0, utils_js_1.getBufferString)(messageGroup);
|
|
443
443
|
await handler.handleLLMStart?.(llm, [messageString], runId_, this._parentRunId, extraParams, this.tags, this.metadata, runName);
|
|
444
444
|
}
|
|
445
445
|
}
|
|
@@ -2,7 +2,7 @@ import { AgentAction, AgentFinish } from "../agents.js";
|
|
|
2
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
|
-
import { type BaseMessage } from "../messages/
|
|
5
|
+
import { type BaseMessage } from "../messages/base.js";
|
|
6
6
|
import { LangChainTracerFields } from "../tracers/tracer_langchain.js";
|
|
7
7
|
import { Serialized } from "../load/serializable.js";
|
|
8
8
|
import type { DocumentInterface } from "../documents/document.js";
|
|
@@ -2,7 +2,7 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
2
2
|
import { BaseCallbackHandler, } from "./base.js";
|
|
3
3
|
import { ConsoleCallbackHandler } from "../tracers/console.js";
|
|
4
4
|
import { getTracingV2CallbackHandler } from "../tracers/initialize.js";
|
|
5
|
-
import { getBufferString } from "../messages/
|
|
5
|
+
import { getBufferString } from "../messages/utils.js";
|
|
6
6
|
import { getEnvironmentVariable } from "../utils/env.js";
|
|
7
7
|
import { LangChainTracer, } from "../tracers/tracer_langchain.js";
|
|
8
8
|
import { consumeCallback } from "./promises.js";
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseLanguageModel = exports.BaseLangChain = exports.calculateMaxTokens = exports.getModelContextSize = exports.getEmbeddingContextSize = exports.getModelNameForTiktoken = void 0;
|
|
4
4
|
const caches_js_1 = require("../caches.cjs");
|
|
5
5
|
const prompt_values_js_1 = require("../prompt_values.cjs");
|
|
6
|
-
const
|
|
6
|
+
const utils_js_1 = require("../messages/utils.cjs");
|
|
7
7
|
const async_caller_js_1 = require("../utils/async_caller.cjs");
|
|
8
8
|
const tiktoken_js_1 = require("../utils/tiktoken.cjs");
|
|
9
9
|
const base_js_1 = require("../runnables/base.cjs");
|
|
@@ -205,7 +205,7 @@ class BaseLanguageModel extends BaseLangChain {
|
|
|
205
205
|
return new prompt_values_js_1.StringPromptValue(input);
|
|
206
206
|
}
|
|
207
207
|
else if (Array.isArray(input)) {
|
|
208
|
-
return new prompt_values_js_1.ChatPromptValue(input.map(
|
|
208
|
+
return new prompt_values_js_1.ChatPromptValue(input.map(utils_js_1.coerceMessageLikeToMessage));
|
|
209
209
|
}
|
|
210
210
|
else {
|
|
211
211
|
return input;
|
|
@@ -2,7 +2,7 @@ import type { TiktokenModel } from "js-tiktoken/lite";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { type BaseCache } from "../caches.js";
|
|
4
4
|
import { type BasePromptValueInterface } from "../prompt_values.js";
|
|
5
|
-
import { type BaseMessage, type BaseMessageLike, type MessageContent } from "../messages/
|
|
5
|
+
import { type BaseMessage, type BaseMessageLike, type MessageContent } from "../messages/base.js";
|
|
6
6
|
import { type LLMResult } from "../outputs.js";
|
|
7
7
|
import { CallbackManager, Callbacks } from "../callbacks/manager.js";
|
|
8
8
|
import { AsyncCaller, AsyncCallerParams } from "../utils/async_caller.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InMemoryCache } from "../caches.js";
|
|
2
2
|
import { StringPromptValue, ChatPromptValue, } from "../prompt_values.js";
|
|
3
|
-
import { coerceMessageLikeToMessage
|
|
3
|
+
import { coerceMessageLikeToMessage } from "../messages/utils.js";
|
|
4
4
|
import { AsyncCaller } from "../utils/async_caller.js";
|
|
5
5
|
import { encodingForModel } from "../utils/tiktoken.js";
|
|
6
6
|
import { Runnable } from "../runnables/base.js";
|
package/dist/messages/ai.cjs
CHANGED
|
@@ -122,7 +122,7 @@ class AIMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
122
122
|
else if (fields.tool_call_chunks === undefined) {
|
|
123
123
|
initParams = {
|
|
124
124
|
...fields,
|
|
125
|
-
tool_calls: [],
|
|
125
|
+
tool_calls: fields.tool_calls ?? [],
|
|
126
126
|
invalid_tool_calls: [],
|
|
127
127
|
tool_call_chunks: [],
|
|
128
128
|
};
|
|
@@ -219,6 +219,7 @@ class AIMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
219
219
|
additional_kwargs: (0, base_js_1._mergeDicts)(this.additional_kwargs, chunk.additional_kwargs),
|
|
220
220
|
response_metadata: (0, base_js_1._mergeDicts)(this.response_metadata, chunk.response_metadata),
|
|
221
221
|
tool_call_chunks: [],
|
|
222
|
+
id: this.id ?? chunk.id,
|
|
222
223
|
};
|
|
223
224
|
if (this.tool_call_chunks !== undefined ||
|
|
224
225
|
chunk.tool_call_chunks !== undefined) {
|
package/dist/messages/ai.js
CHANGED
|
@@ -117,7 +117,7 @@ export class AIMessageChunk extends BaseMessageChunk {
|
|
|
117
117
|
else if (fields.tool_call_chunks === undefined) {
|
|
118
118
|
initParams = {
|
|
119
119
|
...fields,
|
|
120
|
-
tool_calls: [],
|
|
120
|
+
tool_calls: fields.tool_calls ?? [],
|
|
121
121
|
invalid_tool_calls: [],
|
|
122
122
|
tool_call_chunks: [],
|
|
123
123
|
};
|
|
@@ -214,6 +214,7 @@ export class AIMessageChunk extends BaseMessageChunk {
|
|
|
214
214
|
additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
|
|
215
215
|
response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
|
|
216
216
|
tool_call_chunks: [],
|
|
217
|
+
id: this.id ?? chunk.id,
|
|
217
218
|
};
|
|
218
219
|
if (this.tool_call_chunks !== undefined ||
|
|
219
220
|
chunk.tool_call_chunks !== undefined) {
|
package/dist/messages/base.cjs
CHANGED
|
@@ -104,10 +104,21 @@ class BaseMessage extends serializable_js_1.Serializable {
|
|
|
104
104
|
writable: true,
|
|
105
105
|
value: void 0
|
|
106
106
|
});
|
|
107
|
+
/**
|
|
108
|
+
* An optional unique identifier for the message. This should ideally be
|
|
109
|
+
* provided by the provider/model which created the message.
|
|
110
|
+
*/
|
|
111
|
+
Object.defineProperty(this, "id", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
configurable: true,
|
|
114
|
+
writable: true,
|
|
115
|
+
value: void 0
|
|
116
|
+
});
|
|
107
117
|
this.name = fields.name;
|
|
108
118
|
this.content = fields.content;
|
|
109
119
|
this.additional_kwargs = fields.additional_kwargs;
|
|
110
120
|
this.response_metadata = fields.response_metadata;
|
|
121
|
+
this.id = fields.id;
|
|
111
122
|
}
|
|
112
123
|
toDict() {
|
|
113
124
|
return {
|
package/dist/messages/base.d.ts
CHANGED
|
@@ -82,6 +82,11 @@ export type BaseMessageFields = {
|
|
|
82
82
|
};
|
|
83
83
|
/** Response metadata. For example: response headers, logprobs, token counts. */
|
|
84
84
|
response_metadata?: Record<string, any>;
|
|
85
|
+
/**
|
|
86
|
+
* An optional unique identifier for the message. This should ideally be
|
|
87
|
+
* provided by the provider/model which created the message.
|
|
88
|
+
*/
|
|
89
|
+
id?: string;
|
|
85
90
|
};
|
|
86
91
|
export declare function mergeContent(firstContent: MessageContent, secondContent: MessageContent): MessageContent;
|
|
87
92
|
/**
|
|
@@ -106,6 +111,11 @@ export declare abstract class BaseMessage extends Serializable implements BaseMe
|
|
|
106
111
|
additional_kwargs: NonNullable<BaseMessageFields["additional_kwargs"]>;
|
|
107
112
|
/** Response metadata. For example: response headers, logprobs, token counts. */
|
|
108
113
|
response_metadata: NonNullable<BaseMessageFields["response_metadata"]>;
|
|
114
|
+
/**
|
|
115
|
+
* An optional unique identifier for the message. This should ideally be
|
|
116
|
+
* provided by the provider/model which created the message.
|
|
117
|
+
*/
|
|
118
|
+
id?: string;
|
|
109
119
|
/** The type of the message. */
|
|
110
120
|
abstract _getType(): MessageType;
|
|
111
121
|
constructor(fields: string | BaseMessageFields,
|
package/dist/messages/base.js
CHANGED
|
@@ -100,10 +100,21 @@ export class BaseMessage extends Serializable {
|
|
|
100
100
|
writable: true,
|
|
101
101
|
value: void 0
|
|
102
102
|
});
|
|
103
|
+
/**
|
|
104
|
+
* An optional unique identifier for the message. This should ideally be
|
|
105
|
+
* provided by the provider/model which created the message.
|
|
106
|
+
*/
|
|
107
|
+
Object.defineProperty(this, "id", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: void 0
|
|
112
|
+
});
|
|
103
113
|
this.name = fields.name;
|
|
104
114
|
this.content = fields.content;
|
|
105
115
|
this.additional_kwargs = fields.additional_kwargs;
|
|
106
116
|
this.response_metadata = fields.response_metadata;
|
|
117
|
+
this.id = fields.id;
|
|
107
118
|
}
|
|
108
119
|
toDict() {
|
|
109
120
|
return {
|
package/dist/messages/chat.cjs
CHANGED
|
@@ -65,6 +65,7 @@ class ChatMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
65
65
|
additional_kwargs: (0, base_js_1._mergeDicts)(this.additional_kwargs, chunk.additional_kwargs),
|
|
66
66
|
response_metadata: (0, base_js_1._mergeDicts)(this.response_metadata, chunk.response_metadata),
|
|
67
67
|
role: this.role,
|
|
68
|
+
id: this.id ?? chunk.id,
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
}
|
package/dist/messages/chat.js
CHANGED
|
@@ -61,6 +61,7 @@ export class ChatMessageChunk extends BaseMessageChunk {
|
|
|
61
61
|
additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
|
|
62
62
|
response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
|
|
63
63
|
role: this.role,
|
|
64
|
+
id: this.id ?? chunk.id,
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
}
|
|
@@ -40,6 +40,7 @@ class FunctionMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
40
40
|
additional_kwargs: (0, base_js_1._mergeDicts)(this.additional_kwargs, chunk.additional_kwargs),
|
|
41
41
|
response_metadata: (0, base_js_1._mergeDicts)(this.response_metadata, chunk.response_metadata),
|
|
42
42
|
name: this.name ?? "",
|
|
43
|
+
id: this.id ?? chunk.id,
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -36,6 +36,7 @@ export class FunctionMessageChunk extends BaseMessageChunk {
|
|
|
36
36
|
additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
|
|
37
37
|
response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
|
|
38
38
|
name: this.name ?? "",
|
|
39
|
+
id: this.id ?? chunk.id,
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
42
|
}
|
package/dist/messages/human.cjs
CHANGED
|
@@ -30,6 +30,7 @@ class HumanMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
30
30
|
content: (0, base_js_1.mergeContent)(this.content, chunk.content),
|
|
31
31
|
additional_kwargs: (0, base_js_1._mergeDicts)(this.additional_kwargs, chunk.additional_kwargs),
|
|
32
32
|
response_metadata: (0, base_js_1._mergeDicts)(this.response_metadata, chunk.response_metadata),
|
|
33
|
+
id: this.id ?? chunk.id,
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
}
|
package/dist/messages/human.js
CHANGED
|
@@ -26,6 +26,7 @@ export class HumanMessageChunk extends BaseMessageChunk {
|
|
|
26
26
|
content: mergeContent(this.content, chunk.content),
|
|
27
27
|
additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
|
|
28
28
|
response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
|
|
29
|
+
id: this.id ?? chunk.id,
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
}
|
package/dist/messages/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ __exportStar(require("./function.cjs"), exports);
|
|
|
22
22
|
__exportStar(require("./human.cjs"), exports);
|
|
23
23
|
__exportStar(require("./system.cjs"), exports);
|
|
24
24
|
__exportStar(require("./utils.cjs"), exports);
|
|
25
|
+
__exportStar(require("./transformers.cjs"), exports);
|
|
25
26
|
// TODO: Use a star export when we deprecate the
|
|
26
27
|
// existing "ToolCall" type in "base.js".
|
|
27
28
|
var tool_js_1 = require("./tool.cjs");
|
package/dist/messages/index.d.ts
CHANGED
package/dist/messages/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./function.js";
|
|
|
5
5
|
export * from "./human.js";
|
|
6
6
|
export * from "./system.js";
|
|
7
7
|
export * from "./utils.js";
|
|
8
|
+
export * from "./transformers.js";
|
|
8
9
|
// TODO: Use a star export when we deprecate the
|
|
9
10
|
// existing "ToolCall" type in "base.js".
|
|
10
11
|
export { ToolMessage, ToolMessageChunk, } from "./tool.js";
|
package/dist/messages/system.cjs
CHANGED
|
@@ -30,6 +30,7 @@ class SystemMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
30
30
|
content: (0, base_js_1.mergeContent)(this.content, chunk.content),
|
|
31
31
|
additional_kwargs: (0, base_js_1._mergeDicts)(this.additional_kwargs, chunk.additional_kwargs),
|
|
32
32
|
response_metadata: (0, base_js_1._mergeDicts)(this.response_metadata, chunk.response_metadata),
|
|
33
|
+
id: this.id ?? chunk.id,
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
}
|
package/dist/messages/system.js
CHANGED
|
@@ -26,6 +26,7 @@ export class SystemMessageChunk extends BaseMessageChunk {
|
|
|
26
26
|
content: mergeContent(this.content, chunk.content),
|
|
27
27
|
additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
|
|
28
28
|
response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
|
|
29
|
+
id: this.id ?? chunk.id,
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|