langchain 0.1.15 → 0.1.16-rc.0
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/evaluation/base.cjs +2 -2
- package/dist/evaluation/base.d.ts +2 -2
- package/dist/evaluation/base.js +2 -2
- package/dist/evaluation/criteria/criteria.cjs +2 -2
- package/dist/evaluation/criteria/criteria.d.ts +1 -1
- package/dist/evaluation/criteria/criteria.js +2 -2
- package/dist/smith/runner_utils.cjs +44 -13
- package/dist/smith/runner_utils.js +44 -13
- package/package.json +3 -1
package/dist/evaluation/base.cjs
CHANGED
|
@@ -143,9 +143,9 @@ class LLMStringEvaluator extends LLMEvalChain {
|
|
|
143
143
|
* @param callOptions
|
|
144
144
|
* @param config
|
|
145
145
|
*/
|
|
146
|
-
evaluateStrings(args,
|
|
146
|
+
evaluateStrings(args, config) {
|
|
147
147
|
this.checkEvaluationArgs(args.reference, args.input);
|
|
148
|
-
return this._evaluateStrings(args,
|
|
148
|
+
return this._evaluateStrings(args, config);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
exports.LLMStringEvaluator = LLMStringEvaluator;
|
|
@@ -114,7 +114,7 @@ export declare abstract class LLMStringEvaluator<T extends EvalOutputType = Eval
|
|
|
114
114
|
* @param callOptions
|
|
115
115
|
* @param config
|
|
116
116
|
*/
|
|
117
|
-
abstract _evaluateStrings(args: StringEvaluatorArgs
|
|
117
|
+
abstract _evaluateStrings(args: StringEvaluatorArgs & ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
118
118
|
/**
|
|
119
119
|
* Evaluate Chain or LLM output, based on optional input and label.
|
|
120
120
|
* @returns The evaluation results containing the score or value. It is recommended that the dictionary contain the following keys:
|
|
@@ -125,7 +125,7 @@ export declare abstract class LLMStringEvaluator<T extends EvalOutputType = Eval
|
|
|
125
125
|
* @param callOptions
|
|
126
126
|
* @param config
|
|
127
127
|
*/
|
|
128
|
-
evaluateStrings(args: StringEvaluatorArgs
|
|
128
|
+
evaluateStrings(args: StringEvaluatorArgs & ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* Grade, tag, or otherwise evaluate predictions relative to their inputs
|
package/dist/evaluation/base.js
CHANGED
|
@@ -137,9 +137,9 @@ export class LLMStringEvaluator extends LLMEvalChain {
|
|
|
137
137
|
* @param callOptions
|
|
138
138
|
* @param config
|
|
139
139
|
*/
|
|
140
|
-
evaluateStrings(args,
|
|
140
|
+
evaluateStrings(args, config) {
|
|
141
141
|
this.checkEvaluationArgs(args.reference, args.input);
|
|
142
|
-
return this._evaluateStrings(args,
|
|
142
|
+
return this._evaluateStrings(args, config);
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
@@ -217,8 +217,8 @@ class CriteriaEvalChain extends base_js_1.LLMStringEvaluator {
|
|
|
217
217
|
}
|
|
218
218
|
return parsed;
|
|
219
219
|
}
|
|
220
|
-
async _evaluateStrings(args,
|
|
221
|
-
const result = await this.call({ ...this.getEvalInput(args)
|
|
220
|
+
async _evaluateStrings(args, config) {
|
|
221
|
+
const result = await this.call({ ...this.getEvalInput(args) }, config);
|
|
222
222
|
return this._prepareOutput(result);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
@@ -61,7 +61,7 @@ export declare class CriteriaEvalChain extends LLMStringEvaluator {
|
|
|
61
61
|
* @param result
|
|
62
62
|
*/
|
|
63
63
|
_prepareOutput(result: ChainValues): any;
|
|
64
|
-
_evaluateStrings(args: StringEvaluatorArgs
|
|
64
|
+
_evaluateStrings(args: StringEvaluatorArgs & ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Criteria evaluation chain that requires references.
|
|
@@ -213,8 +213,8 @@ export class CriteriaEvalChain extends LLMStringEvaluator {
|
|
|
213
213
|
}
|
|
214
214
|
return parsed;
|
|
215
215
|
}
|
|
216
|
-
async _evaluateStrings(args,
|
|
217
|
-
const result = await this.call({ ...this.getEvalInput(args)
|
|
216
|
+
async _evaluateStrings(args, config) {
|
|
217
|
+
const result = await this.call({ ...this.getEvalInput(args) }, config);
|
|
218
218
|
return this._prepareOutput(result);
|
|
219
219
|
}
|
|
220
220
|
}
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.runOnDataset = void 0;
|
|
4
4
|
const messages_1 = require("@langchain/core/messages");
|
|
5
5
|
const runnables_1 = require("@langchain/core/runnables");
|
|
6
|
-
const run_collector_1 = require("@langchain/core/tracers/run_collector");
|
|
7
6
|
const tracer_langchain_1 = require("@langchain/core/tracers/tracer_langchain");
|
|
7
|
+
const base_1 = require("@langchain/core/tracers/base");
|
|
8
8
|
const langsmith_1 = require("langsmith");
|
|
9
9
|
const loader_js_1 = require("../evaluation/loader.cjs");
|
|
10
10
|
const name_generation_js_1 = require("./name_generation.cjs");
|
|
11
11
|
const progress_js_1 = require("./progress.cjs");
|
|
12
|
-
class
|
|
12
|
+
class SingleRunIdExtractor {
|
|
13
13
|
constructor() {
|
|
14
14
|
Object.defineProperty(this, "runIdPromiseResolver", {
|
|
15
15
|
enumerable: true,
|
|
@@ -39,6 +39,39 @@ class RunIdExtractor {
|
|
|
39
39
|
return this.runIdPromise;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
class SingleRunExtractor extends base_1.BaseTracer {
|
|
43
|
+
constructor() {
|
|
44
|
+
super();
|
|
45
|
+
Object.defineProperty(this, "runPromiseResolver", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(this, "runPromise", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
/** The name of the callback handler. */
|
|
58
|
+
Object.defineProperty(this, "name", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: "single_run_extractor"
|
|
63
|
+
});
|
|
64
|
+
this.runPromise = new Promise((extract) => {
|
|
65
|
+
this.runPromiseResolver = extract;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async persistRun(run) {
|
|
69
|
+
this.runPromiseResolver(run);
|
|
70
|
+
}
|
|
71
|
+
async extract() {
|
|
72
|
+
return this.runPromise;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
42
75
|
/**
|
|
43
76
|
* Wraps an evaluator function + implements the RunEvaluator interface.
|
|
44
77
|
*/
|
|
@@ -59,7 +92,7 @@ class DynamicRunEvaluator {
|
|
|
59
92
|
* @returns A promise that extracts to the evaluation result.
|
|
60
93
|
*/
|
|
61
94
|
async evaluateRun(run, example) {
|
|
62
|
-
const extractor = new
|
|
95
|
+
const extractor = new SingleRunIdExtractor();
|
|
63
96
|
const tracer = new tracer_langchain_1.LangChainTracer({ projectName: "evaluators" });
|
|
64
97
|
const result = await this.evaluator.invoke({
|
|
65
98
|
run,
|
|
@@ -146,7 +179,7 @@ class PreparedRunEvaluator {
|
|
|
146
179
|
rawReferenceOutput: example?.outputs,
|
|
147
180
|
run,
|
|
148
181
|
});
|
|
149
|
-
const extractor = new
|
|
182
|
+
const extractor = new SingleRunIdExtractor();
|
|
150
183
|
const tracer = new tracer_langchain_1.LangChainTracer({ projectName: "evaluators" });
|
|
151
184
|
if (this.isStringEvaluator) {
|
|
152
185
|
const evalResult = await this.evaluator.evaluateStrings({
|
|
@@ -226,25 +259,23 @@ const createWrappedModel = async (modelOrFactory) => {
|
|
|
226
259
|
const loadExamples = async ({ datasetName, client, projectName, }) => {
|
|
227
260
|
const exampleIterator = client.listExamples({ datasetName });
|
|
228
261
|
const configs = [];
|
|
229
|
-
const
|
|
262
|
+
const runExtractors = [];
|
|
230
263
|
const examples = [];
|
|
231
264
|
for await (const example of exampleIterator) {
|
|
232
|
-
const
|
|
233
|
-
exampleId: example.id,
|
|
234
|
-
});
|
|
265
|
+
const runExtractor = new SingleRunExtractor();
|
|
235
266
|
configs.push({
|
|
236
267
|
callbacks: [
|
|
237
268
|
new tracer_langchain_1.LangChainTracer({ exampleId: example.id, projectName }),
|
|
238
|
-
|
|
269
|
+
runExtractor,
|
|
239
270
|
],
|
|
240
271
|
});
|
|
241
272
|
examples.push(example);
|
|
242
|
-
|
|
273
|
+
runExtractors.push(runExtractor);
|
|
243
274
|
}
|
|
244
275
|
return {
|
|
245
276
|
configs,
|
|
246
277
|
examples,
|
|
247
|
-
|
|
278
|
+
runExtractors,
|
|
248
279
|
};
|
|
249
280
|
};
|
|
250
281
|
const applyEvaluators = async ({ evaluation, runs, examples, client, }) => {
|
|
@@ -352,7 +383,7 @@ const runOnDataset = async (chainOrFactory, datasetName, { evaluationConfig, pro
|
|
|
352
383
|
const dataset = await testClient.readDataset({ datasetName });
|
|
353
384
|
const datasetId = dataset.id;
|
|
354
385
|
const testConcurrency = maxConcurrency ?? 5;
|
|
355
|
-
const { configs, examples,
|
|
386
|
+
const { configs, examples, runExtractors } = await loadExamples({
|
|
356
387
|
datasetName,
|
|
357
388
|
client: testClient,
|
|
358
389
|
projectName: testProjectName,
|
|
@@ -384,7 +415,7 @@ const runOnDataset = async (chainOrFactory, datasetName, { evaluationConfig, pro
|
|
|
384
415
|
progress.complete();
|
|
385
416
|
const runs = [];
|
|
386
417
|
for (let i = 0; i < examples.length; i += 1) {
|
|
387
|
-
runs.push(
|
|
418
|
+
runs.push(await runExtractors[i].extract());
|
|
388
419
|
}
|
|
389
420
|
let evalResults = {};
|
|
390
421
|
if (evaluationConfig) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { mapStoredMessagesToChatMessages } from "@langchain/core/messages";
|
|
2
2
|
import { Runnable, RunnableLambda, } from "@langchain/core/runnables";
|
|
3
|
-
import { RunCollectorCallbackHandler } from "@langchain/core/tracers/run_collector";
|
|
4
3
|
import { LangChainTracer } from "@langchain/core/tracers/tracer_langchain";
|
|
4
|
+
import { BaseTracer } from "@langchain/core/tracers/base";
|
|
5
5
|
import { Client } from "langsmith";
|
|
6
6
|
import { loadEvaluator } from "../evaluation/loader.js";
|
|
7
7
|
import { randomName } from "./name_generation.js";
|
|
8
8
|
import { ProgressBar } from "./progress.js";
|
|
9
|
-
class
|
|
9
|
+
class SingleRunIdExtractor {
|
|
10
10
|
constructor() {
|
|
11
11
|
Object.defineProperty(this, "runIdPromiseResolver", {
|
|
12
12
|
enumerable: true,
|
|
@@ -36,6 +36,39 @@ class RunIdExtractor {
|
|
|
36
36
|
return this.runIdPromise;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
class SingleRunExtractor extends BaseTracer {
|
|
40
|
+
constructor() {
|
|
41
|
+
super();
|
|
42
|
+
Object.defineProperty(this, "runPromiseResolver", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: void 0
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(this, "runPromise", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: void 0
|
|
53
|
+
});
|
|
54
|
+
/** The name of the callback handler. */
|
|
55
|
+
Object.defineProperty(this, "name", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: "single_run_extractor"
|
|
60
|
+
});
|
|
61
|
+
this.runPromise = new Promise((extract) => {
|
|
62
|
+
this.runPromiseResolver = extract;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async persistRun(run) {
|
|
66
|
+
this.runPromiseResolver(run);
|
|
67
|
+
}
|
|
68
|
+
async extract() {
|
|
69
|
+
return this.runPromise;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
39
72
|
/**
|
|
40
73
|
* Wraps an evaluator function + implements the RunEvaluator interface.
|
|
41
74
|
*/
|
|
@@ -56,7 +89,7 @@ class DynamicRunEvaluator {
|
|
|
56
89
|
* @returns A promise that extracts to the evaluation result.
|
|
57
90
|
*/
|
|
58
91
|
async evaluateRun(run, example) {
|
|
59
|
-
const extractor = new
|
|
92
|
+
const extractor = new SingleRunIdExtractor();
|
|
60
93
|
const tracer = new LangChainTracer({ projectName: "evaluators" });
|
|
61
94
|
const result = await this.evaluator.invoke({
|
|
62
95
|
run,
|
|
@@ -143,7 +176,7 @@ class PreparedRunEvaluator {
|
|
|
143
176
|
rawReferenceOutput: example?.outputs,
|
|
144
177
|
run,
|
|
145
178
|
});
|
|
146
|
-
const extractor = new
|
|
179
|
+
const extractor = new SingleRunIdExtractor();
|
|
147
180
|
const tracer = new LangChainTracer({ projectName: "evaluators" });
|
|
148
181
|
if (this.isStringEvaluator) {
|
|
149
182
|
const evalResult = await this.evaluator.evaluateStrings({
|
|
@@ -223,25 +256,23 @@ const createWrappedModel = async (modelOrFactory) => {
|
|
|
223
256
|
const loadExamples = async ({ datasetName, client, projectName, }) => {
|
|
224
257
|
const exampleIterator = client.listExamples({ datasetName });
|
|
225
258
|
const configs = [];
|
|
226
|
-
const
|
|
259
|
+
const runExtractors = [];
|
|
227
260
|
const examples = [];
|
|
228
261
|
for await (const example of exampleIterator) {
|
|
229
|
-
const
|
|
230
|
-
exampleId: example.id,
|
|
231
|
-
});
|
|
262
|
+
const runExtractor = new SingleRunExtractor();
|
|
232
263
|
configs.push({
|
|
233
264
|
callbacks: [
|
|
234
265
|
new LangChainTracer({ exampleId: example.id, projectName }),
|
|
235
|
-
|
|
266
|
+
runExtractor,
|
|
236
267
|
],
|
|
237
268
|
});
|
|
238
269
|
examples.push(example);
|
|
239
|
-
|
|
270
|
+
runExtractors.push(runExtractor);
|
|
240
271
|
}
|
|
241
272
|
return {
|
|
242
273
|
configs,
|
|
243
274
|
examples,
|
|
244
|
-
|
|
275
|
+
runExtractors,
|
|
245
276
|
};
|
|
246
277
|
};
|
|
247
278
|
const applyEvaluators = async ({ evaluation, runs, examples, client, }) => {
|
|
@@ -349,7 +380,7 @@ export const runOnDataset = async (chainOrFactory, datasetName, { evaluationConf
|
|
|
349
380
|
const dataset = await testClient.readDataset({ datasetName });
|
|
350
381
|
const datasetId = dataset.id;
|
|
351
382
|
const testConcurrency = maxConcurrency ?? 5;
|
|
352
|
-
const { configs, examples,
|
|
383
|
+
const { configs, examples, runExtractors } = await loadExamples({
|
|
353
384
|
datasetName,
|
|
354
385
|
client: testClient,
|
|
355
386
|
projectName: testProjectName,
|
|
@@ -381,7 +412,7 @@ export const runOnDataset = async (chainOrFactory, datasetName, { evaluationConf
|
|
|
381
412
|
progress.complete();
|
|
382
413
|
const runs = [];
|
|
383
414
|
for (let i = 0; i < examples.length; i += 1) {
|
|
384
|
-
runs.push(
|
|
415
|
+
runs.push(await runExtractors[i].extract());
|
|
385
416
|
}
|
|
386
417
|
let evalResults = {};
|
|
387
418
|
if (evaluationConfig) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16-rc.0",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -1268,6 +1268,7 @@
|
|
|
1268
1268
|
"node-llama-cpp": "2.7.3",
|
|
1269
1269
|
"notion-to-md": "^3.1.0",
|
|
1270
1270
|
"officeparser": "^4.0.4",
|
|
1271
|
+
"openai": "^4.26.1",
|
|
1271
1272
|
"pdf-parse": "1.1.1",
|
|
1272
1273
|
"peggy": "^3.0.2",
|
|
1273
1274
|
"playwright": "^1.32.1",
|
|
@@ -1286,6 +1287,7 @@
|
|
|
1286
1287
|
"vectordb": "^0.1.4",
|
|
1287
1288
|
"weaviate-ts-client": "^1.4.0",
|
|
1288
1289
|
"web-auth-library": "^1.0.3",
|
|
1290
|
+
"wikipedia": "^2.1.2",
|
|
1289
1291
|
"youtube-transcript": "^1.0.6",
|
|
1290
1292
|
"youtubei.js": "^5.8.0"
|
|
1291
1293
|
},
|