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
|
import os
# List of files to extract code from, relative to the `src` folder
files = [
"src/client/views/nodes/chatbot/agentsystem/Agent.ts",
"src/client/views/nodes/chatbot/agentsystem/prompts.ts",
"src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx",
"src/client/views/nodes/chatbot/chatboxcomponents/MessageComponent.tsx",
"src/client/views/nodes/chatbot/response_parsers/AnswerParser.ts",
"src/client/views/nodes/chatbot/response_parsers/StreamedAnswerParser.ts",
"src/client/views/nodes/chatbot/tools/BaseTool.ts",
"src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts",
"src/client/views/nodes/chatbot/tools/RAGTool.ts",
"src/client/views/nodes/chatbot/tools/SearchTool.ts",
"src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts",
"src/client/views/nodes/chatbot/types/tool_types.ts",
"src/client/views/nodes/chatbot/types/types.ts",
"src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts",
]
# Output file name
output_file = "extracted_code.txt"
def extract_and_format_code(file_list, output_path):
with open(output_path, "w") as outfile:
for file in file_list:
# Since the script runs from the chatbot folder, prepend the relative path from chatbot to src
if os.path.exists(file):
with open(file, "r") as infile:
code = infile.read()
# Write formatted code to the output file
outfile.write(f"--- {file} ---\n\n```\n{code}\n```\n\n")
else:
print(f"File not found: {file}")
# Run the extraction and formatting
extract_and_format_code(files, output_file)
print(f"Code extracted and saved to {output_file}")
|