-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup.js
More file actions
46 lines (44 loc) · 1.06 KB
/
setup.js
File metadata and controls
46 lines (44 loc) · 1.06 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
45
46
// Mock text-encoding-polyfill
jest.mock('text-encoding-polyfill', () => ({}));
// Mock fetch for config loading
global.fetch = jest.fn(() =>
Promise.resolve({
arrayBuffer: () =>
Promise.resolve(
Uint8Array.from(
JSON.stringify({
eos_token_id: 2,
num_key_value_heads: 32,
hidden_size: 4096,
num_attention_heads: 32,
num_hidden_layers: 32,
})
.split('')
.map((c) => c.charCodeAt(0))
).buffer
),
})
);
// Mock InferenceSession
jest.mock('onnxruntime-react-native', () => ({
InferenceSession: {
create: jest.fn().mockResolvedValue({
run: jest.fn().mockResolvedValue({
logits: {
data: new Float32Array([0.1, 0.2, 0.3, 0.4]),
dims: [1, 1, 4],
type: 'float32',
},
}),
release: jest.fn(),
}),
},
env: { logLevel: 'error' },
Tensor: jest.fn().mockImplementation((type, data, dims) => ({
type,
data,
dims,
size: data.length,
dispose: jest.fn(),
})),
}));