embedchainjs

Форк
0
66 строк · 2.2 Кб
1
import { EmbedChainApp } from '../embedchain';
2

3
const mockAdd = jest.fn();
4
const mockAddLocal = jest.fn();
5
const mockQuery = jest.fn();
6

7
jest.mock('../embedchain', () => {
8
  return {
9
    EmbedChainApp: jest.fn().mockImplementation(() => {
10
      return {
11
        add: mockAdd,
12
        addLocal: mockAddLocal,
13
        query: mockQuery,
14
      };
15
    }),
16
  };
17
});
18

19
describe('Test App', () => {
20
  beforeEach(() => {
21
    jest.clearAllMocks();
22
  });
23

24
  it('tests the App', async () => {
25
    mockQuery.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

29
    const navalChatBot = await new EmbedChainApp(undefined, false);
30

31
    // Embed Online Resources
32
    await navalChatBot.add('web_page', 'https://nav.al/feedback');
33
    await navalChatBot.add('web_page', 'https://nav.al/agi');
34
    await 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
40
    await navalChatBot.addLocal('qna_pair', [
41
      'Who is Naval Ravikant?',
42
      'Naval Ravikant is an Indian-American entrepreneur and investor.',
43
    ]);
44

45
    const result = await navalChatBot.query(
46
      'What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?'
47
    );
48

49
    expect(mockAdd).toHaveBeenCalledWith('web_page', 'https://nav.al/feedback');
50
    expect(mockAdd).toHaveBeenCalledWith('web_page', 'https://nav.al/agi');
51
    expect(mockAdd).toHaveBeenCalledWith(
52
      'pdf_file',
53
      'https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf'
54
    );
55
    expect(mockAddLocal).toHaveBeenCalledWith('qna_pair', [
56
      'Who is Naval Ravikant?',
57
      'Naval Ravikant is an Indian-American entrepreneur and investor.',
58
    ]);
59
    expect(mockQuery).toHaveBeenCalledWith(
60
      'What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?'
61
    );
62
    expect(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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.