Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Nov 30, 2024
1 parent 14ac54f commit 94445bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions langchain-core/src/singletons/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export const getDefaultLangChainClientSingleton = () => {
}
return client;
};

export const setDefaultLangChainClientSingleton = (newClient: Client) => {
client = newClient;
};
17 changes: 12 additions & 5 deletions langchain-core/src/tracers/tests/langsmith_interop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ import {
expect,
} from "@jest/globals";
import { traceable } from "langsmith/traceable";
import { Client } from "langsmith";

import { RunnableLambda } from "../../runnables/base.js";
import { BaseMessage, HumanMessage } from "../../messages/index.js";
import { setDefaultLangChainClientSingleton } from "../../singletons/tracer.js";

let fetchMock: any;

const originalTracingEnvValue = process.env.LANGCHAIN_TRACING_V2;

const client = new Client({
autoBatchTracing: false,
});

beforeEach(() => {
fetchMock = jest.spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve({
Expand All @@ -29,6 +35,7 @@ beforeEach(() => {
},
} as any)
);
setDefaultLangChainClientSingleton(client);
process.env.LANGCHAIN_TRACING_V2 = "true";
});

Expand All @@ -50,7 +57,7 @@ test.each(["true", "false"])(
await new Promise((resolve) => setTimeout(resolve, 300));
return msg.content + name;
},
{ name: "aiGreet", tracingEnabled: true }
{ name: "aiGreet", tracingEnabled: true, client }
);

const root = RunnableLambda.from(async (messages: BaseMessage[]) => {
Expand Down Expand Up @@ -197,7 +204,7 @@ test.each(["true", "false"])(
expect(getContextVariable("foo")).toEqual("baz");
return msg.content + name;
},
{ name: "aiGreet", tracingEnabled: true }
{ name: "aiGreet", tracingEnabled: true, client }
);

const root = RunnableLambda.from(async (messages: BaseMessage[]) => {
Expand Down Expand Up @@ -485,7 +492,7 @@ test.each(["true", "false"])(
const contents = await nested.invoke([msg]);
return contents[0] + name;
},
{ name: "aiGreet", tracingEnabled: true }
{ name: "aiGreet", tracingEnabled: true, client }
);

await aiGreet(new HumanMessage({ content: "Hello!" }), "mitochondria");
Expand Down Expand Up @@ -632,7 +639,7 @@ test.each(["true", "false"])(
expect(getContextVariable("foo")).toEqual("bar");
return contents[0] + name;
},
{ name: "aiGreet", tracingEnabled: true }
{ name: "aiGreet", tracingEnabled: true, client }
);

await aiGreet(new HumanMessage({ content: "Hello!" }), "mitochondria");
Expand Down Expand Up @@ -781,7 +788,7 @@ test.each(["true", "false"])(
yield letter;
}
},
{ name: "aiGreet", tracingEnabled: true }
{ name: "aiGreet", tracingEnabled: true, client }
);

for await (const _ of aiGreet(
Expand Down

0 comments on commit 94445bd

Please sign in to comment.