-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtext-embedding.pipeline.test.tsx
More file actions
41 lines (35 loc) · 1.22 KB
/
text-embedding.pipeline.test.tsx
File metadata and controls
41 lines (35 loc) · 1.22 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
import TextEmbeddingPipeline from '../pipelines/text-embedding';
// Mock the TextEmbedding model
jest.mock('../models/text-embedding', () => {
return {
TextEmbedding: jest.fn().mockImplementation(() => ({
load: jest.fn().mockResolvedValue(undefined),
embed: jest.fn().mockResolvedValue(new Float32Array([0.1, 0.2, 0.3])),
release: jest.fn().mockResolvedValue(undefined),
})),
};
});
describe('TextEmbedding Pipeline', () => {
beforeEach(() => {
jest.clearAllMocks();
});
afterEach(async () => {
await TextEmbeddingPipeline.release();
});
it('should throw error when not initialized', async () => {
await expect(TextEmbeddingPipeline.embed('test text')).rejects.toThrow(
'Tokenizer undefined, please initialize first'
);
});
it('should initialize properly', async () => {
await expect(
TextEmbeddingPipeline.init('test-model', 'model.onnx')
).resolves.not.toThrow();
});
it('should generate embeddings', async () => {
await TextEmbeddingPipeline.init('test-model', 'model.onnx');
const embeddings = await TextEmbeddingPipeline.embed('test text');
expect(embeddings).toBeInstanceOf(Float32Array);
expect(embeddings.length).toBe(3);
});
});