File size: 5,184 Bytes
d26280a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# import example_snake_files
# import pytest
#
# from llama_index import Document
#
# from gpt_engineer.tools.experimental.code_vector_repository import CodeVectorRepository
#
#
# def mock_load_documents_from_directory(self, directory_name):
#     nonCodeDoc = Document()
#     nonCodeDoc.set_content(
#         "example non code file which currently isnt loaded into the vector store"
#     )
#     nonCodeDoc.metadata["filename"] = "README.md"
#
#     if directory_name == "python":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.PYTHON)
#         doc1.metadata["filename"] = "src/snake_game.py"
#
#     if directory_name == "web":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.HTML)
#         doc1.metadata["filename"] = "src/index.html"
#
#         doc2 = Document()
#         doc2.set_content(example_snake_files.CSS)
#         doc2.metadata["filename"] = "src/styles.css"
#
#         doc3 = Document()
#         doc3.set_content(example_snake_files.JAVASCRIPT)
#         doc3.metadata["filename"] = "src/script.js"
#
#         return [doc1, doc2, doc3, nonCodeDoc]
#
#     if directory_name == "java":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.JAVA)
#         doc1.metadata["filename"] = "src/snake_game.java"
#
#     if directory_name == "c#":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.C_SHARP)
#         doc1.metadata["filename"] = "src/snake_game.cs"
#
#     if directory_name == "typescript":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.TYPESCRIPT)
#         doc1.metadata["filename"] = "src/snake_game.ts"
#
#     if directory_name == "ruby":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.RUBY)
#         doc1.metadata["filename"] = "src/snake_game.rb"
#
#     if directory_name == "php":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.PHP)
#         doc1.metadata["filename"] = "src/snake_game.php"
#
#     if directory_name == "go":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.GO)
#         doc1.metadata["filename"] = "src/main.go"
#
#     if directory_name == "kotlin":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.KOTLIN)
#         doc1.metadata["filename"] = "src/main/kotlin/SnakeGame.kt"
#
#     if directory_name == "rust":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.RUST)
#         doc1.metadata["filename"] = "src/main.rs"
#
#     if directory_name == "c++":
#         doc1 = Document()
#         doc1.set_content(example_snake_files.C_PLUS_PLUS)
#         doc1.metadata["filename"] = "src/main.cpp"
#
#     # c is supported, however it does not pass this test
#     # if directory_name == "c":
#     #     doc1 = Document()
#     #     doc1.set_content(example_snake_files.C)
#     #     doc1.metadata["filename"] = "main.c"
#
#     # Swift not currently supported
#     # if directory_name == "swift":
#     #     doc1 = Document()
#     #     doc1.set_content(example_snake_files.SWIFT)
#     #     doc1.metadata["filename"] = "src/main.swift"
#
#     return [doc1, nonCodeDoc]
#
#
# @pytest.mark.skip(
#     reason="this test makes queries to an LLM as part of creating the vector store so requires an open ai api key. Todo: run the vector store with llm=None so this can run without an LLM"
# )
# @pytest.mark.parametrize(
#     "language",
#     [
#         "python",
#         "web",
#         "java",
#         "c#",
#         "typescript",
#         "ruby",
#         "php",
#         "go",
#         "kotlin",
#         "rust",
#         "c++",
#     ],
# )  # ToDo: add Swift, C and other languages
# def test_load_and_retrieve(monkeypatch, language):
#     # arrange
#     monkeypatch.setattr(
#         CodeVectorRepository,
#         "_load_documents_from_directory",
#         mock_load_documents_from_directory,
#     )
#
#     repository = CodeVectorRepository()
#     repository.load_from_directory(language)
#
#     # act
#     document_chunks = repository.relevent_code_chunks(
#         "Invert the controlls so pressing the up moves the snake down, and pressing down moves the snake up.",
#         llm=None,
#     )
#
#     # assert
#     assert document_chunks.__len__() == 2  # set to return 2 documents
#
#     assert (
#         "up" in document_chunks[0].text.lower()
#     )  # code should include section that sets directions
#     assert "down" in document_chunks[0].text.lower()
#
#
# @pytest.mark.skip(
#     reason="this test makes queries to an LLM so requires an open ai api key"
# )
# def test_load_and_query_python(monkeypatch):
#     # arrange
#     monkeypatch.setattr(
#         CodeVectorRepository,
#         "_load_documents_from_directory",
#         mock_load_documents_from_directory,
#     )
#
#     repository = CodeVectorRepository()
#     repository.load_from_directory("python")
#
#     # act
#     response = repository.query(
#         "How would I invert the direction arrows so up moves the snake down, and down moves the snake up? "
#     )
#
#     # assert
#     assert "Controller" in str(response)