embedchainjs
66 строк · 2.2 Кб
1import { EmbedChainApp } from '../embedchain';
2
3const mockAdd = jest.fn();
4const mockAddLocal = jest.fn();
5const mockQuery = jest.fn();
6
7jest.mock('../embedchain', () => {
8return {
9EmbedChainApp: jest.fn().mockImplementation(() => {
10return {
11add: mockAdd,
12addLocal: mockAddLocal,
13query: mockQuery,
14};
15}),
16};
17});
18
19describe('Test App', () => {
20beforeEach(() => {
21jest.clearAllMocks();
22});
23
24it('tests the App', async () => {
25mockQuery.mockResolvedValue(
26'Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.'
27);
28
29const navalChatBot = await new EmbedChainApp(undefined, false);
30
31// Embed Online Resources
32await navalChatBot.add('web_page', 'https://nav.al/feedback');
33await navalChatBot.add('web_page', 'https://nav.al/agi');
34await navalChatBot.add(
35'pdf_file',
36'https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf'
37);
38
39// Embed Local Resources
40await navalChatBot.addLocal('qna_pair', [
41'Who is Naval Ravikant?',
42'Naval Ravikant is an Indian-American entrepreneur and investor.',
43]);
44
45const result = await navalChatBot.query(
46'What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?'
47);
48
49expect(mockAdd).toHaveBeenCalledWith('web_page', 'https://nav.al/feedback');
50expect(mockAdd).toHaveBeenCalledWith('web_page', 'https://nav.al/agi');
51expect(mockAdd).toHaveBeenCalledWith(
52'pdf_file',
53'https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf'
54);
55expect(mockAddLocal).toHaveBeenCalledWith('qna_pair', [
56'Who is Naval Ravikant?',
57'Naval Ravikant is an Indian-American entrepreneur and investor.',
58]);
59expect(mockQuery).toHaveBeenCalledWith(
60'What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?'
61);
62expect(result).toBe(
63'Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.'
64);
65});
66});
67