Repository navigation
Expand file tree
/
Copy pathtool-intent.test.ts
More file actions
44 lines (40 loc) · 1.94 KB
/
Copy pathtool-intent.test.ts
File metadata and controls
44 lines (40 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { describe, expect, it } from "vitest";
import { inferToolRequirement } from "./tool-intent.js";
describe("inferToolRequirement", () => {
it("does not confuse available tools with a tool requirement", () => {
expect(
inferToolRequirement(
"Which option best explains the observation?\nA. One\nB. Two\nC. Three\nD. Four",
),
).toBe(false);
expect(inferToolRequirement("What is 17 times 9?")).toBe(false);
});
it("recognizes explicit tool, repository, web, and stateful actions", () => {
expect(inferToolRequirement("Use the lookup_order tool for order B-42.")).toBe(true);
expect(inferToolRequirement("Patch the repository and run the tests.")).toBe(true);
expect(
inferToolRequirement("Calculate the average and save it in a file called result.txt."),
).toBe(true);
expect(inferToolRequirement("Search the web for today's weather in Shanghai.")).toBe(true);
expect(inferToolRequirement("Cancel my flight booking and refund the ticket.")).toBe(true);
expect(inferToolRequirement("修改仓库里的文件,然后运行测试。")).toBe(true);
});
it("honors the OpenAI tool_choice contract", () => {
expect(inferToolRequirement("Retrieve the account details.", undefined, "required")).toBe(true);
expect(
inferToolRequirement("Retrieve the account details.", undefined, {
type: "function",
function: { name: "get_account" },
}),
).toBe(true);
expect(inferToolRequirement("What is 17 times 9?", undefined, "auto")).toBe(false);
expect(
inferToolRequirement("Cancel my flight booking and refund the ticket.", undefined, "none"),
).toBe(false);
});
it("does not treat host tool descriptions as a per-turn requirement", () => {
const systemPrompt =
"You can use web_search to look up documentation, run tests, and update account records.";
expect(inferToolRequirement("What is 17 times 9?", systemPrompt)).toBe(false);
});
});