-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathreact.test.ts
56 lines (48 loc) · 2.16 KB
/
react.test.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
import { ReActSingleInputOutputParser } from "../react/output_parser.js";
test("ReActSingleInputOutputParser identifies final answer", async () => {
const finalAnswerText = `Observation: 2.169459462491557
Thought: I now know the final answer
Final Answer: Harry Styles, Olivia Wilde's boyfriend, is 29 years old and his age raised to the 0.23 power is 2.169459462491557.`;
const outputParser = new ReActSingleInputOutputParser({
toolNames: [],
});
const parsedOutput = await outputParser.parse(finalAnswerText);
// console.log(parsedOutput);
expect(parsedOutput).toHaveProperty("returnValues");
expect(
"returnValues" in parsedOutput && parsedOutput.returnValues.output
).toEqual(
"Harry Styles, Olivia Wilde's boyfriend, is 29 years old and his age raised to the 0.23 power is 2.169459462491557."
);
});
test("ReActSingleInputOutputParser identifies agent actions", async () => {
const finalAnswerText = `Observation: 29 years
Thought: I need to calculate 29 raised to the 0.23 power
Action: calculator
Action Input: 29^0.23`;
const outputParser = new ReActSingleInputOutputParser({
toolNames: [],
});
const parsedOutput = await outputParser.parse(finalAnswerText);
// console.log(parsedOutput);
expect(parsedOutput).toHaveProperty("toolInput");
expect(parsedOutput).toHaveProperty("tool");
});
test("ReActSingleInputOutputParser throws if no agent finish/action is passed", async () => {
const finalAnswerText = `Who is Harry Styles' girlfriend?`;
const outputParser = new ReActSingleInputOutputParser({
toolNames: [],
});
await expect(outputParser.parse(finalAnswerText)).rejects.toThrow();
});
test("ReActSingleInputOutputParser throws if agent finish and action are passed", async () => {
const finalAnswerText = `Observation: 29 years
Thought: I need to calculate 29 raised to the 0.23 power
Action: calculator
Action Input: 29^0.23
Final Answer: Harry Styles, Olivia Wilde's boyfriend, is 29 years old and his age raised to the 0.23 power is 2.169459462491557.`;
const outputParser = new ReActSingleInputOutputParser({
toolNames: [],
});
await expect(outputParser.parse(finalAnswerText)).rejects.toThrow();
});