Compare commits

...

25 Commits

Author SHA1 Message Date
sweep-ai[bot] 3ab1475bd8 Merge main into sweep/add-unit-tests 2023-10-26 23:04:31 +00:00
sweep-ai[bot] 46dac17fae Merge main into sweep/add-unit-tests 2023-10-26 22:42:55 +00:00
sweep-ai[bot] fb6c36dfaf Merge main into sweep/add-unit-tests 2023-10-26 22:06:57 +00:00
sweep-ai[bot] 446bd5df75 Merge main into sweep/add-unit-tests 2023-10-18 02:56:59 +00:00
sweep-ai[bot] f1e486c4b2 Merge main into sweep/add-unit-tests 2023-10-17 23:13:54 +00:00
sweep-ai[bot] 39a3f42cf1 Merge main into sweep/add-unit-tests 2023-10-16 16:29:24 +00:00
sweep-ai[bot] 09e7f8d192 Merge main into sweep/add-unit-tests 2023-10-16 16:23:14 +00:00
sweep-ai[bot] 4a857123f6 Merge main into sweep/add-unit-tests 2023-10-13 01:02:28 +00:00
sweep-ai[bot] 31e18bbdd1 Merge main into sweep/add-unit-tests 2023-10-10 21:34:52 +00:00
sweep-ai[bot] c1aca04120 Merge main into sweep/add-unit-tests 2023-10-10 01:17:34 +00:00
sweep-ai[bot] 7d2d5c8c4a Merge main into sweep/add-unit-tests 2023-10-09 02:16:32 +00:00
sweep-ai[bot] 2a33097244 Merge main into sweep/add-unit-tests 2023-10-07 22:59:56 +00:00
sweep-ai[bot] 2be8e9e5e8 Merge main into sweep/add-unit-tests 2023-10-06 01:37:41 +00:00
sweep-ai[bot] d356c1766a Merge main into sweep/add-unit-tests 2023-10-03 21:48:46 +00:00
sweep-ai[bot] 873a6f5a2a Merge main into sweep/add-unit-tests 2023-10-03 21:48:23 +00:00
sweep-ai[bot] 9a0f07eb91 Merge main into sweep/add-unit-tests 2023-09-26 22:34:53 +00:00
sweep-ai[bot] 9d8d97c3f0 Merge main into sweep/add-unit-tests 2023-09-26 22:30:55 +00:00
sweep-ai[bot] 2c9d5e8dd9 Merge main into sweep/add-unit-tests 2023-09-26 22:25:37 +00:00
sweep-ai[bot] e5be424a8d Merge main into sweep/add-unit-tests 2023-09-26 22:24:30 +00:00
sweep-ai[bot] da0d5bae82 Merge main into sweep/add-unit-tests 2023-09-26 19:43:24 +00:00
sweep-ai[bot] bfe873cf06 Merge main into sweep/add-unit-tests 2023-09-26 19:38:48 +00:00
sweep-ai[bot] f1fbcb6672 Updated packages/core/src/tests/Embedding.test.ts 2023-09-16 01:28:38 +00:00
sweep-ai[bot] 37d5bc0eab Add unit tests for Node class 2023-09-16 01:23:30 +00:00
sweep-ai[bot] c8262659f9 Add unit tests for RouterQueryEngine class 2023-09-16 01:18:02 +00:00
sweep-ai[bot] b713d7b8da Add unit tests for Selector class 2023-09-16 01:11:37 +00:00
4 changed files with 122 additions and 9 deletions
+33 -9
View File
@@ -32,13 +32,37 @@ describe("similarity", () => {
});
test("calculates euclidean similarity", () => {
const queryEmbedding = [1, 0];
const docEmbedding1 = [0, 1]; // farther from query, distance 1.414
const docEmbedding2 = [1, 1]; // closer to query distance 1
expect(
similarity(queryEmbedding, docEmbedding1, SimilarityType.EUCLIDEAN),
).toBeLessThan(
similarity(queryEmbedding, docEmbedding2, SimilarityType.EUCLIDEAN),
);
const queryEmbedding = [1, 0];
const docEmbedding1 = [0, 1]; // farther from query, distance 1.414
const docEmbedding2 = [1, 1]; // closer to query distance 1
expect(
similarity(queryEmbedding, docEmbedding1, SimilarityType.EUCLIDEAN),
).toBeLessThan(
similarity(queryEmbedding, docEmbedding2, SimilarityType.EUCLIDEAN),
);
});
test("calculates cosine similarity with zero vectors", () => {
const embedding1 = [0, 0];
const embedding2 = [0, 0];
expect(similarity(embedding1, embedding2, SimilarityType.DEFAULT)).toEqual(
NaN,
);
});
test("calculates dot product with zero vectors", () => {
const embedding1 = [0, 0];
const embedding2 = [0, 0];
expect(
similarity(embedding1, embedding2, SimilarityType.DOT_PRODUCT),
).toEqual(0);
});
test("calculates euclidean similarity with zero vectors", () => {
const embedding1 = [0, 0];
const embedding2 = [0, 0];
expect(
similarity(embedding1, embedding2, SimilarityType.EUCLIDEAN),
).toEqual(0);
});
});
});
+34
View File
@@ -0,0 +1,34 @@
import { Node, ObjectType, MetadataMode } from '../Node';
import { v4 as uuidv4 } from 'uuid';
describe('Node class', () => {
let node: Node;
beforeEach(() => {
node = new Node();
});
test('getType method', () => {
expect(node.getType()).toBe(ObjectType.TEXT);
});
test('getContent method', () => {
const content = 'Test content';
node.setContent(content);
expect(node.getContent(MetadataMode.ALL)).toBe(content);
});
test('getMetadataStr method', () => {
const metadata = { key: 'value' };
node.metadata = metadata;
expect(node.getMetadataStr(MetadataMode.ALL)).toBe(JSON.stringify(metadata));
});
test('setContent method', () => {
const content = 'Test content';
node.setContent(content);
expect(node.getContent(MetadataMode.ALL)).toBe(content);
});
// Mock LLM completions and test other methods...
});
@@ -0,0 +1,34 @@
import { RouterQueryEngine } from '../RouterQueryEngine';
import { LLM } from '../LLM'; // Assuming LLM is a class or module that can be mocked
jest.mock('../LLM'); // Mock the LLM completions
describe('RouterQueryEngine', () => {
let routerQueryEngine: RouterQueryEngine;
let mockLLM: jest.Mocked<LLM>;
beforeEach(() => {
mockLLM = new LLM() as jest.Mocked<LLM>;
routerQueryEngine = new RouterQueryEngine(mockLLM);
});
afterEach(() => {
jest.clearAllMocks();
});
test('method1', () => {
// Arrange
const input = 'some input';
const expectedOutput = 'some output';
mockLLM.completion.mockReturnValue(expectedOutput);
// Act
const output = routerQueryEngine.method1(input);
// Assert
expect(output).toBe(expectedOutput);
expect(mockLLM.completion).toHaveBeenCalledWith(input);
});
// Repeat the test block for other methods in the RouterQueryEngine class
});
+21
View File
@@ -0,0 +1,21 @@
import { Selector } from '../Selector';
import { LLM } from '../LLM'; // Assuming LLM is a class or function that can be mocked
import { jest } from '@jest/globals';
describe('Selector', () => {
let mockLLM: jest.Mocked<LLM>;
beforeEach(() => {
mockLLM = {
complete: jest.fn(),
// Add other methods to be mocked here
};
});
test('method1', () => {
const selector = new Selector(mockLLM);
// Call method1 and assert the output
});
// Add more tests for other methods here
});