Skip to content

Commit

Permalink
Merge pull request #1270 from hwchase17/vwp/add_environment_info
Browse files Browse the repository at this point in the history
Add Environment Info to Run Logs
  • Loading branch information
vowelparrot committed May 16, 2023
2 parents bb60f47 + d1457bf commit 07185dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion langchain/src/callbacks/handlers/tracer_langchain.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getRuntimeEnvironment } from "../../util/env.js";
import { BaseTracer, Run, BaseRun } from "./tracer.js";

export interface RunCreate extends BaseRun {
Expand Down Expand Up @@ -143,14 +144,16 @@ export class LangChainTracer
example_id: string | undefined = undefined
): Promise<RunCreate> {
const session = await this.ensureSession();
const runExtra = run.extra ?? {};
runExtra.runtime = await getRuntimeEnvironment();
const persistedRun: RunCreate = {
id: run.id,
name: run.name,
start_time: run.start_time,
end_time: run.end_time,
run_type: run.run_type,
reference_example_id: example_id,
extra: run.extra ?? {},
extra: runExtra,
execution_order: run.execution_order,
serialized: run.serialized,
error: run.error,
Expand Down
21 changes: 21 additions & 0 deletions langchain/src/util/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,24 @@ export const getEnv = () => {

return env;
};

export type RuntimeEnvironment = {
library: string;
libraryVersion?: string;
runtime: string;
runtimeVersion?: string;
};

let runtimeEnvironment: RuntimeEnvironment | undefined;

export async function getRuntimeEnvironment(): Promise<RuntimeEnvironment> {
if (runtimeEnvironment === undefined) {
const env = getEnv();

runtimeEnvironment = {
library: "langchain-js",
runtime: env,
};
}
return runtimeEnvironment;
}
7 changes: 7 additions & 0 deletions langchain/src/util/tests/environment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getRuntimeEnvironment } from "../env.js";

test("test getRuntimeEnvironment", async () => {
const runtimeEnvironment = await getRuntimeEnvironment();
console.log(runtimeEnvironment);
expect(runtimeEnvironment.runtime).toEqual("node");
});

1 comment on commit 07185dd

@vercel
Copy link

@vercel vercel bot commented on 07185dd May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.