langchain 0.0.194 → 0.0.196
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/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
- package/dist/base_language/count_tokens.cjs +5 -70
- package/dist/base_language/count_tokens.d.ts +1 -10
- package/dist/base_language/count_tokens.js +1 -65
- package/dist/base_language/index.cjs +6 -196
- package/dist/base_language/index.d.ts +1 -111
- package/dist/base_language/index.js +1 -191
- package/dist/cache/base.cjs +15 -37
- package/dist/cache/base.d.ts +1 -20
- package/dist/cache/base.js +1 -33
- package/dist/cache/index.cjs +2 -46
- package/dist/cache/index.d.ts +1 -29
- package/dist/cache/index.js +1 -45
- package/dist/callbacks/base.cjs +3 -139
- package/dist/callbacks/base.d.ts +1 -266
- package/dist/callbacks/base.js +1 -126
- package/dist/callbacks/handlers/console.cjs +14 -221
- package/dist/callbacks/handlers/console.d.ts +1 -117
- package/dist/callbacks/handlers/console.js +1 -217
- package/dist/callbacks/handlers/initialize.cjs +15 -30
- package/dist/callbacks/handlers/initialize.d.ts +1 -16
- package/dist/callbacks/handlers/initialize.js +1 -27
- package/dist/callbacks/handlers/log_stream.cjs +15 -293
- package/dist/callbacks/handlers/log_stream.d.ts +1 -100
- package/dist/callbacks/handlers/log_stream.js +1 -289
- package/dist/callbacks/handlers/run_collector.cjs +15 -48
- package/dist/callbacks/handlers/run_collector.d.ts +1 -26
- package/dist/callbacks/handlers/run_collector.js +1 -46
- package/dist/callbacks/handlers/tracer.cjs +15 -375
- package/dist/callbacks/handlers/tracer.d.ts +1 -70
- package/dist/callbacks/handlers/tracer.js +1 -373
- package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
- package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
- package/dist/callbacks/handlers/tracer_langchain.js +1 -102
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
- package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
- package/dist/callbacks/manager.cjs +15 -676
- package/dist/callbacks/manager.d.ts +1 -180
- package/dist/callbacks/manager.js +1 -666
- package/dist/callbacks/promises.cjs +14 -42
- package/dist/callbacks/promises.d.ts +1 -11
- package/dist/callbacks/promises.js +1 -37
- package/dist/chains/graph_qa/prompts.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.js +1 -1
- package/dist/chat_models/baiduwenxin.d.ts +1 -1
- package/dist/chat_models/base.cjs +15 -296
- package/dist/chat_models/base.d.ts +1 -122
- package/dist/chat_models/base.js +1 -292
- package/dist/chat_models/bedrock/web.d.ts +1 -1
- package/dist/chat_models/fireworks.d.ts +1 -1
- package/dist/document.cjs +2 -24
- package/dist/document.d.ts +1 -12
- package/dist/document.js +1 -23
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
- package/dist/document_loaders/web/s3.d.ts +1 -1
- package/dist/embeddings/base.cjs +15 -22
- package/dist/embeddings/base.d.ts +1 -33
- package/dist/embeddings/base.js +1 -20
- package/dist/embeddings/cache_backed.cjs +2 -2
- package/dist/embeddings/cache_backed.js +1 -1
- package/dist/embeddings/hf.cjs +1 -2
- package/dist/embeddings/hf.js +1 -2
- package/dist/evaluation/agents/trajectory.d.ts +1 -1
- package/dist/evaluation/criteria/prompt.d.ts +2 -2
- package/dist/evaluation/qa/prompt.d.ts +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
- package/dist/experimental/openai_assistant/index.cjs +2 -1
- package/dist/experimental/openai_assistant/index.d.ts +2 -1
- package/dist/experimental/openai_assistant/index.js +2 -1
- package/dist/experimental/openai_files/index.cjs +88 -0
- package/dist/experimental/openai_files/index.d.ts +79 -0
- package/dist/experimental/openai_files/index.js +84 -0
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
- package/dist/llms/base.cjs +15 -278
- package/dist/llms/base.d.ts +1 -115
- package/dist/llms/base.js +1 -275
- package/dist/llms/bedrock/web.d.ts +1 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +4 -2
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/load/index.cjs +7 -148
- package/dist/load/index.js +7 -148
- package/dist/load/map_keys.cjs +0 -24
- package/dist/load/map_keys.d.ts +0 -6
- package/dist/load/map_keys.js +1 -17
- package/dist/load/serializable.cjs +15 -178
- package/dist/load/serializable.d.ts +1 -66
- package/dist/load/serializable.js +1 -175
- package/dist/memory/base.cjs +17 -92
- package/dist/memory/base.d.ts +2 -68
- package/dist/memory/base.js +2 -87
- package/dist/output_parsers/openai_functions.cjs +2 -2
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_functions.js +1 -1
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/prompts/base.cjs +8 -183
- package/dist/prompts/base.d.ts +3 -132
- package/dist/prompts/base.js +3 -178
- package/dist/prompts/chat.cjs +15 -477
- package/dist/prompts/chat.d.ts +1 -219
- package/dist/prompts/chat.js +1 -466
- package/dist/prompts/few_shot.cjs +15 -353
- package/dist/prompts/few_shot.d.ts +1 -192
- package/dist/prompts/few_shot.js +1 -350
- package/dist/prompts/index.cjs +3 -2
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/pipeline.cjs +15 -142
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +15 -146
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
- package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
- package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
- package/dist/prompts/selectors/conditional.cjs +15 -74
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.cjs +15 -0
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/serde.js +1 -1
- package/dist/prompts/template.cjs +14 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- package/dist/retrievers/chaindesk.cjs +9 -1
- package/dist/retrievers/chaindesk.d.ts +3 -1
- package/dist/retrievers/chaindesk.js +9 -1
- package/dist/retrievers/self_query/vectara.cjs +138 -0
- package/dist/retrievers/self_query/vectara.d.ts +41 -0
- package/dist/retrievers/self_query/vectara.js +134 -0
- package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
- package/dist/runnables/index.d.ts +1 -0
- package/dist/runnables/index.js +1 -0
- package/dist/schema/document.cjs +3 -34
- package/dist/schema/document.d.ts +2 -29
- package/dist/schema/document.js +2 -32
- package/dist/schema/index.cjs +37 -612
- package/dist/schema/index.d.ts +11 -311
- package/dist/schema/index.js +8 -583
- package/dist/schema/output_parser.cjs +15 -309
- package/dist/schema/output_parser.d.ts +1 -173
- package/dist/schema/output_parser.js +1 -301
- package/dist/schema/retriever.cjs +15 -77
- package/dist/schema/retriever.d.ts +1 -43
- package/dist/schema/retriever.js +1 -75
- package/dist/schema/runnable/base.cjs +10 -1072
- package/dist/schema/runnable/base.d.ts +1 -356
- package/dist/schema/runnable/base.js +1 -1060
- package/dist/schema/runnable/branch.cjs +2 -131
- package/dist/schema/runnable/branch.d.ts +1 -94
- package/dist/schema/runnable/branch.js +1 -130
- package/dist/schema/runnable/config.cjs +0 -6
- package/dist/schema/runnable/config.d.ts +1 -3
- package/dist/schema/runnable/config.js +1 -4
- package/dist/schema/runnable/index.cjs +15 -16
- package/dist/schema/runnable/index.d.ts +1 -5
- package/dist/schema/runnable/index.js +1 -4
- package/dist/schema/runnable/passthrough.cjs +3 -113
- package/dist/schema/runnable/passthrough.d.ts +1 -72
- package/dist/schema/runnable/passthrough.js +1 -111
- package/dist/schema/runnable/router.cjs +2 -71
- package/dist/schema/runnable/router.d.ts +1 -29
- package/dist/schema/runnable/router.js +1 -70
- package/dist/schema/storage.cjs +15 -8
- package/dist/schema/storage.d.ts +1 -57
- package/dist/schema/storage.js +1 -6
- package/dist/tools/bingserpapi.d.ts +1 -1
- package/dist/tools/searchapi.d.ts +1 -1
- package/dist/tools/serpapi.d.ts +1 -1
- package/dist/tools/serper.d.ts +1 -1
- package/dist/util/async_caller.cjs +14 -128
- package/dist/util/async_caller.d.ts +1 -45
- package/dist/util/async_caller.js +1 -124
- package/dist/vectorstores/vectara.cjs +77 -7
- package/dist/vectorstores/vectara.d.ts +9 -3
- package/dist/vectorstores/vectara.js +54 -7
- package/experimental/openai_files.cjs +1 -0
- package/experimental/openai_files.d.ts +1 -0
- package/experimental/openai_files.js +1 -0
- package/package.json +27 -5
- package/retrievers/self_query/vectara.cjs +1 -0
- package/retrievers/self_query/vectara.d.ts +1 -0
- package/retrievers/self_query/vectara.js +1 -0
- package/runnables.cjs +1 -0
- package/runnables.d.ts +1 -0
- package/runnables.js +1 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/index.js +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
- package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
- package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
- package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/format.js +0 -136
- package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
- package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
- package/dist/util/@cfworker/json-schema/src/index.js +0 -8
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
- package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
- package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
- package/dist/util/@cfworker/json-schema/src/types.js +0 -1
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
- package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
- package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
- package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
- package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
- package/dist/util/fast-json-patch/index.cjs +0 -49
- package/dist/util/fast-json-patch/index.d.ts +0 -22
- package/dist/util/fast-json-patch/index.js +0 -16
- package/dist/util/fast-json-patch/src/core.cjs +0 -469
- package/dist/util/fast-json-patch/src/core.d.ts +0 -111
- package/dist/util/fast-json-patch/src/core.js +0 -459
- package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
- package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
- package/dist/util/fast-json-patch/src/duplex.js +0 -230
- package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
- package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
- package/dist/util/fast-json-patch/src/helpers.js +0 -181
- package/dist/util/js-sha1/hash.cjs +0 -358
- package/dist/util/js-sha1/hash.d.ts +0 -1
- package/dist/util/js-sha1/hash.js +0 -355
|
@@ -1,289 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseTracer } from "./tracer.js";
|
|
3
|
-
import { IterableReadableStream } from "../../util/stream.js";
|
|
4
|
-
/**
|
|
5
|
-
* List of jsonpatch JSONPatchOperations, which describe how to create the run state
|
|
6
|
-
* from an empty dict. This is the minimal representation of the log, designed to
|
|
7
|
-
* be serialized as JSON and sent over the wire to reconstruct the log on the other
|
|
8
|
-
* side. Reconstruction of the state can be done with any jsonpatch-compliant library,
|
|
9
|
-
* see https://jsonpatch.com for more information.
|
|
10
|
-
*/
|
|
11
|
-
export class RunLogPatch {
|
|
12
|
-
constructor(fields) {
|
|
13
|
-
Object.defineProperty(this, "ops", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: void 0
|
|
18
|
-
});
|
|
19
|
-
this.ops = fields.ops;
|
|
20
|
-
}
|
|
21
|
-
concat(other) {
|
|
22
|
-
const ops = this.ops.concat(other.ops);
|
|
23
|
-
const states = applyPatch({}, ops);
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
25
|
-
return new RunLog({
|
|
26
|
-
ops,
|
|
27
|
-
state: states[states.length - 1].newDocument,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export class RunLog extends RunLogPatch {
|
|
32
|
-
constructor(fields) {
|
|
33
|
-
super(fields);
|
|
34
|
-
Object.defineProperty(this, "state", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true,
|
|
38
|
-
value: void 0
|
|
39
|
-
});
|
|
40
|
-
this.state = fields.state;
|
|
41
|
-
}
|
|
42
|
-
concat(other) {
|
|
43
|
-
const ops = this.ops.concat(other.ops);
|
|
44
|
-
const states = applyPatch(this.state, other.ops);
|
|
45
|
-
return new RunLog({ ops, state: states[states.length - 1].newDocument });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Class that extends the `BaseTracer` class from the
|
|
50
|
-
* `langchain.callbacks.tracers.base` module. It represents a callback
|
|
51
|
-
* handler that logs the execution of runs and emits `RunLog` instances to a
|
|
52
|
-
* `RunLogStream`.
|
|
53
|
-
*/
|
|
54
|
-
export class LogStreamCallbackHandler extends BaseTracer {
|
|
55
|
-
constructor(fields) {
|
|
56
|
-
super(fields);
|
|
57
|
-
Object.defineProperty(this, "autoClose", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: true
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(this, "includeNames", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: void 0
|
|
68
|
-
});
|
|
69
|
-
Object.defineProperty(this, "includeTypes", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: true,
|
|
72
|
-
writable: true,
|
|
73
|
-
value: void 0
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(this, "includeTags", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
writable: true,
|
|
79
|
-
value: void 0
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(this, "excludeNames", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
value: void 0
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(this, "excludeTypes", {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
configurable: true,
|
|
90
|
-
writable: true,
|
|
91
|
-
value: void 0
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(this, "excludeTags", {
|
|
94
|
-
enumerable: true,
|
|
95
|
-
configurable: true,
|
|
96
|
-
writable: true,
|
|
97
|
-
value: void 0
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(this, "keyMapByRunId", {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
configurable: true,
|
|
102
|
-
writable: true,
|
|
103
|
-
value: {}
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(this, "counterMapByRunName", {
|
|
106
|
-
enumerable: true,
|
|
107
|
-
configurable: true,
|
|
108
|
-
writable: true,
|
|
109
|
-
value: {}
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(this, "transformStream", {
|
|
112
|
-
enumerable: true,
|
|
113
|
-
configurable: true,
|
|
114
|
-
writable: true,
|
|
115
|
-
value: void 0
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperty(this, "writer", {
|
|
118
|
-
enumerable: true,
|
|
119
|
-
configurable: true,
|
|
120
|
-
writable: true,
|
|
121
|
-
value: void 0
|
|
122
|
-
});
|
|
123
|
-
Object.defineProperty(this, "receiveStream", {
|
|
124
|
-
enumerable: true,
|
|
125
|
-
configurable: true,
|
|
126
|
-
writable: true,
|
|
127
|
-
value: void 0
|
|
128
|
-
});
|
|
129
|
-
Object.defineProperty(this, "name", {
|
|
130
|
-
enumerable: true,
|
|
131
|
-
configurable: true,
|
|
132
|
-
writable: true,
|
|
133
|
-
value: "log_stream_tracer"
|
|
134
|
-
});
|
|
135
|
-
this.autoClose = fields?.autoClose ?? true;
|
|
136
|
-
this.includeNames = fields?.includeNames;
|
|
137
|
-
this.includeTypes = fields?.includeTypes;
|
|
138
|
-
this.includeTags = fields?.includeTags;
|
|
139
|
-
this.excludeNames = fields?.excludeNames;
|
|
140
|
-
this.excludeTypes = fields?.excludeTypes;
|
|
141
|
-
this.excludeTags = fields?.excludeTags;
|
|
142
|
-
this.transformStream = new TransformStream();
|
|
143
|
-
this.writer = this.transformStream.writable.getWriter();
|
|
144
|
-
this.receiveStream = IterableReadableStream.fromReadableStream(this.transformStream.readable);
|
|
145
|
-
}
|
|
146
|
-
[Symbol.asyncIterator]() {
|
|
147
|
-
return this.receiveStream;
|
|
148
|
-
}
|
|
149
|
-
async persistRun(_run) {
|
|
150
|
-
// This is a legacy method only called once for an entire run tree
|
|
151
|
-
// and is therefore not useful here
|
|
152
|
-
}
|
|
153
|
-
_includeRun(run) {
|
|
154
|
-
if (run.parent_run_id === undefined) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
const runTags = run.tags ?? [];
|
|
158
|
-
let include = this.includeNames === undefined &&
|
|
159
|
-
this.includeTags === undefined &&
|
|
160
|
-
this.includeTypes === undefined;
|
|
161
|
-
if (this.includeNames !== undefined) {
|
|
162
|
-
include = include || this.includeNames.includes(run.name);
|
|
163
|
-
}
|
|
164
|
-
if (this.includeTypes !== undefined) {
|
|
165
|
-
include = include || this.includeTypes.includes(run.run_type);
|
|
166
|
-
}
|
|
167
|
-
if (this.includeTags !== undefined) {
|
|
168
|
-
include =
|
|
169
|
-
include ||
|
|
170
|
-
runTags.find((tag) => this.includeTags?.includes(tag)) !== undefined;
|
|
171
|
-
}
|
|
172
|
-
if (this.excludeNames !== undefined) {
|
|
173
|
-
include = include && !this.excludeNames.includes(run.name);
|
|
174
|
-
}
|
|
175
|
-
if (this.excludeTypes !== undefined) {
|
|
176
|
-
include = include && !this.excludeTypes.includes(run.run_type);
|
|
177
|
-
}
|
|
178
|
-
if (this.excludeTags !== undefined) {
|
|
179
|
-
include =
|
|
180
|
-
include && runTags.every((tag) => !this.excludeTags?.includes(tag));
|
|
181
|
-
}
|
|
182
|
-
return include;
|
|
183
|
-
}
|
|
184
|
-
async onRunCreate(run) {
|
|
185
|
-
if (run.parent_run_id === undefined) {
|
|
186
|
-
await this.writer.write(new RunLogPatch({
|
|
187
|
-
ops: [
|
|
188
|
-
{
|
|
189
|
-
op: "replace",
|
|
190
|
-
path: "",
|
|
191
|
-
value: {
|
|
192
|
-
id: run.id,
|
|
193
|
-
streamed_output: [],
|
|
194
|
-
final_output: undefined,
|
|
195
|
-
logs: {},
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
}));
|
|
200
|
-
}
|
|
201
|
-
if (!this._includeRun(run)) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (this.counterMapByRunName[run.name] === undefined) {
|
|
205
|
-
this.counterMapByRunName[run.name] = 0;
|
|
206
|
-
}
|
|
207
|
-
this.counterMapByRunName[run.name] += 1;
|
|
208
|
-
const count = this.counterMapByRunName[run.name];
|
|
209
|
-
this.keyMapByRunId[run.id] =
|
|
210
|
-
count === 1 ? run.name : `${run.name}:${count}`;
|
|
211
|
-
const logEntry = {
|
|
212
|
-
id: run.id,
|
|
213
|
-
name: run.name,
|
|
214
|
-
type: run.run_type,
|
|
215
|
-
tags: run.tags ?? [],
|
|
216
|
-
metadata: run.extra?.metadata ?? {},
|
|
217
|
-
start_time: new Date(run.start_time).toISOString(),
|
|
218
|
-
streamed_output_str: [],
|
|
219
|
-
final_output: undefined,
|
|
220
|
-
end_time: undefined,
|
|
221
|
-
};
|
|
222
|
-
await this.writer.write(new RunLogPatch({
|
|
223
|
-
ops: [
|
|
224
|
-
{
|
|
225
|
-
op: "add",
|
|
226
|
-
path: `/logs/${this.keyMapByRunId[run.id]}`,
|
|
227
|
-
value: logEntry,
|
|
228
|
-
},
|
|
229
|
-
],
|
|
230
|
-
}));
|
|
231
|
-
}
|
|
232
|
-
async onRunUpdate(run) {
|
|
233
|
-
try {
|
|
234
|
-
const runName = this.keyMapByRunId[run.id];
|
|
235
|
-
if (runName === undefined) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const ops = [
|
|
239
|
-
{
|
|
240
|
-
op: "add",
|
|
241
|
-
path: `/logs/${runName}/final_output`,
|
|
242
|
-
value: run.outputs,
|
|
243
|
-
},
|
|
244
|
-
];
|
|
245
|
-
if (run.end_time !== undefined) {
|
|
246
|
-
ops.push({
|
|
247
|
-
op: "add",
|
|
248
|
-
path: `/logs/${runName}/end_time`,
|
|
249
|
-
value: new Date(run.end_time).toISOString(),
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
const patch = new RunLogPatch({ ops });
|
|
253
|
-
await this.writer.write(patch);
|
|
254
|
-
}
|
|
255
|
-
finally {
|
|
256
|
-
if (run.parent_run_id === undefined) {
|
|
257
|
-
const patch = new RunLogPatch({
|
|
258
|
-
ops: [
|
|
259
|
-
{
|
|
260
|
-
op: "replace",
|
|
261
|
-
path: "/final_output",
|
|
262
|
-
value: run.outputs,
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
});
|
|
266
|
-
await this.writer.write(patch);
|
|
267
|
-
if (this.autoClose) {
|
|
268
|
-
await this.writer.close();
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
async onLLMNewToken(run, token) {
|
|
274
|
-
const runName = this.keyMapByRunId[run.id];
|
|
275
|
-
if (runName === undefined) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const patch = new RunLogPatch({
|
|
279
|
-
ops: [
|
|
280
|
-
{
|
|
281
|
-
op: "add",
|
|
282
|
-
path: `/logs/${runName}/streamed_output_str/-`,
|
|
283
|
-
value: token,
|
|
284
|
-
},
|
|
285
|
-
],
|
|
286
|
-
});
|
|
287
|
-
await this.writer.write(patch);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
1
|
+
export * from "langchain-core/callbacks/tracers/log_stream";
|
|
@@ -1,50 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* For instance, it makes it easy to fetch the run ID and then do things with that, such as log feedback.
|
|
8
|
-
*/
|
|
9
|
-
class RunCollectorCallbackHandler extends tracer_js_1.BaseTracer {
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new instance of the RunCollectorCallbackHandler class.
|
|
12
|
-
* @param exampleId The ID of the example.
|
|
13
|
-
*/
|
|
14
|
-
constructor({ exampleId } = {}) {
|
|
15
|
-
super();
|
|
16
|
-
/** The name of the callback handler. */
|
|
17
|
-
Object.defineProperty(this, "name", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: "run_collector"
|
|
22
|
-
});
|
|
23
|
-
/** The ID of the example. */
|
|
24
|
-
Object.defineProperty(this, "exampleId", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: void 0
|
|
29
|
-
});
|
|
30
|
-
/** An array of traced runs. */
|
|
31
|
-
Object.defineProperty(this, "tracedRuns", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: void 0
|
|
36
|
-
});
|
|
37
|
-
this.exampleId = exampleId;
|
|
38
|
-
this.tracedRuns = [];
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Persists the given run object.
|
|
42
|
-
* @param run The run object to persist.
|
|
43
|
-
*/
|
|
44
|
-
async persistRun(run) {
|
|
45
|
-
const run_ = { ...run };
|
|
46
|
-
run_.reference_example_id = this.exampleId;
|
|
47
|
-
this.tracedRuns.push(run_);
|
|
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]; } };
|
|
48
7
|
}
|
|
49
|
-
|
|
50
|
-
|
|
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("langchain-core/callbacks/tracers/run_collector"), exports);
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseTracer } from "./tracer.js";
|
|
3
|
-
/**
|
|
4
|
-
* A callback handler that collects traced runs and makes it easy to fetch the traced run object from calls through any langchain object.
|
|
5
|
-
* For instance, it makes it easy to fetch the run ID and then do things with that, such as log feedback.
|
|
6
|
-
*/
|
|
7
|
-
export declare class RunCollectorCallbackHandler extends BaseTracer {
|
|
8
|
-
/** The name of the callback handler. */
|
|
9
|
-
name: string;
|
|
10
|
-
/** The ID of the example. */
|
|
11
|
-
exampleId?: string;
|
|
12
|
-
/** An array of traced runs. */
|
|
13
|
-
tracedRuns: Run[];
|
|
14
|
-
/**
|
|
15
|
-
* Creates a new instance of the RunCollectorCallbackHandler class.
|
|
16
|
-
* @param exampleId The ID of the example.
|
|
17
|
-
*/
|
|
18
|
-
constructor({ exampleId }?: {
|
|
19
|
-
exampleId?: string;
|
|
20
|
-
});
|
|
21
|
-
/**
|
|
22
|
-
* Persists the given run object.
|
|
23
|
-
* @param run The run object to persist.
|
|
24
|
-
*/
|
|
25
|
-
protected persistRun(run: BaseRun): Promise<void>;
|
|
26
|
-
}
|
|
1
|
+
export * from "langchain-core/callbacks/tracers/run_collector";
|
|
@@ -1,46 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* A callback handler that collects traced runs and makes it easy to fetch the traced run object from calls through any langchain object.
|
|
4
|
-
* For instance, it makes it easy to fetch the run ID and then do things with that, such as log feedback.
|
|
5
|
-
*/
|
|
6
|
-
export class RunCollectorCallbackHandler extends BaseTracer {
|
|
7
|
-
/**
|
|
8
|
-
* Creates a new instance of the RunCollectorCallbackHandler class.
|
|
9
|
-
* @param exampleId The ID of the example.
|
|
10
|
-
*/
|
|
11
|
-
constructor({ exampleId } = {}) {
|
|
12
|
-
super();
|
|
13
|
-
/** The name of the callback handler. */
|
|
14
|
-
Object.defineProperty(this, "name", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: "run_collector"
|
|
19
|
-
});
|
|
20
|
-
/** The ID of the example. */
|
|
21
|
-
Object.defineProperty(this, "exampleId", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
27
|
-
/** An array of traced runs. */
|
|
28
|
-
Object.defineProperty(this, "tracedRuns", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: void 0
|
|
33
|
-
});
|
|
34
|
-
this.exampleId = exampleId;
|
|
35
|
-
this.tracedRuns = [];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Persists the given run object.
|
|
39
|
-
* @param run The run object to persist.
|
|
40
|
-
*/
|
|
41
|
-
async persistRun(run) {
|
|
42
|
-
const run_ = { ...run };
|
|
43
|
-
run_.reference_example_id = this.exampleId;
|
|
44
|
-
this.tracedRuns.push(run_);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
export * from "langchain-core/callbacks/tracers/run_collector";
|