Skip to content

Commit

Permalink
Remove LangGraph dep
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Nov 25, 2024
1 parent 9ae7525 commit 75c8fd0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 81 deletions.
3 changes: 1 addition & 2 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"author": "LangChain",
"license": "MIT",
"dependencies": {
"@langchain/langgraph": "^0.2.22",
"@langchain/openai": ">=0.2.0 <0.4.0",
"binary-extensions": "^2.2.0",
"expr-eval": "^2.0.2",
Expand Down Expand Up @@ -193,7 +192,7 @@
"node-llama-cpp": "3.1.1",
"notion-to-md": "^3.1.0",
"officeparser": "^4.0.4",
"openai": "^4.73.0",
"openai": "*",
"pdf-parse": "1.1.1",
"pg": "^8.11.0",
"pg-copy-streams": "^6.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, describe, test, beforeEach, afterEach } from "@jest/globals";
import { Stagehand } from "@browserbasehq/stagehand";
import { z } from "zod";
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
// import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { StagehandToolkit } from "../stagehand.js";

describe("StagehandToolkit Integration Tests", () => {
Expand Down Expand Up @@ -165,78 +165,78 @@ describe("StagehandToolkit Integration Tests", () => {
expect(currentUrl).toContain("google.com/search?q=OpenAI");
});

test("should work with langgraph", async () => {
const actTool = toolkit.tools.find((t) => t.name === "stagehand_act");
const navigateTool = toolkit.tools.find(
(t) => t.name === "stagehand_navigate"
);
if (!actTool || !navigateTool) {
throw new Error("Required tools not found");
}
const tools = [actTool, navigateTool];

const model = new ChatOpenAI({
modelName: "gpt-4",
temperature: 0,
});

const agent = createReactAgent({
llm: model,
tools,
});
// Navigate to Google
const inputs1 = {
messages: [
{
role: "user",
content: "Navigate to https://www.google.com",
},
],
};

const stream1 = await agent.stream(inputs1, {
streamMode: "values",
});

for await (const { messages } of stream1) {
const msg =
messages && messages.length > 0
? messages[messages.length - 1]
: undefined;
if (msg?.content) {
console.log(msg.content);
} else if (msg?.tool_calls && msg.tool_calls.length > 0) {
console.log(msg.tool_calls);
} else {
console.log(msg);
}
}

// Click through to careers page and search
const inputs2 = {
messages: [
{
role: "user",
content: "Click on the About page",
},
],
};

const stream2 = await agent.stream(inputs2, {
streamMode: "values",
});
for await (const { messages } of stream2) {
const msg = messages ? messages[messages.length - 1] : undefined;
if (msg?.content) {
console.log(msg.content);
} else if (msg?.tool_calls && msg.tool_calls.length > 0) {
console.log(msg.tool_calls);
} else {
console.log(msg);
}
}

const currentUrl = stagehand.page.url();
expect(currentUrl).toContain("about");
});
// test("should work with langgraph", async () => {
// const actTool = toolkit.tools.find((t) => t.name === "stagehand_act");
// const navigateTool = toolkit.tools.find(
// (t) => t.name === "stagehand_navigate"
// );
// if (!actTool || !navigateTool) {
// throw new Error("Required tools not found");
// }
// const tools = [actTool, navigateTool];

// const model = new ChatOpenAI({
// modelName: "gpt-4",
// temperature: 0,
// });

// const agent = createReactAgent({
// llm: model,
// tools,
// });
// // Navigate to Google
// const inputs1 = {
// messages: [
// {
// role: "user",
// content: "Navigate to https://www.google.com",
// },
// ],
// };

// const stream1 = await agent.stream(inputs1, {
// streamMode: "values",
// });

// for await (const { messages } of stream1) {
// const msg =
// messages && messages.length > 0
// ? messages[messages.length - 1]
// : undefined;
// if (msg?.content) {
// console.log(msg.content);
// } else if (msg?.tool_calls && msg.tool_calls.length > 0) {
// console.log(msg.tool_calls);
// } else {
// console.log(msg);
// }
// }

// // Click through to careers page and search
// const inputs2 = {
// messages: [
// {
// role: "user",
// content: "Click on the About page",
// },
// ],
// };

// const stream2 = await agent.stream(inputs2, {
// streamMode: "values",
// });
// for await (const { messages } of stream2) {
// const msg = messages ? messages[messages.length - 1] : undefined;
// if (msg?.content) {
// console.log(msg.content);
// } else if (msg?.tool_calls && msg.tool_calls.length > 0) {
// console.log(msg.tool_calls);
// } else {
// console.log(msg);
// }
// }

// const currentUrl = stagehand.page.url();
// expect(currentUrl).toContain("about");
// });
});
7 changes: 3 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6674,7 +6674,6 @@ __metadata:
"@jest/globals": ^29.5.0
"@lancedb/lancedb": ^0.13.0
"@langchain/core": "workspace:*"
"@langchain/langgraph": ^0.2.22
"@langchain/openai": ">=0.2.0 <0.4.0"
"@langchain/scripts": ">=0.1.0 <0.2.0"
"@langchain/standard-tests": 0.0.0
Expand Down Expand Up @@ -6792,7 +6791,7 @@ __metadata:
node-llama-cpp: 3.1.1
notion-to-md: ^3.1.0
officeparser: ^4.0.4
openai: ^4.73.0
openai: "*"
pdf-parse: 1.1.1
pg: ^8.11.0
pg-copy-streams: ^6.0.5
Expand Down Expand Up @@ -7555,7 +7554,7 @@ __metadata:
languageName: node
linkType: hard

"@langchain/langgraph@npm:^0.2.22, @langchain/langgraph@npm:^0.2.3":
"@langchain/langgraph@npm:^0.2.3":
version: 0.2.22
resolution: "@langchain/langgraph@npm:0.2.22"
dependencies:
Expand Down Expand Up @@ -26886,7 +26885,7 @@ __metadata:
languageName: node
linkType: hard

"openai@npm:^4.32.1, openai@npm:^4.41.1, openai@npm:^4.71.0, openai@npm:^4.73.0":
"openai@npm:*, openai@npm:^4.32.1, openai@npm:^4.41.1, openai@npm:^4.71.0":
version: 4.73.0
resolution: "openai@npm:4.73.0"
dependencies:
Expand Down

0 comments on commit 75c8fd0

Please sign in to comment.