forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargument_extraction_v0.test.ts
148 lines (139 loc) · 4.07 KB
/
argument_extraction_v0.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import ArgumentExtractionNode, {
argument_extraction_node_data_v0
} from '$lib/compute/argument_extraction_v0';
import deepCopy from 'deep-copy';
import { describe, it, vi, beforeEach } from 'vitest';
import { expect } from 'vitest';
import mock_argument_extraction_data from '$lib/mock_data/argument_extraction/argument_extraction.json';
import mock_cluster_extraction_data from '$lib/mock_data/cluster_extraction/cluster_extraction.json';
import csv_data from '$lib/mock_data/csv/csv.json';
import prompt from '$lib/mock_data/argument_extraction/v0/prompt.txt?raw';
import system_prompt from '$lib/mock_data/argument_extraction/system_prompt.txt?raw';
vi.mock('$lib/utils', () => ({
readFileFromGCS: vi.fn(() => Promise.resolve(JSON.stringify(mock_argument_extraction_data))),
uploadJSONToGCS: vi.fn(() => Promise.resolve())
}));
describe('ArgumentExtractionNode class', function () {
let node;
let inputData;
const timeout = 60000;
beforeEach(() => {
node = new ArgumentExtractionNode(deepCopy(argument_extraction_node_data_v0));
inputData = {
open_ai_key: 'sk-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
csv: csv_data,
cluster_extraction: mock_cluster_extraction_data
};
node.data.prompt = prompt;
node.data.system_prompt = system_prompt;
}, timeout);
it(
'extract the given arguments',
async () => {
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(output).toEqual(mock_argument_extraction_data);
expect(node.data.message).toEqual(`comments: 2 claims: 2.`);
},
timeout
);
it(
'should not extract the arguments if no csv',
async () => {
delete inputData.csv;
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(output).toEqual(undefined);
expect(node.data.message).toEqual(`missing_input_data`);
},
timeout
);
it(
'should not extract the arguments if no open_ai_key and no GCS',
async () => {
delete inputData.open_ai_key;
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(output).toEqual(undefined);
expect(node.data.message).toEqual(`missing_input_data`);
},
timeout
);
it(
'should load from GCS if no open ai key',
async () => {
delete inputData.open_ai_key;
node.data.gcs_path = 'gs://test_bucket/test_path';
node.data.csv_length = csv_data.length;
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(output).toEqual(mock_argument_extraction_data);
expect(node.data.message).toEqual(`loaded_from_gcs. comments: 2 claims: 2.`);
},
timeout
);
it(
'should not extract the arguments if no prompt and no system prompt',
async () => {
node.data.system_prompt = undefined;
node.data.prompt = undefined;
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(output).toEqual(undefined);
expect(node.data.message).toEqual(`missing_input_data`);
},
timeout
);
it(
'test GCS caching',
async () => {
node.data.gcs_path = 'gs://test_bucket/test_path';
node.data.dirty = false;
node.data.csv_length = csv_data.length;
const output = await node.compute(
inputData,
'run',
(x) => {
console.log(x);
expect(x == 'Calling OpenAI').toEqual(false);
},
console.error,
console.log,
'test_slug'
);
expect(output).toEqual(mock_argument_extraction_data);
expect(node.data.message).toEqual(`loaded_from_gcs. comments: 2 claims: 2.`);
},
timeout
);
});