Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Apr 8, 2024
1 parent 2bd42f7 commit b7e74e1
Show file tree
Hide file tree
Showing 35 changed files with 132 additions and 132 deletions.
20 changes: 10 additions & 10 deletions langchain-core/src/utils/testing/tests/chatfake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Test FakeListChatLLM", () => {
test("Should exist", async () => {
const chat = new FakeListChatModel({ responses: ["test response"] });
const message = new HumanMessage("test message");
const response = await chat.call([message]);
const response = await chat.invoke([message]);

expect(typeof response.content).toBe("string");
});
Expand All @@ -17,8 +17,8 @@ describe("Test FakeListChatLLM", () => {
responses: ["test response 1", "test response 2"],
});
const message = new HumanMessage("test message");
const response1 = await chat.call([message]);
const response2 = await chat.call([message]);
const response1 = await chat.invoke([message]);
const response2 = await chat.invoke([message]);

expect(response1.content).toBe("test response 1");
expect(response2.content).toBe("test response 2");
Expand All @@ -29,9 +29,9 @@ describe("Test FakeListChatLLM", () => {
responses: ["test response 1", "test response 2"],
});
const message = new HumanMessage("test message");
const first_response = await chat.call([message]);
const second_response = await chat.call([message]);
const third_response = await chat.call([message]);
const first_response = await chat.invoke([message]);
const second_response = await chat.invoke([message]);
const third_response = await chat.invoke([message]);

expect(first_response.content).toBe("test response 1");
expect(second_response.content).toBe("test response 2");
Expand All @@ -43,7 +43,7 @@ describe("Test FakeListChatLLM", () => {
responses: ["test response 1", "test response 2"],
});
const message = new HumanMessage("test message");
const response = await chat.call([message], { stop: ["stop"] });
const response = await chat.invoke([message], { stop: ["stop"] });

expect(response.content).toBe("stop");
});
Expand All @@ -53,8 +53,8 @@ describe("Test FakeListChatLLM", () => {
responses: ["test response 1", "test response 2"],
});
const message = new HumanMessage("test message");
const first_response = await chat.call([message], { stop: ["stop"] });
const second_response = await chat.call([message]);
const first_response = await chat.invoke([message], { stop: ["stop"] });
const second_response = await chat.invoke([message]);

expect(first_response.content).toBe("stop");
expect(second_response.content).toBe("test response 1");
Expand All @@ -67,7 +67,7 @@ describe("Test FakeListChatLLM", () => {
});
const sleepSpy = jest.spyOn(chat, "_sleep");
const message = new HumanMessage("test message");
await chat.call([message]);
await chat.invoke([message]);

expect(sleepSpy).toHaveBeenCalledTimes(1);
}, 30000);
Expand Down
4 changes: 2 additions & 2 deletions langchain-core/src/utils/tests/async_caller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test("AsyncCaller passes on arguments and returns return value", async () => {
const callable = jest.fn((arg1, arg2) => Promise.resolve([arg2, arg1]));

const resultDirect = await callable(1, 2);
const resultWrapped = await caller.call(callable, 1, 2);
const resultWrapped = await caller.invoke(callable, 1, 2);

expect(resultDirect).toEqual([2, 1]);
expect(resultWrapped).toEqual([2, 1]);
Expand All @@ -29,7 +29,7 @@ test("AsyncCaller retries on failure", async () => {
.mockRejectedValueOnce("error")
.mockResolvedValueOnce([2, 1]);

const resultWrapped = await caller.call(callable);
const resultWrapped = await caller.invoke(callable);

expect(resultWrapped).toEqual([2, 1]);
expect(callable.mock.calls).toHaveLength(2);
Expand Down
10 changes: 5 additions & 5 deletions langchain/src/agents/tests/calculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ import { Calculator } from "../../tools/calculator.js";

test("Calculator tool, sum", async () => {
const calculator = new Calculator();
const result = await calculator.call("1 + 1");
const result = await calculator.invoke("1 + 1");
expect(result).toBe("2");
});

test("Calculator tool, product", async () => {
const calculator = new Calculator();
const result = await calculator.call("2 * 3");
const result = await calculator.invoke("2 * 3");
expect(result).toBe("6");
});

test("Calculator tool, division", async () => {
const calculator = new Calculator();
const result = await calculator.call("7 /2");
const result = await calculator.invoke("7 /2");
expect(result).toBe("3.5");
});

test("Calculator tool, exponentiation", async () => {
const calculator = new Calculator();
const result = await calculator.call("2 ^ 8");
const result = await calculator.invoke("2 ^ 8");
expect(result).toBe("256");
});

test("Calculator tool, complicated expression", async () => {
const calculator = new Calculator();
const result = await calculator.call("((2 + 3) * 4) / 2");
const result = await calculator.invoke("((2 + 3) * 4) / 2");
expect(result).toBe("10");
});
64 changes: 32 additions & 32 deletions langchain/src/agents/tests/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ test("JsonListKeysTool", async () => {
baz: { test: { foo: [1, 2, 3], qux: [{ x: 1, y: 2, z: 3 }, { a: 1 }] } },
});
const jsonListKeysTool = new JsonListKeysTool(jsonSpec);
expect(await jsonListKeysTool.call("")).toBe("foo, baz");
expect(await jsonListKeysTool.call("/foo")).toContain("not a dictionary");
expect(await jsonListKeysTool.call("/baz")).toBe("test");
expect(await jsonListKeysTool.call("/baz/test")).toBe("foo, qux");
expect(await jsonListKeysTool.call("/baz/test/foo")).toContain(
expect(await jsonListKeysTool.invoke("")).toBe("foo, baz");
expect(await jsonListKeysTool.invoke("/foo")).toContain("not a dictionary");
expect(await jsonListKeysTool.invoke("/baz")).toBe("test");
expect(await jsonListKeysTool.invoke("/baz/test")).toBe("foo, qux");
expect(await jsonListKeysTool.invoke("/baz/test/foo")).toContain(
"not a dictionary"
);
expect(await jsonListKeysTool.call("/baz/test/foo/0")).toContain(
expect(await jsonListKeysTool.invoke("/baz/test/foo/0")).toContain(
"not a dictionary"
);
expect(await jsonListKeysTool.call("/baz/test/qux")).toContain(
expect(await jsonListKeysTool.invoke("/baz/test/qux")).toContain(
"not a dictionary"
);
expect(await jsonListKeysTool.call("/baz/test/qux/0")).toBe("x, y, z");
expect(await jsonListKeysTool.call("/baz/test/qux/1")).toBe("a");
expect(await jsonListKeysTool.call("/bar")).toContain("not a dictionary");
expect(await jsonListKeysTool.invoke("/baz/test/qux/0")).toBe("x, y, z");
expect(await jsonListKeysTool.invoke("/baz/test/qux/1")).toBe("a");
expect(await jsonListKeysTool.invoke("/bar")).toContain("not a dictionary");
});

test("JsonListKeysTool, paths containing escaped characters", async () => {
Expand All @@ -40,7 +40,7 @@ test("JsonListKeysTool, paths containing escaped characters", async () => {
});

const jsonListKeyTool = new JsonListKeysTool(jsonSpec);
expect(await jsonListKeyTool.call("/paths")).toBe(
expect(await jsonListKeyTool.invoke("/paths")).toBe(
"a~0b, a~1b, a~0~1b, a~1~1~0b"
);
});
Expand All @@ -51,27 +51,27 @@ test("JsonGetValueTool", async () => {
baz: { test: { foo: [1, 2, 3], qux: [{ x: 1, y: 2, z: 3 }, { a: 1 }] } },
});
const jsonGetValueTool = new JsonGetValueTool(jsonSpec);
expect(await jsonGetValueTool.call("")).toBe(
expect(await jsonGetValueTool.invoke("")).toBe(
`{"foo":"bar","baz":{"test":{"foo":[1,2,3],"qux":[{"x":1,"y":2,"z":3},{"a":1}]}}}`
);
expect(await jsonGetValueTool.call("/foo")).toBe("bar");
expect(await jsonGetValueTool.call("/baz")).toBe(
expect(await jsonGetValueTool.invoke("/foo")).toBe("bar");
expect(await jsonGetValueTool.invoke("/baz")).toBe(
`{"test":{"foo":[1,2,3],"qux":[{"x":1,"y":2,"z":3},{"a":1}]}}`
);
expect(await jsonGetValueTool.call("/baz/test")).toBe(
expect(await jsonGetValueTool.invoke("/baz/test")).toBe(
`{"foo":[1,2,3],"qux":[{"x":1,"y":2,"z":3},{"a":1}]}`
);
expect(await jsonGetValueTool.call("/baz/test/foo")).toBe("[1,2,3]");
expect(await jsonGetValueTool.call("/baz/test/foo/0")).toBe("1");
expect(await jsonGetValueTool.call("/baz/test/qux")).toBe(
expect(await jsonGetValueTool.invoke("/baz/test/foo")).toBe("[1,2,3]");
expect(await jsonGetValueTool.invoke("/baz/test/foo/0")).toBe("1");
expect(await jsonGetValueTool.invoke("/baz/test/qux")).toBe(
`[{"x":1,"y":2,"z":3},{"a":1}]`
);
expect(await jsonGetValueTool.call("/baz/test/qux/0")).toBe(
expect(await jsonGetValueTool.invoke("/baz/test/qux/0")).toBe(
`{"x":1,"y":2,"z":3}`
);
expect(await jsonGetValueTool.call("/baz/test/qux/0/x")).toBe("1");
expect(await jsonGetValueTool.call("/baz/test/qux/1")).toBe(`{"a":1}`);
expect(await jsonGetValueTool.call("/bar")).toContain(`null`);
expect(await jsonGetValueTool.invoke("/baz/test/qux/0/x")).toBe("1");
expect(await jsonGetValueTool.invoke("/baz/test/qux/1")).toBe(`{"a":1}`);
expect(await jsonGetValueTool.invoke("/bar")).toContain(`null`);
});

test("JsonGetValueTool, large values", async () => {
Expand All @@ -80,14 +80,14 @@ test("JsonGetValueTool, large values", async () => {
5
);
const jsonGetValueTool = new JsonGetValueTool(jsonSpec);
expect(await jsonGetValueTool.call("")).toContain("large dictionary");
expect(await jsonGetValueTool.call("/foo")).toBe("bar");
expect(await jsonGetValueTool.call("/baz")).toContain("large dictionary");
expect(await jsonGetValueTool.call("/baz/test")).toContain(
expect(await jsonGetValueTool.invoke("")).toContain("large dictionary");
expect(await jsonGetValueTool.invoke("/foo")).toBe("bar");
expect(await jsonGetValueTool.invoke("/baz")).toContain("large dictionary");
expect(await jsonGetValueTool.invoke("/baz/test")).toContain(
"large dictionary"
);
expect(await jsonGetValueTool.call("/baz/test/foo")).toBe("[1,2,...");
expect(await jsonGetValueTool.call("/baz/test/foo/0")).toBe("1");
expect(await jsonGetValueTool.invoke("/baz/test/foo")).toBe("[1,2,...");
expect(await jsonGetValueTool.invoke("/baz/test/foo/0")).toBe("1");
});

test("JsonGetValueTool, paths containing escaped characters", async () => {
Expand All @@ -101,19 +101,19 @@ test("JsonGetValueTool, paths containing escaped characters", async () => {
});

const jsonGetValueTool = new JsonGetValueTool(jsonSpec);
expect(await jsonGetValueTool.call("/paths/~0IDSGenericFXCrossRate")).toBe(
expect(await jsonGetValueTool.invoke("/paths/~0IDSGenericFXCrossRate")).toBe(
"1"
);

expect(await jsonGetValueTool.call("/paths/~1IDSGenericFXCrossRate")).toBe(
expect(await jsonGetValueTool.invoke("/paths/~1IDSGenericFXCrossRate")).toBe(
"2"
);

expect(await jsonGetValueTool.call("/paths/~0~1IDSGenericFXCrossRate")).toBe(
expect(await jsonGetValueTool.invoke("/paths/~0~1IDSGenericFXCrossRate")).toBe(
"3"
);

expect(await jsonGetValueTool.call("/paths/~1~0IDSGenericFXCrossRate")).toBe(
expect(await jsonGetValueTool.invoke("/paths/~1~0IDSGenericFXCrossRate")).toBe(
"4"
);
});
16 changes: 8 additions & 8 deletions langchain/src/agents/tests/sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ afterEach(async () => {

test.skip("QuerySqlTool", async () => {
const querySqlTool = new QuerySqlTool(db);
const result = await querySqlTool.call("SELECT * FROM users");
const result = await querySqlTool.invoke("SELECT * FROM users");
expect(result).toBe(
`[{"id":1,"name":"Alice","age":20},{"id":2,"name":"Bob","age":21},{"id":3,"name":"Charlie","age":22}]`
);
});

test.skip("QuerySqlTool with error", async () => {
const querySqlTool = new QuerySqlTool(db);
const result = await querySqlTool.call("SELECT * FROM userss");
const result = await querySqlTool.invoke("SELECT * FROM userss");
expect(result).toBe(`QueryFailedError: SQLITE_ERROR: no such table: userss`);
});

test.skip("InfoSqlTool", async () => {
const infoSqlTool = new InfoSqlTool(db);
const result = await infoSqlTool.call("users, products");
const result = await infoSqlTool.invoke("users, products");
const expectStr = `
CREATE TABLE products (
id INTEGER , name TEXT , price INTEGER )
Expand All @@ -101,7 +101,7 @@ test.skip("InfoSqlTool with customDescription", async () => {
userss: "Should not appear",
};
const infoSqlTool = new InfoSqlTool(db);
const result = await infoSqlTool.call("users, products");
const result = await infoSqlTool.invoke("users, products");
const expectStr = `
Custom Description for Products Table
CREATE TABLE products (
Expand All @@ -124,15 +124,15 @@ SELECT * FROM "users" LIMIT 3;

test.skip("InfoSqlTool with error", async () => {
const infoSqlTool = new InfoSqlTool(db);
const result = await infoSqlTool.call("userss, products");
const result = await infoSqlTool.invoke("userss, products");
expect(result).toBe(
`Error: Wrong target table name: the table userss was not found in the database`
);
});

test.skip("ListTablesSqlTool", async () => {
const listSqlTool = new ListTablesSqlTool(db);
const result = await listSqlTool.call("");
const result = await listSqlTool.invoke("");
expect(result).toBe(`products, users`);
});

Expand All @@ -146,14 +146,14 @@ test.skip("ListTablesSqlTool with include tables", async () => {
const includesTables = ["users"];
db.includesTables = includesTables;
const listSqlTool = new ListTablesSqlTool(db);
const result = await listSqlTool.call("");
const result = await listSqlTool.invoke("");
expect(result).toBe("users");
});

test.skip("ListTablesSqlTool with ignore tables", async () => {
const ignoreTables = ["products"];
db.ignoreTables = ignoreTables;
const listSqlTool = new ListTablesSqlTool(db);
const result = await listSqlTool.call("");
const result = await listSqlTool.invoke("");
expect(result).toBe("users");
});
2 changes: 1 addition & 1 deletion langchain/src/chains/router/tests/multi_prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test("Test MultiPromptChain", async () => {
promptTemplates,
});

const { text: result } = await multiPromptChain.call({ input: "Test input" });
const { text: result } = await multiPromptChain.invoke({ input: "Test input" });

expect(result).toEqual(`<from ${pickedPrompt}>`);
});
4 changes: 2 additions & 2 deletions langchain/src/chains/router/tests/multi_retrieval_qa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test("Test MultiRetrievalQAChain No Defaults With Retriever Prompts", async () =
}
);

const { text: result } = await multiRetrievalQAChain.call({
const { text: result } = await multiRetrievalQAChain.invoke({
input: "test input",
});

Expand Down Expand Up @@ -129,7 +129,7 @@ test("Test MultiRetrievalQAChain No Defaults No Retriever Prompts", async () =>
}
);

const { text: result, sourceDocuments } = await multiRetrievalQAChain.call({
const { text: result, sourceDocuments } = await multiRetrievalQAChain.invoke({
input: "test input",
});

Expand Down
4 changes: 2 additions & 2 deletions langchain/src/chains/tests/combine_docs_chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test("Test MapReduceDocumentsChain", async () => {
new Document({ pageContent: "ankush went to princeton" }),
];

const res = await chain.call({
const res = await chain.invoke({
input_documents: docs,
question: "Where did harrison go to college",
});
Expand All @@ -69,7 +69,7 @@ test("Test MapReduceDocumentsChain with content above maxTokens and intermediate
new Document({ pageContent: bString }),
];

const res = await chain.call({
const res = await chain.invoke({
input_documents: docs,
question: "Is the letter c present in the document",
});
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/chains/tests/constitutional_chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test("Test ConstitutionalChain", async () => {
],
});

const { output } = await constitutionalChain.call({
const { output } = await constitutionalChain.invoke({
question: "What is the meaning of life?",
});
expect(output).toContain(critiqueWord);
Expand Down
6 changes: 3 additions & 3 deletions langchain/src/chains/tests/sequential_chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ test("Test SequentialChain", async () => {
inputVariables: ["input1", "input2"],
outputVariables: ["text"],
});
const response = await combinedChain.call({
const response = await combinedChain.invoke({
input1: "test1",
input2: "test2",
});
Expand Down Expand Up @@ -233,7 +233,7 @@ test("Test SequentialChain chains passes all outputs", async () => {
outputVariables: ["text"],
});
expect(
await combinedChain.call({
await combinedChain.invoke({
input1: "1",
})
).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -283,7 +283,7 @@ test("Test SequentialChain for memory on one of the sub-chains", async () => {
outputVariables: ["text"],
});

const result = await combinedChain.call({ input1: "test1" });
const result = await combinedChain.invoke({ input1: "test1" });

expect(result).toMatchObject({
text: "Final Answer: \nHuman: Hello\nAI: Hi\nThe answer is XXX.",
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/chains/tests/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ test("TransformChain", async () => {
outputVariables: ["c"],
});

await expect(chain.call({ a: 1, b: 2 })).resolves.toEqual({ c: 3 });
await expect(chain.invoke({ a: 1, b: 2 })).resolves.toEqual({ c: 3 });
});
Loading

0 comments on commit b7e74e1

Please sign in to comment.