UNPKG

@langchain/core

Version:
1 lines 1.65 kB
{"version":3,"file":"run_collector.cjs","names":["BaseTracer","run: BaseRun"],"sources":["../../src/tracers/run_collector.ts"],"sourcesContent":["import { BaseRun, Run } from \"langsmith/schemas\";\nimport { BaseTracer } from \"./base.js\";\n\n/**\n * A callback handler that collects traced runs and makes it easy to fetch the traced run object from calls through any langchain object.\n * For instance, it makes it easy to fetch the run ID and then do things with that, such as log feedback.\n */\nexport class RunCollectorCallbackHandler extends BaseTracer {\n /** The name of the callback handler. */\n name = \"run_collector\";\n\n /** The ID of the example. */\n exampleId?: string;\n\n /** An array of traced runs. */\n tracedRuns: Run[];\n\n /**\n * Creates a new instance of the RunCollectorCallbackHandler class.\n * @param exampleId The ID of the example.\n */\n constructor({ exampleId }: { exampleId?: string } = {}) {\n super({ _awaitHandler: true });\n this.exampleId = exampleId;\n this.tracedRuns = [];\n }\n\n /**\n * Persists the given run object.\n * @param run The run object to persist.\n */\n protected async persistRun(run: BaseRun): Promise<void> {\n const run_ = { ...run } as Run;\n run_.reference_example_id = this.exampleId;\n this.tracedRuns.push(run_);\n }\n}\n"],"mappings":";;;;;;;;;;AAOA,IAAa,8BAAb,cAAiDA,gCAAW;;CAE1D,OAAO;;CAGP;;CAGA;;;;;CAMA,YAAY,EAAE,WAAmC,GAAG,CAAE,GAAE;EACtD,MAAM,EAAE,eAAe,KAAM,EAAC;EAC9B,KAAK,YAAY;EACjB,KAAK,aAAa,CAAE;CACrB;;;;;CAMD,MAAgB,WAAWC,KAA6B;EACtD,MAAM,OAAO,EAAE,GAAG,IAAK;EACvB,KAAK,uBAAuB,KAAK;EACjC,KAAK,WAAW,KAAK,KAAK;CAC3B;AACF"}