Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Improve interoperability between different langsmith versions #7297

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions dependency_range_tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
# LangChain
langchain-latest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -13,7 +13,7 @@ services:
- ./scripts:/scripts
command: bash /scripts/langchain/test-with-latest-deps.sh
langchain-lowest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -23,10 +23,10 @@ services:
- ../langchain:/langchain
- ./scripts:/scripts
command: bash /scripts/langchain/test-with-lowest-deps.sh

# Community
community-latest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -40,7 +40,7 @@ services:
- ./scripts:/scripts
command: bash /scripts/with_standard_tests/community/test-with-latest-deps.sh
community-lowest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -54,7 +54,7 @@ services:
- ./scripts:/scripts
command: bash /scripts/with_standard_tests/community/test-with-lowest-deps.sh
community-npm-install:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -69,7 +69,7 @@ services:

# OpenAI
openai-latest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -83,7 +83,7 @@ services:
- ./scripts:/scripts
command: bash /scripts/with_standard_tests/openai/test-with-latest-deps.sh
openai-lowest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -99,7 +99,7 @@ services:

# Anthropic
anthropic-latest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -113,7 +113,7 @@ services:
- ./scripts:/scripts
command: bash /scripts/with_standard_tests/anthropic/test-with-latest-deps.sh
anthropic-lowest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -129,7 +129,7 @@ services:

# Google VertexAI
google-vertexai-latest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -143,7 +143,7 @@ services:
- ./scripts:/scripts
command: bash /scripts/with_standard_tests/google-vertexai/test-with-latest-deps.sh
google-vertexai-lowest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -159,7 +159,7 @@ services:

# Cohere
cohere-latest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -173,7 +173,7 @@ services:
- ./scripts:/scripts
command: bash /scripts/with_standard_tests/cohere/test-with-latest-deps.sh
cohere-lowest-deps:
image: node:18
image: node:20
environment:
PUPPETEER_SKIP_DOWNLOAD: "true"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
Expand All @@ -185,4 +185,4 @@ services:
- ../libs/langchain-standard-tests:/libs/langchain-standard-tests
- ../libs/langchain-cohere:/libs/langchain-cohere
- ./scripts:/scripts
command: bash /scripts/with_standard_tests/cohere/test-with-lowest-deps.sh
command: bash /scripts/with_standard_tests/cohere/test-with-lowest-deps.sh
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"ioredis": "^5.3.2",
"js-yaml": "^4.1.0",
"langchain": "workspace:*",
"langsmith": "^0.2.0",
"langsmith": "^0.2.8",
"mongodb": "^6.3.0",
"pg": "^8.11.0",
"pickleparser": "^0.2.1",
Expand Down
2 changes: 1 addition & 1 deletion langchain-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"camelcase": "6",
"decamelize": "1.2.0",
"js-tiktoken": "^1.0.12",
"langsmith": "^0.2.0",
"langsmith": "^0.2.8",
"mustache": "^4.2.0",
"p-queue": "^6.6.2",
"p-retry": "4",
Expand Down
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
8 changes: 4 additions & 4 deletions langchain-core/src/tracers/tracer_langchain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "langsmith";
import type { Client, LangSmithTracingClientInterface } from "langsmith";
import { RunTree } from "langsmith/run_trees";
import { getCurrentRunTree } from "langsmith/singletons/traceable";

Expand Down Expand Up @@ -36,7 +36,7 @@ export interface RunUpdate extends BaseRunUpdate {
export interface LangChainTracerFields extends BaseCallbackHandlerInput {
exampleId?: string;
projectName?: string;
client?: Client;
client?: LangSmithTracingClientInterface;
}

export class LangChainTracer
Expand All @@ -49,7 +49,7 @@ export class LangChainTracer

exampleId?: string;

client: Client;
client: LangSmithTracingClientInterface;

constructor(fields: LangChainTracerFields = {}) {
super(fields);
Expand Down Expand Up @@ -156,7 +156,7 @@ export class LangChainTracer
parent_run: undefined,

// inherited properties
client: this.client,
client: this.client as Client,
project_name: this.projectName,
reference_example_id: this.exampleId,
tracingEnabled: true,
Expand Down
2 changes: 1 addition & 1 deletion langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@
"js-tiktoken": "^1.0.12",
"js-yaml": "^4.1.0",
"jsonpointer": "^5.0.1",
"langsmith": "^0.2.0",
"langsmith": "^0.2.8",
"openapi-types": "^12.1.3",
"p-retry": "4",
"uuid": "^10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"flat": "^5.0.2",
"js-yaml": "^4.1.0",
"langchain": ">=0.2.3 <0.3.0 || >=0.3.4 <0.4.0",
"langsmith": "^0.2.0",
"langsmith": "^0.2.8",
"uuid": "^10.0.0",
"zod": "^3.22.3",
"zod-to-json-schema": "^3.22.5"
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11829,7 +11829,7 @@ __metadata:
jsdom: ^22.1.0
jsonwebtoken: ^9.0.2
langchain: ">=0.2.3 <0.3.0 || >=0.3.4 <0.4.0"
langsmith: ^0.2.0
langsmith: ^0.2.8
llmonitor: ^0.5.9
lodash: ^4.17.21
lunary: ^0.7.10
Expand Down Expand Up @@ -12263,7 +12263,7 @@ __metadata:
jest: ^29.5.0
jest-environment-node: ^29.6.4
js-tiktoken: ^1.0.12
langsmith: ^0.2.0
langsmith: ^0.2.8
ml-matrix: ^6.10.4
mustache: ^4.2.0
p-queue: ^6.6.2
Expand Down Expand Up @@ -27675,7 +27675,7 @@ __metadata:
ioredis: ^5.3.2
js-yaml: ^4.1.0
langchain: "workspace:*"
langsmith: ^0.2.0
langsmith: ^0.2.8
mongodb: ^6.3.0
pg: ^8.11.0
pickleparser: ^0.2.1
Expand Down Expand Up @@ -33329,7 +33329,7 @@ __metadata:
js-tiktoken: ^1.0.12
js-yaml: ^4.1.0
jsonpointer: ^5.0.1
langsmith: ^0.2.0
langsmith: ^0.2.8
openai: ^4.41.1
openapi-types: ^12.1.3
p-retry: 4
Expand Down Expand Up @@ -33408,9 +33408,9 @@ __metadata:
languageName: unknown
linkType: soft

"langsmith@npm:^0.2.0":
version: 0.2.0
resolution: "langsmith@npm:0.2.0"
"langsmith@npm:^0.2.8":
version: 0.2.8
resolution: "langsmith@npm:0.2.8"
dependencies:
"@types/uuid": ^10.0.0
commander: ^10.0.1
Expand All @@ -33423,7 +33423,7 @@ __metadata:
peerDependenciesMeta:
openai:
optional: true
checksum: 0cd92d0e31526d309af197a3502c93a00ac8c09f6b2864161a18a5c1e8b95b0e8203bad2dfe3b4beb26055fc815a8d70730592a58c9af7e202917b13d01f695c
checksum: 8695df08a09b9885b0308c66fbf9802edbe20e286fec3db8faa75ed1893a7aafae014441e311677bb60abb33af49da7f7d8404f55fffbdad5aec61cf65215fc8
languageName: node
linkType: hard

Expand Down
Loading